unstable ADC values sent to serial - 20X2

Sean87

Member
Hi all,

I have a 10k pot (Also tried with 470k pot). I use the following command to send the value which is stored in b1 :

Code:
let adcsetup = %0000000100000000
let dirsc = %00001100

main:
readadc c.1,b1
sertxd (#b1, CR)
goto main
Now the problem is I receive something like this (In this case I rotated the pot handle to the end)
Code:
255
255
255
255
255
255
255
255
248
245
255
255
245
255
255
255
255
255
255
255
255
255
255
255
255
248
As you can see, it is not 255 all the time.

I have to mention that I connected the pot to the same V+ of the chip which comes from a wall adapter that is pretty much stable at 3V. Can this be the problem? What can I do to improve this?

Thanks.
 

John West

Senior Member
Click on HELP on the command bar of the PICAXE Editor. Open Manual 1 to page 45, (Editor version 5.4.0) and there you'll find the Enhanced programming circuit. That may steady the readings for you, as there can be a problem with minor level fluctuations associated with being connected to a PC while reading the ADC, thus the "enhanced" version of the download circuit.

Also, a .1uF capacitor across the power supply pins at the PICAXE can help, as well as a 100uF or so bulk electrolytic capacitor across the same power pins. Plug-in bds in particular can be a bit noisy, so some filtering is in order.

Typically, I also add a .1uF cap from the pot wiper lead to ground to help ensure a stable voltage is being read by the PICAXE.
 
Last edited:

srnet

Senior Member
and there you'll find the Enhanced programming circuit. That may steady the readings for you, as there can be a problem with minor level fluctuations associated with being connected to a PC while reading the ADC, thus the "enhanced" version of the download circuit.
Interesting, how does the enhanced circuit affect\improve ADC readings ?
 

John West

Senior Member
As I understand it (not clearly) the Shottky diode establishes a better ground reference for the PICAXE by its nature of having a lower voltage drop than the chip's internal diodes, holding the PICAXE's ground reference more solidly to ground.

You have to realize that when currents flow they also flow through the ground parts of a circuit, and current flows cause voltage drops through even very low resistances, creating slight (or not so slight) shifting of the ground reference.

The currents flowing through the programming (communications) cable to the PC apparently worsen that ground shift on the chip substrate. Rev. Ed. has analyzed this and determined the nature of the problem and recommended the addition of the Schottky diode to solve it.

I hope I've described the situation accurately enough. I've not analyzed it myself, just read a bit about it in the forum. Perhaps one of the Rev. Ed. site gurus will correct me if I'm wrong in my description.
 
Last edited:

Goeytex

Senior Member
An ADC value jump from 255 to 245 suggests a voltage variation of about 100mv at the the ADC pin. This is quite a bit. I get zero deviation on my 20x2 with the same code but running at 5.05v. With ADC10 there is a max of 2 LSB deviation. You should be able to get similar results.

Try this.

Put a 10uf - 100uf bulk capacitor on the board where the Wall Adapter attaches. Small 3v wall adapters are usually "switchers" and can sometimes be rather noisy. Sometimes with very noisy switchers is helpful to put some resistance in the positive line before the bulk cap. Something like 10 -20 ohms might help and still allow up 150 - 300 ma of current if you need it.

Make sure there is a 100n bypass capacitor as close to the Picaxe +V ( Pin 1) as possible.

Place a 100n capacitor between Pin 9 (c.1) and ground. Then retest.

Also test in a range other than with the pot fully one way or the other. Some pots are flaky at the end of their travel.

If it still has the same problem, then try using two 1.5v Batteries for the 3.0v supply and see how that goes. If the problem goes away then the supply or something related is the likely culprit.

I am assuming of course that you do not have the Picaxe blinking 10
LED's at max current all the time....
 

srnet

Senior Member
As I understand it (not clearly) the Shottky diode establishes a better ground reference for the PICAXE by its nature of having a lower voltage drop than the chip's internal diodes, holding the PICAXE's ground reference more solidly to ground.
Dont make sense to me.

The Ov of the PICAXE is already connected to the ground referance of the PC via the serial cable anyway.
 

eclectic

Moderator
Dont make sense to me.

The Ov of the PICAXE is already connected to the ground referance of the PC via the serial cable anyway.
No, I am not an expert, but please see:

Manual 1, P. 171
then an advanced search using both the terms

enhanced BAT85

e
 

John West

Senior Member
Goeytex, I think the problem isn't a change of input voltage to the ADC, but a change of current flowing through the internal diode on the PIC substrate that is used to establish the reference voltage against which input voltages are measured.

In any event, Rev. Ed. has gone to the effort in Manual 1 to clearly document a fix for it. All that's left to do is implement it.
 
Last edited:

jtcurneal

Senior Member
I have had similar things happen when I used an older pot that had poor contact between the wiper and the resistive contact surface.

Joel
 

John West

Senior Member
Dont make sense to me.

The Ov of the PICAXE is already connected to the ground referance of the PC via the serial cable anyway.
Any current flowing through a wire, including ground wires, will drop a voltage due to the resistance (however small) of the wire. No two points share precisely the same ground voltage. Star ground configurations come about as close as we can get.
 

srnet

Senior Member
In any event, Rev. Ed. has gone to the effort in Manual 1 to clearly document a fix for it. All that's left to do is implement it.
My reading of that bit of the manual is that the extra diode works to improve the switching point of the RS232 incoming signal about the zero point to make it more symetrical, not that it helps with the ADC reference.
 

Sean87

Member
An ADC value jump from 255 to 245 suggests a voltage variation of about 100mv at the the ADC pin. This is quite a bit. I get zero deviation on my 20x2 with the same code but running at 5.05v. With ADC10 there is a max of 2 LSB deviation. You should be able to get similar results.

Try this.

Put a 10uf - 100uf bulk capacitor on the board where the Wall Adapter attaches. Small 3v wall adapters are usually "switchers" and can sometimes be rather noisy. Sometimes with very noisy switchers is helpful to put some resistance in the positive line before the bulk cap. Something like 10 -20 ohms might help and still allow up 150 - 300 ma of current if you need it.

Make sure there is a 100n bypass capacitor as close to the Picaxe +V ( Pin 1) as possible.

Place a 100n capacitor between Pin 9 (c.1) and ground. Then retest.

Also test in a range other than with the pot fully one way or the other. Some pots are flaky at the end of their travel.

If it still has the same problem, then try using two 1.5v Batteries for the 3.0v supply and see how that goes. If the problem goes away then the supply or something related is the likely culprit.

I am assuming of course that you do not have the Picaxe blinking 10
LED's at max current all the time....
Thanks for info.

Actually I have those 10 LED's conencted to the chip to test the ADC...I will try to remove them and try again, also I will try those caps as soon as I get them.
 

hippy

Ex-Staff (retired)
The BAT85 diode in the Enhanced Download Circuit as I understand it is to deal with the potentially adverse affects of an incoming RS232 signal into the Serial In going negative.

The internal diode on the Serial In pin should clamp the current limited negative voltage close to 0V. This should mean no affect on ADC readings but on some PICAXE it does sometimes affect the ADC. I'm not sure anyone is entirely sure how and why the problem manifests itself but the external Schottky diode, with a lower Vforward than the internal diode, clamps the negative voltage closer to 0V or does the job better and mitigates this.

I've also had good results putting a standard signal diode ( 1N4148 etc ) in series with the PC TX line meaning it can only put out positive voltage. That can however introduce its own problems with higher baud rates.

Using the AXE027 ( or any 0V/+Ve signal ) there should be no negative voltage and the Enhanced Download Circuit should not be required.
 

Technical

Technical Support
Staff member
Dont make sense to me.

The Ov of the PICAXE is already connected to the ground referance of the PC via the serial cable anyway.
That is correct, 0V is connected. And when using the AXE027 USB cable there will never be any issues, because, as the AXE027 is a Logic level device, the serin pin only receives clean 0V or 5V signals.

However traditional serial cables (including some 'universal' usb adapters) give out RS232 level voltages, which can be anywhere from -12V to +12V with reference to the connected 0V. However most computers' serial ports these days are actually much nearer 0V-5V, but some are not.

The 10k/22k download circuit *together* with the internal diodes in the PICAXE chip, handle this voltage range absolutely fine, the internal diodes clipping any negative voltage to about -0.6V. But this small negative difference can occasionally affect the accuracy of the ADC *when the cable is plugged in* (e.g when using debug or sertxd). The enhanced download circuit helps makes this situation better by using a more 'effective' diode than the default internal diode.

So in summary the enhanced serial circuit is only a help when:
1) using a traditional RS232 signal with a large negative voltage swing
2) and the cable is actually connected

If using an AXE027 you can forget about this all together!
 

srnet

Senior Member
The 10k/22k download circuit *together* with the internal diodes in the PICAXE chip, handle this voltage range absolutely fine, the internal diodes clipping any negative voltage to about -0.6V. But this small negative difference can occasionally affect the accuracy of the ADC *when the cable is plugged in* (e.g when using debug or sertxd)
That I can see, in the circumstance where data is being recieved at the same time as the ADC is being used.
 

Sean87

Member
Do you have access to a CRO? Can you observe the +5v line and the the ADC voltage?
I just have a digital multimeter dont think it will be helpful.

I am now confused a lot. This topic became a PRO users talking...so can somone simplify what shoud I do at the end please?
 

Dippy

Moderator
I think most of the answers are in there somewhere :)

(Not necessarily in this order);
1. Use the Enhanced download circuit or an AXE027 or similar.
2. Put capacitors on the PICAXE `V and 0V pins as CLOSE as physically possible to the PICAXE chip legs.
This is Good Practice in all case. And particulalry important when using ADC. Often referred to as decoupling/bypass capacitors.
3. This bit is tricky without the correct gear... check stability of the power in line. It must be smooth and stable.
If you have some crappy old bit of cheap tat wall+wart then unless you can check it and/or smooth it then you are wasting your time.
It MAY be good to try some fresh batteries for testing and comparison.
4. Similarly, check your 'signal'. If you put a small cap from wiper to ground this may help. Or, use a bit of RC.
5. Keep everything away from noisy sources.

Bottom line: stability.
REMEMBER, in most cases the supply voltage PICAXE will be the REFERENCE.
Even if your PSU is good , the PIC , by its very nature, will introduce noise ; hence the decoupling caps play a dual role.

Don't go daft and splatter everything with dusty old monster caps.
People often use a ceramic capacitor in parallel with an electrolytic for decouple/bypass of the power supply.
Capacitors behave differently and this is a proven low-cost combination.

Ultimately, without a 'scope your design will require a bit of luck ;)
If you want to persue electronics and want to make fancy designs then you will be stuffed without one.
Save up - get a good one.
 
Last edited:

hippy

Ex-Staff (retired)
I am now confused a lot. This topic became a PRO users talking...so can somone simplify what shoud I do at the end please?
Perhaps the two most important things are -

1) Let us know which download cable you are using.

2) Run powered from fresh batteries and let us know if that improves things.
 

Goeytex

Senior Member
I just have a digital multimeter dont think it will be helpful.

I am now confused a lot. This topic became a PRO users talking...so can somone simplify what shoud I do at the end please?
Sean, you stated, "Well I just have the chip, pot and some wires and LED's on a bread board...."

This implies that:

1. There is no bulk capacitor on the breadboard and ..
2. The Picaxe has not been bypassed with a .1uf capacitor.

(These are standard practice bare minimums that should always be done.)

You did not mention current limiting resistors for the LED's so we are forced to guess if you are using them, how many and what value resistors you have used. Mentioning the LEDS also implies that you are driving a substantial load somehow for testing the ADC.. as you eluded to in another posting.

My guess is that you are not providing a complete picture of what you are doing and what is connected to what. If so, then by omitting important details of your project you are limiting how you can be helped.

Please post a complete and exact schematic diagram of your project. Leave out nothing. Also post your complete programming code ( not just the ADC part) .

If possible take a clear photo of your project and post it here so that others can review it.

There is no reason to be confused. If you are using a USB download cable then don't worry about the "enhanced download circuit" . It is not the problem. ONLY if you are using the serial cable attached to a PC RS232 port would the enhanced circuit make any difference anyway. And even then it's not a sure fix for your problem. It's something to consider AFTER after taking care of the basics.

Goeytex
 
Last edited:

Sean87

Member
Well my setup is as following:

1- 3V Wall adapter which provides very smooth 3.1V (I'v checked this with multimeter)
2- I am using AXE026 (serial cable) ** I had to cut the stereo jack because I lost it and I soldered the wires into some jumpers.
3- I have 10 LED's connected to the 20x2 to indicate ADC values
4- there is only the 10k and 22k resistors as suggested by manual for donwloading progams into chip
5- nothing more is connected.

here is a video of my setup:
http://www.youtube.com/watch?v=_X0OY3TVbO4

You can see the last LED is sometimes blinking. In the program I wrote if ADS is bigger than 245 the last LED should be ON...so my ADC is not stable and sometimes it goes under 245 I guess mybe thats why it blinks?
 

Sean87

Member
What is the program?

e
Code:
let adcsetup = %0000000100000000
let dirsc = %00001100

main:
readadc c.1,b1
sertxd (#b1, CL)

SELECT b1

CASE 0
low 0,1,2,3,4,5,6,7,c.2,c.3

CASE 1 TO 25
low 1,2,3,4,5,6,7,c.2,c.3
high 0

CASE 25 TO 50
low 2,3,4,5,6,7,c.2,c.3
HIGH 0,1

CASE 50 TO 75
low 3,4,5,6,7,c.2,c.3
HIGH 0,1,2

CASE 75 TO 100
low 4,5,6,7,c.2,c.3
HIGH 0,1,2,3

CASE 125 TO 150
low 5,6,7,c.2,c.3
HIGH 0,1,2,3,4

CASE 150 TO 175
low 6,7,c.2,c.3
HIGH 0,1,2,3,4,5

CASE 175 TO 200
low 7,c.2,c.3
HIGH 0,1,2,3,4,5,6

CASE 200 TO 225
low c.2,c.3
HIGH 0,1,2,3,4,5,6,7

CASE 225 TO 245
low c.3
HIGH 0,1,2,3,4,5,6,7,c.2

CASE > 245
HIGH 0,1,2,3,4,5,6,7,c.2,c.3

ENDSELECT

goto main
 

eclectic

Moderator
Three quick points.

1. You are living dangerously with no resistors!

2. Is the
potentiometer
giving consistent readings?

3. See Dippy's post above.

e
 

jtcurneal

Senior Member
Originally Posted by eclectic: "OK, can you swap the pot. for another?"

For another pot, use one that is 10k or less.

Joel
 

Technical

Technical Support
Staff member
There is a very simple check to do, remove the wire to the pot and connect it to your 3V supply rail instead. What happens then, do the lights all stay on permanently?
 

Sean87

Member
There is a very simple check to do, remove the wire to the pot and connect it to your 3V supply rail instead. What happens then, do the lights all stay on permanently?
I checked this and the last LED is still blinking. and when I totaly remove the V line from ADC pin, the first LED blinks.
 

Technical

Technical Support
Staff member
Then the pot is irrelevent and you need to sort out the other mistakes on your circuit.
1) put a 100nF decoupling capacitor across the PICAXE power pins
2) add those missing LED resistors as EC has already pointed out. They *are* required.
4) try with a 3V or 4.5V battery pack instead of your power supply. A multimeter will *not* show noise on the rail.
 

Sean87

Member
Thanks, at the moment I only have a 470µF electrolit cap and I put it across V+ and GND of the chip. This till now hs showed much better result, no LED is blinking now and also the sertxd command seems to send more stable values to my PC (for 255 it only sometimes jump to 253 or 254).
 

Goeytex

Senior Member
Why aren't you using current limit resistors on the LED's ?

Driving 10 LED's directly from the Picaxe with no current limit resistors is a very very bad idea.

Each LED should have a current limit resistor in series. I would suggest 470 ohms . This will allow approx 7 ma per LED leg for a total of 70 ma of current through the Picaxe when all the LEDs are lit.

If you want brighter LEDS then use a 2N3904 NPN or equivalent transitor on each LED so that the transistor is driving the LED and not the Picaxe.

All this info ( except the 90ma max) is in in Manual 3. You should read it and make it your best friend.

The way you have it ( no resistors) is probably causing the Picaxe to overheat and become unstable by exceeding its total current capability of 90ma. It may have already become damaged. Get this corrected before wasting your time with the enhanced DL circuit.

And add the bulk capacitor! Not at the chip ! ... but where the Power Supply leads go to the board. Put the smaller 100n decoupling capacitor near the chip.

BTW.... You CANNOT tell if voltage is "smooth" with a multimeter. You could have 100mv of 50hz ripple and your multimeter will never show it.
 
Last edited:
Top