onklen
04-20-07, 07:30 AM
I'm trying to create a function which should make a moving average of some values from the adc channel. But I would like to be able to call the function and sending the start address of the buffer and which adc channel it should take new values from. As seen in my example below it's pretty simple to send the start address of the buffer, but I'm pretty lost in how to send the adc channel.
: ADC-NEW DUP 21 1 DO I
+ DUP 1 - SWAP @ SWAP ! DUP
LOOP
DROP ADC9 ANALOGIN SWAP 20 + ! ;
So this example takes the new data and shift it through the 21 word buffer and the last word should be the new data from channel ADC9. But is there anyway to avoid writing ADC9 in the function and instead putting something on the stack and making Isomax understand that it is channel 9 it should take the new data from.
The reason is that I need to get new data from a lot adc channels and would like to re-use the function.
Rolf
: ADC-NEW DUP 21 1 DO I
+ DUP 1 - SWAP @ SWAP ! DUP
LOOP
DROP ADC9 ANALOGIN SWAP 20 + ! ;
So this example takes the new data and shift it through the 21 word buffer and the last word should be the new data from channel ADC9. But is there anyway to avoid writing ADC9 in the function and instead putting something on the stack and making Isomax understand that it is channel 9 it should take the new data from.
The reason is that I need to get new data from a lot adc channels and would like to re-use the function.
Rolf