10 bit ADC result stored?

gerrymcc

New Member
I am wanting to change from using the 8-bit adc to a 10-bit adc in an existing 28X1 program, by changing the "readadc" statement to a "readadc10".

The 8-bit read requires one word for the result. But a 10-bit read requires a word plus 2 bits.

Where are the additional 2 bits stored? Is there a risk they will overwrite 2 bits in another byte or word in the program?

Thank you.
 

testerrrs

New Member
8-bit requires a byte (8 bits).

10-bit requires a word (16 bits) because it won't fit in a byte variable.

So instead of
Code:
readadc 0,b0
you'd need
Code:
 readadc10 0,w0
Be aware that w0 comprises b0 and b1, and as such, modifying w0 will also change b0 and b1.

Jon
 

Benjie

Senior Member
Hello there, I notice that many posts are dealing with readadc10 and the word reading. I am no exception. The application I am working on should stop a step motor when th analog input signal does not change during a sampling interval of, says, 1-2 msec.
By no change I means a variation of less than 10 mV. This variation is less than one bit if I use the 255 steps of b0 therefore I should go for readadc10 and store in a word variable.
I tried it in the simulator but I can change the analog input only from 0 to 255. How can I extend the input range and increase the resolution? In other words how is it possible to write and read into b1?

Thanks for your patience.
 

Chavaquiah

Senior Member
b0 and b1 are byte (8-bit) variables. If you're going to use readadc10 then you must use 16-bit variables (w0, w1, ...). You use these just like you would use byte variables except you know they can handle larger values.

readadc10 1, w0 'Read 10-bit value
w1 = w0 'Store it in w1
pause 1000 'Wait a bit
readadc10 1, w0 'Read new voltage
if w0 > w1 then
'voltage went up
endif

Only thing to look for is that each 16-bit variable shares the same space as 2 8-bit variables (w0 = b0, b1; w1 = b2, b3; ...). We should thus not mix them. For instance, the following code fails miserably:

readadc10 1, w0
for b0 = 1 to 3 'overwrites w0
w0 = w0 * 2 'changes b0 and b1
next b0
 

Technical

Technical Support
Staff member
If your result will never be higher than 255 you could use a byte for readadc10, but we would still recommend a word variable.

Readadc divides the supply voltage by 256 steps, readadc10 by 1024 steps, so 'each step' is much smaller hence greater accuracy.

Use the 'generic' entry box to load values for the readadc10 command in the simulator.
 

Benjie

Senior Member
what do you mean by 'generic' entry? Usually I click on the pin arrows (up-down).
Do you actually mean a program entry like let w0=856?
 

hippy

Ex-Staff (retired)
The generic entry is the field at the bottom of the PICAXE image during simulation which is labelled as "Generic:". The value entered there will be used by READADC10.
 
Top