Hi,
I'd probably sample at atleast 10 times the input frequency dependning on what else the PIC has to do while doing this thing.
Here's one idea, from the top of my head, untested....
Code:
Sample VAR WORD
LastSample VAR WORD
Average VAR WORD
Peaks VAR WORD [8]
i VAR BYTE
j VAR BYTE
' You might want to insert some form of "trigger" mechanism here.
' Perhaps sample the input in a loop and wait until there's a
' positive going trend or something - then move on the following:
For i = 0 to 7 ' Get 8 peaks
LastSample = 0 ' Set up
Average = 0 ' Set up
Sample = 0 ' Set up
DO
LastSample = Average ' Save previous sample
Average = 0 ' Reset accumulator
For j = 0 to 3 ' Take 4 samples quickly
ADCIN 1, Sample ' Get current input
Average = Average + Sample ' Add to accumulator
Next ' Next sample
Average = Average >> 2 ' Divide by 4
UNTIL Average < LastSample ' Stop if this sample is lower than the last one.
Peaks[i] = LastSample ' Current sample is lower than last one, we've found the peak.
NEXT
For i = 0 to 7
HSEROUT ["Peak number", DEC (i+1), ": ", DEC Peaks[i], " ADC counts", 13]
Next
/Henrik.
Bookmarks