Is the readadc10 function reliable (readadc)

JBrookes

Member
I'm posting this question as my results with the readadc10 on the 08M2 have been variable. In my circuit, I was measuring a voltage divider between a 5k pot and a 5k thermistor. When I turned the pot, the displayed value in debug did not change or it went to a random value.

Rather than speculating at this time on my setup, I'd like to hear from anyone who HAS achieved reliable results from readadc10. That's first.

Here is code for readadc10:

loop:
readadc10 4,w2
pause 500
debug w2
goto loop

Ok, Now about my circuit. Here are some items about adc which are not commonly known. I am in process of testing readadc10 with these items fixed:

MUST use a ground plane under all analog circuitry
MUST put .1 microfarad cap across V-GND pins on all analog chips
MUST use 10mF cap on power supply source
PREFER highpass/bandpass filtering on adc input.

The question is whether the picaxe adc is a toy or capable of reliable use - Some experts criictize mcu-internal adc as being too polluted by switching noise from digital circuits.

Overall, I am contemplating switching an led with a square wave and detecting with a photodiode.

jb
 

bfgstew

Senior Member
Have you tried using a FOR/NEXT loop then average the reading out, rather than using a 500ms pause, by the time the next reading is due the value is going to be way out.
I have never used readadc10, l but use readadc a lot and have no trouble using it the way I suggested, others will beg to differ and rightly so, but I believe averaging your readings will give you a more accurate value.
 

geoff07

Senior Member
It sounds as though you have a noisy pot. Try two fixed good quality resistors and see what consistency you get.
 

matherp

Senior Member
Using 2 off 10K 0.1% resistors as a potential divider from the power rails into a 08m2, no filtering of any sort on an axe091, I get values between 510 and 514. Doing 10 x readadc10 and averaging reduces the range to 510-512. Adding a 2Kohm/220nF filter reduces averaged range to 511,512
 

rq3

Senior Member
I'm posting this question as my results with the readadc10 on the 08M2 have been variable. In my circuit, I was measuring a voltage divider between a 5k pot and a 5k thermistor. When I turned the pot, the displayed value in debug did not change or it went to a random value.

Rather than speculating at this time on my setup, I'd like to hear from anyone who HAS achieved reliable results from readadc10. That's first.

Ok, Now about my circuit. Here are some items about adc which are not commonly known. I am in process of testing readadc10 with these items fixed:

MUST use a ground plane under all analog circuitry
MUST put .1 microfarad cap across V-GND pins on all analog chips
MUST use 10mF cap on power supply source
PREFER highpass/bandpass filtering on adc input.

The question is whether the picaxe adc is a toy or capable of reliable use - Some experts criictize mcu-internal adc as being too polluted by switching noise from digital circuits.

Overall, I am contemplating switching an led with a square wave and detecting with a photodiode.

jb
I invoke readadc10 in the code for a small quantity commercial product, which reads an analog input over 30 feet of wire in a wickedly noisy environment, and does it very well.

Your "not commonly known" ideas are actually very commonly known, except that a lowpass filter on the input would be more useful than a bandpass or high pass response. A very low impedance power plane AND ground plane, locally by-passed at the Picaxe is very desirable (4 layer PC board).

I suspect that the thermistor may be part of your problem. Depending on the thermistor response curve, and the thermal mass of the thermistor, you will see many hundreds of ohms of variation just from air currents in the room.

A very clean, linear regulated power supply (or batteries during bench experimentation) is also critical. Trying to clean up supply noise with by-pass caps after the fact will be very frustrating. A switching regulator of any kind WILL be producing supply ripple and noise that is not ratiometric to the readadc conversion, and you will see it as random variations in the result.

Hope this helps,
Rip
 

srnet

Senior Member
Here are some items about adc which are not commonly known. I am in process of testing readadc10 with these items fixed:
MUST use a ground plane under all analog circuitry
MUST put .1 microfarad cap across V-GND pins on all analog chips
MUST use 10mF cap on power supply source
Those are no more than standard, and very commonly know design criteria if you want reliable ADC readings.

Although even without some 'must haves' you can get very reliable results.
 

srnet

Senior Member
I'd like to hear from anyone who HAS achieved reliable results from readadc10.
The PICAXE readadc10 is capable of very reliable results indeed.

I used that command to read the battery voltage on the PICAXE satellite code, and despite the somewhat extreme environment, the reading only seems to vary by +\- one bit, which is as good as you can expect.

The question is whether the picaxe adc is a toy or capable of reliable use
Its been very reliable on the PICAXE satellite.

Some experts criictize mcu-internal adc as being too polluted by switching noise from digital circuits.
Then maybe they are not 'experts' at all.

With proper attention to circuit design an layout then an mcu internal adcs (10 bit) is perfectly capable of acceptable results.
 

BeanieBots

Moderator
With proper layout and a decent power supply, ReadADC10 should not (and does not) jitter more than 1 count.
Things which can go wrong are:-
Poor power supply.
Inadequate or wrong decoupling.
PICAXE setup wrong.
Too high source impedance.
-ve RS232 levels direct into serin. (See advanced download circuit)
 

Goeytex

Senior Member
Ok, Now about my circuit. Here are some items about adc which are not commonly known. I am in process of testing readadc10 with these items fixed:

MUST use a ground plane under all analog circuitry
MUST put .1 microfarad cap across V-GND pins on all analog chips
MUST use 10mF cap on power supply source
PREFER highpass/bandpass filtering on adc input.
These are (as Rip indicated) actually quite well known but many times ignored. I disagree that they are "musts" ,but rather "good practice where possible."

There is no good reason to omit a bypass capacitor from IC's (analog or digital). A ground plane is nice, but impractical/ impossible on stripboard or a breadboard. Similar performance can be attained by using a star ground technique on breadboards or home spun boards.

Many times problems similar to that described can be attributed to a crappy power source, sloppy/ poor grounding, wires snaking all over the place, & components sticking up like little antennas. (I am referring to a breadboard.) I have not seen a "noisy pot" in 5 years, but then I use Bournes pots and not grab bag stuff from Ebay.

With a stable supply, and proper grounding, I consistently get around +- 1 LSB deviation with READADC10 on a common breadboard. (Without a low pass/band pass filter).

If on a breadboard, I would suggest removing the thermistor & just use the pot. Then test again. If the random return values continue, then employ star grounding on the breadboard. If there is "offset", meaning with the pot at 0 ohms and the ADC reading is above zero, then place a ground wire directly from the Picaxe 0V pin to the ground side of the Pot. Any offset should then disappear. This all assumes a bypass cap across the Picaxe + V & 0V pin and a reasonably sized filter/bulk cap on the breadboard where the power lead are connected. I generally use a 22uf cap.

The question is whether the picaxe adc is a toy or capable of reliable use - Some experts criictize mcu-internal adc as being too polluted by switching noise from digital circuits.
The Picaxe ADC is no more a "toy" than that of any PIC ( It is a PIC), or any other MCU. Reliable use depends upon if the designer can follow good practice or not.

I might question who these "experts" are and how they got to be experts. Some "experts" (and might I add amateurs) use mcu-internal ADC's without a hitch. However, for critical applications where absolute accuracy is needed, an external ADC might be the best choice.

Goeytex
 
Last edited:

Billo

Senior Member
. In my circuit, I was measuring a voltage divider between a 5k pot and a 5k thermistor.
So your source impedance is 2.5K or less. I have had great (+/- 2 bits or better) results with source impedance of over 5K on a simple solderless breadboard. No special precautions at all.


Overall, I am contemplating switching an led with a square wave and detecting with a photodiode.

jb
Would you really need 10 bit resolution for this?
 

JBrookes

Member
Using 2 off 10K 0.1% resistors as a potential divider from the power rails into a 08m2, no filtering of any sort on an axe091, I get values between 510 and 514. Doing 10 x readadc10 and averaging reduces the range to 510-512. Adding a 2Kohm/220nF filter reduces averaged range to 511,512
Thank you. I feel better already. Any feel for the signal capture time? I believe the entire readadc10 takes about .5 msec. , most of which is probably Basic interpreter overhead.
 

JBrookes

Member
I invoke readadc10 in the code for a small quantity commercial product, which reads an analog input over 30 feet of wire in a wickedly noisy environment, and does it very well.

Your "not commonly known" ideas are actually very commonly known, except that a lowpass filter on the input would be more useful than a bandpass or high pass response. A very low impedance power plane AND ground plane, locally by-passed at the Picaxe is very desirable (4 layer PC board).

I suspect that the thermistor may be part of your problem. Depending on the thermistor response curve, and the thermal mass of the thermistor, you will see many hundreds of ohms of variation just from air currents in the room.

A very clean, linear regulated power supply (or batteries during bench experimentation) is also critical. Trying to clean up supply noise with by-pass caps after the fact will be very frustrating. A switching regulator of any kind WILL be producing supply ripple and noise that is not ratiometric to the readadc conversion, and you will see it as random variations in the result.

Hope this helps,
Rip
Yes, thank you. Very affirming for the Pic adc Faith, I must say. I had the T'istor in ie bath, so stable temp. I believe, judging from the personal experience reviews, that I must have had a noisy potentiometer.
About commonly known, you must admit in the Picaxe world, as well as the Arduino/Raspberry Pi/BeagleFood genre, that many users are amateurs, and what is known to experienced people is not to many new comers. I myself, despite being a ham radio person in my youth ("amateur radio"), did not have impressed on me the necessity of decoupling and sometimes filtering, based on casual readings in the analog field.
 

hippy

Technical Support
Staff member
Make sure the analogue signal is connected to PICAXE pin 4 (leg 3) and not to leg 4. Perhaps try the input with a simple pot across +V and 0V and see how that behaves.
 

JBrookes

Member
Have you tried using a FOR/NEXT loop then average the reading out, rather than using a 500ms pause, by the time the next reading is due the value is going to be way out.
I have never used readadc10, l but use readadc a lot and have no trouble using it the way I suggested, others will beg to differ and rightly so, but I believe averaging your readings will give you a more accurate value.
Yes, my readings were so outlandish, I knew I did not have a small noise source. I may have had a cold solder joint/noisy poy. In addition I had the thermistor on 18 inches of twisted pair wire. As I think of it, I suspect the cold solder joint, as it was very wiggly. I will repewat everything with fixed resistors.
The next issue concerns what a low pass filter will do to a square wave - I'll post something separate on. JB
 

JBrookes

Member
Using 2 off 10K 0.1% resistors as a potential divider from the power rails into a 08m2, no filtering of any sort on an axe091, I get values between 510 and 514. Doing 10 x readadc10 and averaging reduces the range to 510-512. Adding a 2Kohm/220nF filter reduces averaged range to 511,512
In case I did not reply to this, this is very encouraging. Thank you. JB
 

JBrookes

Member
Those are no more than standard, and very commonly know design criteria if you want reliable ADC readings.

Although even without some 'must haves' you can get very reliable results.
Yes, that may be, but when something goes wrong, and I don't know what it is, I am like the Queen in Alice in Wonderland, "Off with their heads!" :)
 

JBrookes

Member
The PICAXE readadc10 is capable of very reliable results indeed.

I used that command to read the battery voltage on the PICAXE satellite code, and despite the somewhat extreme environment, the reading only seems to vary by +\- one bit, which is as good as you can expect.



Its been very reliable on the PICAXE satellite.



Then maybe they are not 'experts' at all.

With proper attention to circuit design an layout then an mcu internal adcs (10 bit) is perfectly capable of acceptable results.
OK excellent. Thank you. Nice to know there IS cheese at the end of the tunnel. :)
 

JBrookes

Member
With proper layout and a decent power supply, ReadADC10 should not (and does not) jitter more than 1 count.
Things which can go wrong are:-
Poor power supply.
Inadequate or wrong decoupling.
PICAXE setup wrong.
Too high source impedance.
-ve RS232 levels direct into serin. (See advanced download circuit)
Yes, I've gotten quite a response detailing good results.
Could you elaborate on RS232 issue?
JB
 

john2051

New Member
Hi
Regarding this issue of using bandpass/low pass filters. Since the voltage is dc, does this not mean we just need
a very low frequency bandpass filter?
just curious, because I need to measure battery voltages whilst charging fairly accurately.
regards john
 

JBrookes

Member
Thanks. Comments below marked with @@@:

These are (as Rip indicated) actually quite well known but many times ignored. I disagree that they are "musts" ,but rather "good practice where possible."

There is no good reason to omit a bypass capacitor from IC's (analog or digital). A ground plane is nice, but impractical/ impossible on stripboard or a breadboard.

@@@ Thanks.I have been pondering this, and it occurred to me that a piece of copper foil can easily be glued to underside of the white pin boards and grounded. With a through-hole board, it can be covered with tape to insulate it,
and then taped to the underside (and grounded). This allows changes to be made.

Similar performance can be attained by using a star ground technique on breadboards or home spun boards.

Many times problems similar to that described can be attributed to a crappy power source, sloppy/ poor grounding, wires snaking all over the place, & components sticking up like little antennas. (I am referring to a breadboard.) I have not seen a "noisy pot" in 5 years, but then I use Bournes pots and not grab bag stuff from Ebay.
@@@ I had a cold solder joint, and maybe was culprit.
With a stable supply, and proper grounding, I consistently get around +- 1 LSB deviation with READADC10 on a common breadboard. (Without a low pass/band pass filter).
@@@ok thanks.
If on a breadboard, I would suggest removing the thermistor & just use the pot. Then test again. If the random return values continue, then employ star grounding on the breadboard. If there is "offset", meaning with the pot at 0 ohms and the ADC reading is above zero, then place a ground wire directly from the Picaxe 0V pin to the ground side of the Pot. Any offset should then disappear. This all assumes a bypass cap across the Picaxe + V & 0V pin and a reasonably sized filter/bulk cap on the breadboard where the power lead are connected. I generally use a 22uf cap.

@@@ I'm getting rid of pot.

The Picaxe ADC is no more a "toy" than that of any PIC ( It is a PIC), or any other MCU. Reliable use depends upon if the designer can follow good practice or not.

I might question who these "experts" are and how they got to be experts. Some "experts" (and might I add amateurs) use mcu-internal ADC's without a hitch. However, for critical applications where absolute accuracy is needed, an external ADC might be the best choice.
@@@ The opinion was by Bonnie Baker in n Analog Design book edited by Robert Pease. BB has books on op amps and adc written, and she has been a senior engineer at Microchip and TI.
That being said, the saying: "An expert is a person from the next town over." :) JB

Goeytex
 

JBrookes

Member
So your source impedance is 2.5K or less. I have had great (+/- 2 bits or better) results with source impedance of over 5K on a simple solderless breadboard. No special precautions at all.




Would you really need 10 bit resolution for this?
@@@ Good question. But jitter was so wild I had to investigate. (+/- 50%) JB
 

JBrookes

Member
You can just put a 1 microfarad cap from the pin to ground. More sophisticated filters use an op amp and a few caps plus resistors. (active filters). Here are several web sites with software to
design these filters:
FilterPro - ti.com
FilterLab - Microchip.com
FilterWizard - analog.com

These are free programs, and its easy to design and make these. The more bandwidth you filter out, the lower your noise is, and the higher the SNR.
Did you say this was for a rocket in a hostile EMP environment? :)
 

JBrookes

Member
Make sure the analogue signal is connected to PICAXE pin 4 (leg 3) and not to leg 4. Perhaps try the input with a simple pot across +V and 0V and see how that behaves.
puzzling. I had connectd it to pin 3, and the command was
readadc10 4, w2

??
JB
 

inglewoodpete

Senior Member
puzzling. I had connectd it to pin 3, and the command was
readadc10 4, w2

??
JB
A terminology problem. In the world of the PICAXE (and other higher level microcontroller languages), a "LEG" is the physical piece of metal sticking out of the device (Leg 4) and a "PIN" is the virtual ID reference to it (Eg Pin C.3).
 

BeanieBots

Moderator
Could you elaborate on RS232 issue?
Most people use the AXE027 download cable which is not a problem because it uses 5v logic.
However, if you are using a true RS232 connection, it will be typically +/- 12v.
The download circuit protects the PICAXE from these voltages but some current will flow through the internal clamp diodes. In most cases, this is not a problem.
However, when it comes to the internal ADC circuitry, any negative current (RS232 idle low) going through the diode clamps mucks up the ADC reading.
This usually presents itself as different readings depending on if the download cable is plugged in or not rather than erratic readings.

I have had a similar issue to yourself where the ADC value only appeared to give a vague resemblance to the voltage being measured. This was tracked down to the issue pointed by hippy earlier. Namely, reading the wrong pin. The ADC input impedance is so high that a floating pin is likely to follow the voltage on the pin next to it making it look like erratic readings.
 

srnet

Senior Member
Yes, that may be, but when something goes wrong, and I don't know what it is, I am like the Queen in Alice in Wonderland, "Off with their heads!" :)
Not the best policy at all.

Far better to assume that if something does not work as expected, you assume its something wrong with your circuit.

Speculating about your circuit, is very likely where a solution to your problem lies.
 

JBrookes

Member
Most people use the AXE027 download cable which is not a problem because it uses 5v logic.
However, if you are using a true RS232 connection, it will be typically +/- 12v.
The download circuit protects the PICAXE from these voltages but some current will flow through the internal clamp diodes. In most cases, this is not a problem.
However, when it comes to the internal ADC circuitry, any negative current (RS232 idle low) going through the diode clamps mucks up the ADC reading.
This usually presents itself as different readings depending on if the download cable is plugged in or not rather than erratic readings.

@@@NOW you've got my interest about the pin issue, as I don't follow what you are saying at all. hmmm I think I see. However, I was using a dev board which had the channels (approximate word) marked on it - eg channel 4 is pin 3, etc. Eventually what happened is that the adc circuit blew out on the chip, and it read near 1000 continuously.

I have had a similar issue to yourself where the ADC value only appeared to give a vague resemblance to the voltage being measured. This was tracked down to the issue pointed by hippy earlier. Namely, reading the wrong pin. The ADC input impedance is so high that a floating pin is likely to follow the voltage on the pin next to it making it look like erratic readings.
The posting nanny complained about msg too short, xxxxxxxxxxxxxxxxxxxxxxx
 

JBrookes

Member
Not the best policy at all.

Far better to assume that if something does not work as expected, you assume its something wrong with your circuit.

Speculating about your circuit, is very likely where a solution to your problem lies.

@@@ I have found that, in designing circuits, every component has its limits and quirks. For example, a potentiometer may be noisy or an op amp leaky. That is why I came here to the Picaxe forum - to see whether others had the erratic adc problem. If the problem was noise sensitivity, then filtering might cure it. Part of my suspicion is that I have seen others have this problem with the picaxe adc. So I investigated the rules for a stable adc input, and found distributed decoupling and ground plane a MUST. It's like the belt on your pants: It's optional, but a good idea to use just in case. In other words, a sensitive analog circuit preceding the adc must be carefully guarded against noise. If the transducer circuit is low impedance, this relaxes things a bit, but, like the belt on your pants, the precaution is easy to use, so it's a good idea to use it.
Now, with analog design (as opposed to digital), problems can happen which are invisible and not easily assigned to circuit mistakes or poor design. For example, oscillation and ringing can occur up into the ghz range, which is impossible to see with common equipment. Other problems can be noise from certain components or layout acting as an antenna. Noise can travel from the digital part to the analog through the power supply or other coupling paths.
Given all these possibilities, the precautions of ground plane and decoupling on each and every chip are a MUST.
Just my opinion, gained from reading the log drummers in the analog voodoo world. :)
 

srnet

Senior Member
Noise can travel from the digital part to the analog through the power supply or other coupling paths.
Given all these possibilities, the precautions of ground plane and decoupling on each and every chip are a MUST.
Just my opinion, gained from reading the log drummers in the analog voodoo world. :)
Its very misleading to maintain that if your using AD then you 'MUST' have a PCB with a ground plane, simply because its not true.

The decoupling is very important, but in no way is a ground plane mandatory to get reliable results form AD.
 

Dippy

Moderator
I think you are absolutely spot-on with investigating ADC performance from a variety of sources - though do beware of some 'experts'.

The experienced users here have given excellent advice and DO heed Beaniebot's point about the download circuitry which is peculiar to PICAXE.
(You haven't responded to his description in any detail so I'm not sure you understand).

I agree with srnet's points though, as usual, it's horses for courses. In electronics you use design techniques appropriate to the task or environment.
What has been said is, on the whole, good practice.

Most of us Old Hands have been using some/all of your "not commonly known" ideas for years. I have an extra one to add to your list: that processor power decoupling/bypassing is also to reduce digital noise sneaking out. Using several parallel cascaded-value decoupling caps is commonly used in dsPIC circuits and similar. Get the 700 page datasheet and read through it :)

On the whole I have found PIC ADC to be perfectly good for low/medium quality measurements. And you don't need high precision for most hobby applications.

From memory, my last two ADC cock-ups were caused by me; one was inadequate Cout on a regulator and the other was bad-handling of a dsPIC damaging (but not completely wrecking) the ADC channel.

Unless you have damaged something you will likely find your problem is down to your design/layout... though, as I haven't seen your circuit, I'll not rule out any oddities.
 

JBrookes

Member
Its very misleading to maintain that if your using AD then you 'MUST' have a PCB with a ground plane, simply because its not true.

The decoupling is very important, but in no way is a ground plane mandatory to get reliable results form AD.
Again, I am just quoting guys like Jim Williams, Dobkins, Pease, etc.
Jim Williams prototypes (or did) on clad pcb board which is a ground plane.
See articles in EDN like
"Whats all this ground noise about, anyway?" - R Pease
 

JBrookes

Member
I think you are absolutely spot-on with investigating ADC performance from a variety of sources - though do beware of some 'experts'.

The experienced users here have given excellent advice and DO heed Beaniebot's point about the download circuitry which is peculiar to PICAXE.
(You haven't responded to his description in any detail so I'm not sure you understand).

@@@ We talked about RS-232. I am using USB.

I agree with srnet's points though, as usual, it's horses for courses. In electronics you use design techniques appropriate to the task or environment.
What has been said is, on the whole, good practice.

Most of us Old Hands have been using some/all of your "not commonly known" ideas for years. I have an extra one to add to your list: that processor power decoupling/bypassing is also to reduce digital noise sneaking out. Using several parallel cascaded-value decoupling caps is commonly used in dsPIC circuits and similar. Get the 700 page datasheet and read through it :)

On the whole I have found PIC ADC to be perfectly good for low/medium quality measurements. And you don't need high precision for most hobby applications.

From memory, my last two ADC cock-ups were caused by me; one was inadequate Cout on a regulator and the other was bad-handling of a dsPIC damaging (but not completely wrecking) the ADC channel.

Unless you have damaged something you will likely find your problem is down to your design/layout... though, as I haven't seen your circuit, I'll not rule out any oddities.
@@@ Thanks. A Jim Williams quote borrowed from Richard Feynman.
"When I start a project, unless I'm totally confused, I'm doing something wrong."
 
Top