ReadADC10 Example??

CDRIVE

Senior Member
Since my download of M2 software I seem intent on finding confusing data in the pdfs, as evidenced by some of my recent posts. Well, here's another one pasted from page 171 of Picaxe_Manual2.pdf titled 'Basic Commands'.

Code:
main:
readadc10 C.4,w1 ; read value into b1
debug ; transmit to computer
pause 200 ; short delay
goto main ; loop back to start
Note the "read value into b1" comment. Besides this typo I think the use of "debug" in this example just muddy's the water and has no relation to the command anyway.

While I'm on the subject, how do I generate a word variable like 1.25 using the simulator? I can only generate a byte variable in steps of 5 using the controls provided.
 

nick12ab

Senior Member
While I'm on the subject, how do I generate a word variable like 1.25 using the simulator?
For a word variable, you use the Generic value shown below the chip in the simulation dialog. However 1.25 is a decimal and is not supported by PICAXE.

Note the "read value into b1" comment
While we're on the subject, now introducting the Serial CD Firmware!



At least the Serial LCD Firmware datasheet no longer says "Serial Printer Firmware Contents:"
 

CDRIVE

Senior Member
For a word variable, you use the Generic value shown below the chip in the simulation dialog. However 1.25 is a decimal and is not supported by PICAXE.

While we're on the subject, now introducting the Serial CD Firmware!At least the Serial LCD Firmware datasheet no longer says "Serial Printer Firmware Contents:"
OK, then let's say I'm using ReadADC or ReadADC10 to read the voltage from a 10:1 voltage divider. Let's further assume a battery of 12.5V which would produce 1.25V when divided down for the ADC. Now let's reduce the battery voltage to 12.4V, which would give us 1.24V at the ADC. How does the ReadADC or ReadADC10 interpret this?
 

hippy

Technical Support
Staff member
The voltage into the ADC (Vadc) is converted to a numeric result (Nadc) in accordance with the following equation -

Nadc = Vadc * Nmax / Vref

Nmax will be 255 for READADC, 1023 for READADC10. Vref is the reference voltage, usually the PICAXE supply voltage. The result will depend on what Vref / supply voltage you use which is why srnet asks.

If we assume you use READADC10, have a 5V supply, 1.25V into the ADC pin, it would be -

Nadc = Vadc * Nmax / Vref

Nadc = 1.25 * 1023 / 5 = 255.75 = 255

For 1.24V ...

Nadc = 1.24 * 1023 / 5 = 253.704 = 253
 

CDRIVE

Senior Member
Hippy, srnet, thank you for the replies. Hippy, the information you posted is exactly what I was looking for. I spent most of yesterday evening searching the pdf's to see if they contained anything that remotely resembled your explanation. The mosts pertinent information I could find was on page 109 of manual 1 but even that explanation fell short of your excellent description.

Thanks again!
 
Last edited:

CDRIVE

Senior Member
A Senior Moment

I thought I was through with this thread but I thought I should warn the young folk of what their inevitable future will bring. After Hippy posted his excellent description I thought that I'd make a spread sheet chart that would aid in finding values faster. After thinking about it for a while I thought "Why not write this in VB"? So I started up VB. While doing so I a little voice said "Did you do this already"? Something kept telling me that I once had a better understanding of the ReadAdc at an earlier date. Sure enough I found a volt to b val app that I wrote in 2008!

Getting old really bites!


Edit: Trying to add an attachment here is as much fun as a getting a root canal! :rolleyes:
 

westaust55

Moderator
To add an attachment first click on the "Go Advanced" button at the bottom right of your post window.
When the larger edit window has appeared, click on the paper clip icon in the toolbar at the top of your post window.
Then you access the Manage Attachments section with a new window to browse for, select and upload the attachments of choice. Finally click "Done" in the bottom right of the Manage Attachments window to return to you main post edit window.
 

CDRIVE

Senior Member
When I tried it last time I skipped the paper clip and went directly to "manage Attachments". It uploads my file but gives me a MessageBox when I click done. The MessageBox is telling my to drag the file into another box, which it won't do. After the upload there's an exclamation point next to my file name. It may be telling me its too large but since I can't find the standard ListBox that lists accepted files and file size, I don't know.

Thanks
 

CDRIVE

Senior Member
The voltage into the ADC (Vadc) is converted to a numeric result (Nadc) in accordance with the following equation -

Nadc = Vadc * Nmax / Vref

Nmax will be 255 for READADC, 1023 for READADC10. Vref is the reference voltage, usually the PICAXE supply voltage. The result will depend on what Vref / supply voltage you use which is why srnet asks.

If we assume you use READADC10, have a 5V supply, 1.25V into the ADC pin, it would be -

Nadc = Vadc * Nmax / Vref

Nadc = 1.25 * 1023 / 5 = 255.75 = 255

For 1.24V ...

Nadc = 1.24 * 1023 / 5 = 253.704 = 253
Sorry to drag this back to the front of the line but I do have a question. Unless I'm missing something, I can't see any scenario where Vref is not the Picaxe Vdd. If not the Picaxe Vdd than what and how?
 
Top