trial to run a dsPIC

Create new topics, add your comment, remark, bugs...
Post Reply
crh
Posts: 20
Joined: Wed Oct 29, 2008 11:51 am

trial to run a dsPIC

Post by crh » Thu Jan 22, 2009 8:40 am

Bonjour Lubin,

I am trying to run a dsPIC30f4013 for the first time, together with a function generator. In the image attachment you see a screenprint from my scope and the pinlayout of the pic4013.
When I start my simulink model I get the next intitial warning:

Code: Select all

Warning: dsPICdrivers.mdl, line 52: block_diagram does not have a parameter named 'CovModelRefEnable'.
> In general\private\openmdl at 13
  In open at 148
  In uiopen at 196
Warning: Error evaluating 'LoadFcn' callback of Master block (mask) 'Master'. Error using ==> dsPIC_ConfigRTWOption
at 100
The *System Target File must be defined to dsPIC Real Time workshop (Simulation ==> Configuration Parameters ==>
Real Time workshop.
> In general\private\openmdl at 13
  In open at 148
  In uiopen at 196
Warning: In instantiating linked block 'BCfirsttestwithLPfilter/ADC Input' : Invalid setting in dsPIC : ADC10 block
(mask) 'ADC Input' for parameter 'OutFormatBitspopup'.
> In C:\My Toolbox\blocks\dsPIC_ConfigRTWOption.p>dsPIC_ConfigRTWOption at 4
  In C:\My Toolbox\blocks\dsPIC_MASTER_callback.p>dsPIC_MASTER_callback at 87
  In general\private\openmdl at 13
  In open at 148
  In uiopen at 196.
When I compile the model, I get the warning/error:

Code: Select all

''pic30-gcc  -c -mcpu=30f4013 -O3 -fschedule-insns -fschedule-insns2	 -O   -I. -I..\.. -IC:\PROGRA~1\MATLAB\R2007b/simulink/include -IC:\PROGRA~1\MATLAB\R2007b/extern/include -IC:\PROGRA~1\MATLAB\R2007b/rtw/c/src -IC:\PROGRA~1\MATLAB\R2007b/rtw/c/ert -IC:\PROGRA~1\MATLAB\R2007b/rtw/c/src/ext_mode/common -IC:\Users\Casparus\DOCUME~1\MATLAB\Work\WORKFL~1\SIMPLE~1\BCFIRS~1\sources - 
dsPIC_UART1_Interrupt.c: In function '_U1TXInterrupt': 
dsPIC_UART1_Interrupt.c:19: warning:  PSV model not specified for '_U1TXInterrupt'; 
   assuming 'auto_psv' this may affect latency 
dsPIC_UART1_Interrupt.c: In function '_U1RXInterrupt': 
dsPIC_UART1_Interrupt.c:31: warning:  PSV model not specified for '_U1RXInterrupt'; 
   assuming 'auto_psv' this may affect latency
and at the end the message:
*** Version 0.98fe                            16-Sep-2008      " 
"*** For Matlab 7.5             R2007b       " 
"*** Created "executable": ..\../BCfirsttestwithLPfilter.coff"	 
''pic30-bin2hex ..\../BCfirsttestwithLPfilter.coff  
"*** Created "executable": ..\../BCfirsttestwithLPfilter.hex"	 
### Successful completion of Real-Time Workshop build procedure for model: BCfirsttestwithLPfilter
Next, I write the hex file with a Pickit2 in the pic4013. Then I connect the funtion generator with the pic. As you can see in the printscreen of the scope, there is no correlation between the frequency of the generator and the pic4013. The only thing is, when I change the frequency of the generator the frequency of the pic is changing, but it seems to be without any correlation.
Please, can you provide me with some helpful hints?

Kind regards,
Casparus
Attachments
scope+4013.gif
BCfirsttestwithLPfilter.mdl
(476.39 KiB) Downloaded 191 times

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: trial to run a dsPIC

Post by LubinKerhuel » Thu Jan 22, 2009 9:07 pm

Hello Casparus,

First of all, do not take into account any error message while you open a model.
Then, compilation finished without error, so it’s seems to be Ok, problems are no there.

As far as I understand, you want to make a digital LP filter at 148Hz. A very first remark is from a theoretical signal processing point of view: The sampling time (model step time) is 1/300s. Thus, all frequency above 150Hz will recopy themselves inside the 0-150Hz band creating aliasing. You should use an analog filter to take out all frequency above 150Hz before the A/D conversion take place.

Anyway, there are few problems with your model:

*30f4013 has a 12 bit ADC. Thus, the first uint8 Data type conversion block after the ADC will certainly saturate.

*about the LP filter: all coefficients are stored in double format (that is a good point because their value look like 0.014552788094050004). Thus the multiplications are done in double. Thus, there is no reason to make the output a uint8 value. The output of the first calculation could vary between 0 and 4 (0.014*255) only. There is a major problem with fixed point calculation here.

*Some coefficient are negative ==> Major problem when result is stored in an unsigned variable.

You may consider using a IIR filter that usually give good filtering results with fewer taps than a FIR filters. (That may allow leaving all calculation in double inside the dsPIC).

I would recommend to do simulation test (start with the file attached). Start using double calculation only ; then, try to use the fixed point tools to make the calculation efficient on the dsPIC.
BCfirsttestwithLPfilter_Simulation.mdl
This filter must be modified to work properly
(498.81 KiB) Downloaded 319 times
I hope this will help.
Lubin

crh
Posts: 20
Joined: Wed Oct 29, 2008 11:51 am

Re: trial to run a dsPIC

Post by crh » Thu Feb 05, 2009 8:49 am

Hello Lubin,
In the meantime, I have made a study of the FDAT tool in Simulink.
I have developed a LP 145Hz filter. According to the attachment it is working.
From this point on, I developed a model in order to implement it in dsPIC30f4013. See attachment.
With my scope, I get a frequency signal on the U1ATX pin, but it is not equal to the signal of my function generator on pin AN0/Vref.

I developed also the same model with a fixed point filter (based on the original LP filter), but the same problem.

Till now, I spend a lot of time to develop a working filter on a dsPIC. I do not care, because my goal is to learn everything about MCU’s, and this I like very much. But if you have a very simple model with a filter which I can upload into a pic and can check with a function generator on pin AN0/Vref and a scope on pin U1ATX , I should be very grateful.

Kind regards, Casparus.
Attachments
LP145floatwithADCUART.mdl
(202.33 KiB) Downloaded 192 times
LPsimulation.mdl
(203.2 KiB) Downloaded 178 times

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: trial to run a dsPIC

Post by LubinKerhuel » Thu Feb 05, 2009 7:49 pm

Hi Casparus,
crh wrote:I have developed a LP 145Hz filter
* Same problems remains: filtering at 145Hz with a sampling rate at 300Hz is a non sense. (See sampling theory http://en.wikipedia.org/wiki/Nyquist%E2 ... ng_theorem)
* Output visualisation: your signal is likely to be greater than 255 (ADC output value is within a 10 or 12 bit range and positive only). You should output your signal via a 16 bit variable. I suggest using the TX_Labview_MATLAB block to send the data, and to see your data on your PC with the rs232GUI interface that comes with the dsPIC blockset.
* The designed filter is a FIR with many taps. Calculation are in double, the number or instruction of your dsPIC is not that high (2.5MIPS ?). You should make sure that the dsPIC has time to make the calculation within the defined time step (3.3ms, hopefully that's a large time step). Use the Overload Flag Port option available on the master block or the Calculus Time Step block

The filter calculation itself may work well (from your simulation). There may be problems at the output level and in the real time calculation.

for a simple example, go to the example directory of the dsPIC blockset and open the model dsPIC_33f_Explorer16.mdl. Two very simple IIR filters are designed and may be adapted for your microcontroller. Make sure to adapt the time step on your model to use theses filters properly. Otherwise, you may have to change the filters coefficient...

Lots of useful information about digital signal processing is available on Wikipedia.

Lubin

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests