SignalGenerator example - increase number of stored samples?

General discussion on mikroPascal for dsPIC30/33 and PIC24.
Post Reply
Author
Message
OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

SignalGenerator example - increase number of stored samples?

#1 Post by OT » 07 Nov 2007 14:54

The signal generator example is working very nicely. By transforming the stored sine sample array to a multidimensional array, I am able to choose between different waveforms just by changing one index. So far I have implemented Sine, Square, saw-tooth and EMG (see below..). I had to fine tune the main loop with a short delay and some dummy statements to get highly accurate frequency.

However it would be nice to be able to use a longer/higher resolution wave form. Is there a way to increase the size of the array (assuming that more is needed than just increasing the index), or is it limited by the DSP engine/accumulator ?

I must admit I do not have a very good understanding of how the accumulator works in this case in spite of the careful explanation in the comments... for instance "The part B (lower bits comparing to A) defines resolution of frequency tuning: N=2^B. In the example below N= 2^16= 65536"; where does the exponent 16 come from?

(The reason for the request is that in addition I am also trying to add some physiological signals: ECG, EMG [muscle electrical activity] and EEG [brainwave activity]. Some of these preferably could use a longer/higher resolution sample than a 256 array since periods would extend over > 1 s.)

OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

#2 Post by OT » 08 Nov 2007 17:57

Any response to this?

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

#3 Post by zristic » 09 Nov 2007 11:26

One nice thing you can read about is DDS method for signal synthesis. It is very nice for changing number of samples in the output signal.

In example folders of mB there is an example for DDS.

OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

#4 Post by OT » 13 Nov 2007 12:16

Ahem, this is the pascal group and there is one for the non-dsPIC pascal version too if we talk abut the sine wave example... :D

It is interesting to see how that version has everything upside down (or perhaps the dsPIC version has it), interrupts used to generate the frequency, and main loop used for changing parameters. Could be easier to obtain small frequency steps at low frequency. dsPIC version runs a loop to generate a constant frequency, and uses accumulator indexing.
(I seem to recall something about DSP routines that cannot be called from interrupts?)

So the examples do not help each other too much. However I found that I could accommodate longer array by changing the shift index to the accumulator in the dsPIC version, I had sine wave going with 2048 samples covering 2 seconds with a shift of 5 instead of 8. However when I added content and checked the other waveform arrays, a small portion got corrupted. Sine wave was still fine. I suspect there might be an issue with some unspecified shifts in the index. Perhaps not surprising, considering that I used all but about 2K of the memory in the statistics view...
(I tried shifting the dynamic/static memory slider to no effect). Now I am running fine with a shift of 6, same array size, covering a 1 sec sample. Interestingly the cutoff point differs if I reduce array size to 1024, so there might still be some partly hidden problems with the indexing.

Post Reply

Return to “mikroPascal for dsPIC30/33 and PIC24 General”