ADC values Floating (Noob Newbie Question)

fcd72

New Member
Guys and Ladies (if there are any....)

sorry to bother your with this question thats probably been asked a 1000 times but obviously i am to dumb to use the search function correctly.

I try to read out the Value from an Pot that is used as a simple Voltage Divider between Vcc an GND. I wrote a simple loop that reads the Value from a Pin and writes it and the difference from the last known Value to the LCD.

My Code works, the problem is that the values read float ± 4 - is this normal? Am I missing something?

Thanx for your Help,

Frank
 

Goeytex

Senior Member
Without seeing your circuit it's hard to tell, but +- 4 with 8bit ADC is not too good. The likely causes could be:

1. No Bypass/decoupling capacitor across the Picaxe +V and 0v Pins
Solution: Add a .1us cap from Picaxe +V to ground.

2. Noisy / Unstable Power supply. Maybe a cheap Wall Wart or Cheap Cell Phone Charger
Solution: Try 3 1.5V Batteries instead. Try a different Power Supply.

3. Long wires from Power Supply to Bread Board/ Proto Board.
Solution: Put a 10uf to 100uf Bulk/Filter on the board where +V
from the supply enters the board. Cap goes from +V to GND.

4. Pot has too much resistance. ( 100K is too much)
Solution. Use a 10K pot
 
Last edited:

fcd72

New Member
Yo Goeytex,

Thanks for your Quick reply.....

Im using the 20M2 Demo board so

1) the decoupling Cap is there by default
2) Im Using Batteries....
3) I soldered approx 15cm directly to the demo Board - 100µF installed where you said
4) its 10KLin

I now have whoopping 570µF Elkos buffering the Supply and i'm down to ± 1 with ±0 below approx 80... any Expierience i can bring it down to 0 completely ('im out of Caps ;-) ) or should i software-smoothen the Signal ? Im not that impressed with the accuracy....

Greetz to Texas!
 
Last edited:

Goeytex

Senior Member
You will likely never get zero deviation unless you have a 10 - 22 turn pot and can set it dead center between
two numbers. You may also want to try a .1uf cap from the ADC PIN to GND.

You can take 5 readings and then do an average to smooth it out. The "accuracy" is the same as any PIC and is probably
more dependent upon external circuitry, wiring, board layout, quality of the pot, etc than the microprocessor itself. I consistently
get +- 2 or less using ADC10 ( 10 bit).

+- 0 is an unreasonable expectation unless YOU buffer the signal from the pot to the ADC input of the microprocessor and provide some kind
of temperature compensation circuitry. Even then it will need to be sampled and averaged to approach "zero".
 
Last edited:

hippy

Ex-Staff (retired)
Using a 20M2 on an AXE091 development board with a bench supply I'm seeing a little jitter from noise with 10-bit ADC of +/-1 and an occasional +2 which fits with Goeytex's results ( same using AXE027 and AXE026 RS232 download cables ).

With 8-bit ADC I'm getting a spot-on reading, +/-0, but it can depend on how lucky you are with pot positioning, +0/-1 or +1/-0 would be expected if you hit an unlucky 'on the edge' position.

Getting +/-4 does seem to be quite noisy and especially if reading 8-bit ADC and there shouldn't be much need for large smoothing caps with a battery supply. First try a shorter length of cable to the pot and if that isn't the issue then what happens if you replace the pot with fixed resistors ? Is there anything else connected to the board; servos, motors, RF receivers or transmitters ?

Code:
#Picaxe 20M2
#Terminal 4800
Do
  ReadAdc10 C.1, w0
  If w0 = w1 Then
    SerTxd( #w0, CR, LF )
  Else
    If w0 >= w1 Then
      w2 = w0 - w1
      SerTxd( #w0, 9, "+", #w2, CR, LF )
    Else
      w2 = w1 - w0
      SerTxd( #w0, 9, "-", #w2, CR, LF )
    End If
  End If
  w1 = w0
  Pause 100
Loop
 

lewisg

Senior Member
I made a circuit to get variable heat from the foot warmer under my desk. Worked great on the dev board but when built and installed the relay would sometimes cycle several times around the on to off transition. I need to add some filtering but for now I did a little programming to calm things down:
Code:
'ReadPotDelay6.bas
'designed for variable heat from foot warmer
'by changing on time over a fixed period.

#picaxe08M
#terminal 4800

'I/O pins
symbol relay      = C.1
symbol LED        = C.2
symbol pot1       = C.4

'variables
symbol potval     = b0
symbol lastpotval = b1
symbol potdelta   = b2
symbol loopcount  = w2


pause 500
readadc pot1, potval
lastpotval = 0
sertxd("lastpotval", 9, "potval", 9, "potdelta", 9, "loop", 9, "relay", 13,10)

main:

    loopcount=0

    do

        readadc pot1,potval
        sertxd(#lastpotval, 9, #potval, 9)

        if potval > lastpotval then
            potdelta = potval - lastpotval
        else
            potdelta = lastpotval - potval
        endif

        if potdelta < 10 then                                     'replace 10 with the jitter value you want to suppress
            potval = lastpotval
        else
            lastpotval = potval
        end if

        if potval > loopcount then                                'turn on for pot value loops
            high relay
            high LED
            sertxd(#potdelta, 9, #loopcount, 9, "on", 13,10)
        else                                                      'turn off for rest of loops
            low relay
            low LED
            sertxd(#potdelta, 9, #loopcount, 9, "off", 13,10)
        end if

        pause 1000

        loopcount=loopcount + 1

    loop until loopcount = 255                                    'max pot value(255)

goto main
It also makes a nice CSV log file with header...
 

Dippy

Moderator
In addition to the wise words above there are a number of points with ADCing.

1. PIC Data Sheets give the error (uncertainty) that you are likely to see. dsPIC data gives some good info on decoupling.
If you have to start shoving in gallons of farads then you have something more fundamental to look into first.

2. For x-stat (e.g. heat/light) type Apps simply moving the threshold is often adequate and more simple than a pile of maths.
Set a threshold value and then when the ADC goes over the threshold you shift threshold down numerically (and the reverse in the other direction). If you have a variable/constant as your threshold and another as your 'shift' value then you are building a hysteresis and it stops that annoying dithering at the threshold. Adjusting the 'shift' value allows you to adjust your hysteresis/lag in the system.
It's analogous with how you would do it in hardware with an OA or VC circuit.

3. When your PICAXE V supply is your reference and also shared with a simple pot-div then , transients/noise excepted, it becomes (at least partially) self-compensating.

4. Where time and space permits, use ADC averaging and, where appropriate, consider some filtering too.
 
Top