Average an ADC Output over a Time Interval (BS2)
MtnFlyer
Posts: 28
Greetings all,
I'm trying to average an ADC output (8 bit) in the following way:
When signal goes above a threshold value, say %00010000, THEN
- continue sampling ADC
- start calculating a running sum of ADC values·for the next 0.1s
- divide the sum by the number of samples to get an average
- exit the loop and print the result
I'm having a hard time figuring out how to specify the time interval in PBASIC.· Thanks for the help!
Jim
I'm trying to average an ADC output (8 bit) in the following way:
When signal goes above a threshold value, say %00010000, THEN
- continue sampling ADC
- start calculating a running sum of ADC values·for the next 0.1s
- divide the sum by the number of samples to get an average
- exit the loop and print the result
I'm having a hard time figuring out how to specify the time interval in PBASIC.· Thanks for the help!
Jim
Comments
for example;
if inA > %00010000 then
y = 1 ' samples
a = inA ' storage variable
c = inA ' total variable
for x = 0 to 100 'guess work of time
b = inA 'temp variable
if b = a then next elseif
y = y + 1 ' amount of samples
c = c + b ' add samples together
a = b ' next check
next
a = c / y ' result