multiple samples from ADC ?

fran1942

New Member
Hello, I am wanting to take three samples per second from my ADC input, so I can be sure the input is continuous and not just a quick, one off input.
Each sample gets stored into B12 and then copied to B13. B13 grows incrementally with each sample of B12.
I then divide B13 by three and test the value.
This is the code I am using, but it is not doing anything.
I am sure it is something simple I am doing wrong. Could someone please take a look ? I am unfamiliar with the nuances of picaxe basic.
Thanks kindly for any help.

main:
let w0=0
let w1=0
readadc 4,w0
let w1=w0
pause 500
readadc 4,w0
let w1 = w1+w0
pause 500
readadc 4,w0
let w1 = w1+w0
let w1 = w1/3

if w1 >= 152 then
goto lights
endif
goto main
 
Last edited:

fran1942

New Member
thanks, I fixed that, but it is still not working.
Is there something else obvious I not doing right with the code ?
 
Last edited:

Texy

Senior Member
Note that the maximum reading from the readadc10 function is 1023, so we can use a word variable to store up to 64 readings, so this is what I do :

Code:
w3=0
for b9 = 1 to 64
readadc10 c.1,w2
w3=w3+w2
next
w2=w3/64
Hope this helps,
Texy
 

Svejk

Senior Member
What picaxe are you using? What's your hardware setup? Please post your circuit and a photo of your setup. A detailed description of your project will help too.
 

hippy

Ex-Staff (retired)
Add some DEBUG or SERTXD commands so you can see what's in the variables -

In w0 after each READADC
In w1 after each addition of w0
In w1 after division by 3
 

hippy

Ex-Staff (retired)
Add some DEBUG or SERTXD commands so you can see what's in the variables -

In w0 after each READADC
In w1 after each addition of w0
In w1 after division by 3
 

cravenhaven

Senior Member
Readadc produces a byte output (8 bits, 255 values). I dont see that it should matter but try something like

w1=0
readadc 4,b4
w1=w1+b4
.
.
.
Allan
 

Goeytex

Senior Member
This should do what you are trying to do. But will it solve your real problem is another question.
I assume you are still working on the mic input to an ADC ?

=================
symbol sample = b0
symbol sample_sum = w1
symbol result = w2

main:
let w0=0
let w1=0

for b1 = 1 to 3 'Loop three times
pause 667
readadc 4,sample
sample_sum = sample + sample_sum
next

result = sample_sum / 3

DEBUG ' HERE

if result >= 152 then
goto lights
endif
goto main

lights:
rem do whatever
pause 1000
return
=========================

@fran
Real help will be limited as long as you ignore requests for a schematic diagram and or photo
of your circuit.
 

inglewoodpete

Senior Member
fran, It would help if you restored your original code, warts and all. If you need to change a post after others have commented, please make it obvious what your changes are.

Have a re-read of your first post now. The text discusses all sorts of byte variables and issues that do not appear in the currently posted piece of code. While you have learned from the exercise, this thread does nothing to help future readers searching the forum for a solution to a similar problem.

Peter
 
Top