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.)
SignalGenerator example - increase number of stored samples?
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...
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.
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.