adc stability for volt meter

late_voyager

New Member
late_voyager,

I thought of my next test.

Disconnect the 10v from the voltage divider.
Measure the voltage at the pin. It should be 0v.
Run the program to find out what the raw ADC value reported by SerTxd( #w0, CR, LF ) is. It should be 0.

yes value is zero...
1546193415568.png
 

Flenser

Senior Member
late_voyager,

OK, the ADC is reading the voltage on C.3.

I realized that the raw ADC value you get when 10v is connected to the voltage divider and the pin voltage is 0.57v is consistent with the ADC Vref+ being connected to 5v.

pin voltage = raw ADC value / max ADC value * ADC Vref+ voltage
117 / 1023 * 5v = 0.57v

I can't explain why Vref+ is 5v, it is just that the calculation works.

We can confirm this with another test.
Connect 5v to the voltage divider.
Measure the voltage at the pin. It should be around 0.285v.
Run the program to find out what the raw ADC value reported by SerTxd( #w0, CR, LF ) is. It should be around 58.
 

Flenser

Senior Member
I can explain why Vref+ is 5v. Your latest version of the code from post #37 needs to add back the adcconfig and fvrsetup commands.

The fvrsetup command needs to be inside the do loop. The adcconfig can be done once outside the do loop.
Code:
#Picaxe 20M2
#Terminal 4800
ADCCONFIG %011         'Set ADC to FVR
Do
  FVRSETUP FVR2048      'Set Fixed Voltage Reference = 2.048 Volts
  ReadAdc10 C.3, w0
  SerTxd( #w0, CR, LF )
  Pause 1000
Loop
And then retest with 10v on the voltage divider. With 0.57v at the pin and using the 2.048 FVR for the ADC Vref+ we expect to see a raw ADC value of around 284.
 

AllyCat

Senior Member
Hi,

It seems quite clear that the OP has an "unintended" resistance of 10k between the ADC input and ground, as predicted by hippy way back in [edit] #32. Now it's only necessary to determine whether it is (1) a "pre-installed" pull-down resistor, (2) the meter loading, or (3) something else (e.g. the "fine adjust" mentioned in #35), and whether it will be present in the "final" hardware.

Then he can get back to activating the FVR again and calibrating the program code properly. For example, using the "Reference Code Snippet" and calibration values shown in #27.

The cause of the original "stability" problem is still unexplained, but I strongly suspect a hardware issue (bad connection) which became masked by "unwise" software editing.. ;)

Cheers, Alan.
 
Last edited:

Gramps

Senior Member
When y'all get this voltmeter working, please post the code and schematic.
I'd like to build one. Had in mind a power line monitor. Range between 100 and 130 VAC.
Even have a optocoupler link and some 7 segment LED's floating around here someplace.
Very cool project!
 
Last edited:

tmfkam

Senior Member
When y'all get this voltmeter working, please post the code and schematic.
I'd like to build one. Had in mind a power line monitor. Range between 100 and 130 VAC.
Even have a optocoupler link and some 7 segment LED's floating around here someplace.
Very cool project!
Try this: Grid Frequency Monitor

Monitors Mains frequency and voltage. 120V compatible too.
 

Gramps

Senior Member
For some reason the links to your PDFs are not opening don't know if it's us or if others are having trouble with this Gramps
 

late_voyager

New Member
Happy new year...!
right..

1k and 15k resistor,
10volt input
reading 0.58 into picaxe
W0 reading 10150


24v input
1.37 volt at picaxe input
W0 24000 BUT wanders about .... getting 23.6 to 24.2 v (23600 to 24200)
tried battery instead of power supply same...

Code:
#picaxe 20m2
main:
debug
symbol batt = w0        ' symbol for w0.. b0-6
FVRSETUP FVR2048      'Set Fixed Voltage Reference = 2.048 Volts 
ADCCONFIG %011         'Set ADC to FVR
        readadc10 C.3, batt' 24v input
        batt= batt*35

    bintoascii batt ,b2,b3,b4,b5,b6
    serout C.0,N2400,(254,192)
    serout C.0,N2400,(" ",b2,b3,".",b4," volts") 
    pause 10
goto main
 

hippy

Technical Support
Staff member
1k and 15k resistor,
10volt input
reading 0.58 into picaxe
W0 reading 10150
That would seem to be as expected with a 10K on-board pull-down resistor after multiplying the reading by 35.

24v input
1.37 volt at picaxe input
W0 24000
That would also seem be as expected after multiplying by 35.

BUT wanders about .... getting 23.6 to 24.2 v (23600 to 24200)
If the result is changing between 23600 and 24200 the raw READADC10 reading must be changing between 674 to 691, that's equivalent to 682.5+/-8.5, an input voltage of 1.366V+/-0.017V.

The variance does seem to be higher than would normally be expected, but your earlier tests were also showing some large jumps in ADC reading values.

I would suspect it's a hardware or circuit issue, or external noise. You have not described your actual hardware nor described what board you are using. It could even be pick-up which is coming from the clock circuitry of the OLED or LCD display you are using.
 

AllyCat

Senior Member
Hi,

[ Much the same as hippy said, but he types faster than I do. ;) ]

Where are your "W0" values coming from, since your code doesn't show a SERTXD, nor the last two digits of "batt"?

The maximum ADC output is 1023, so presumably your "W0" values are multiplied by 35? 10150 is a multiple of 35, but 24000 isn't ! :unsure:

10 volts into the divider should give 0.625 volts: Your 0.58 is about 7% low, which is "possible" but not as good as expected (so deserves more investigation). 10150 / 35 = 290 which typically corresponds to 0.58 volt, so the ADC and FVR appear to be working correctly..

Similarly the 24 volts input should be divided to 1.5 volts, so your 1.37 is about 8% low and the nearest integer to 24000 / 35 = 686 = 1.372 volts.. But, if the ADC output is varying by about 2.5%, what about the input reading on the multimeter?

Cheers, Alan.
 

late_voyager

New Member
the W0 reading is from debug.
Yes was times 35.
10k pulldown removed

24v input, volt meter 1.369 / 1.370 at picaxe
now 35 multiplier removed, varies from aprox 670 to 690 on debug W0

circuit
24v was through reverse protection, p-mosfet 100k and 10v zenier
removed this out of equation same wandering

picaxe 20m2 and oled on custom board,
however this has now changed dramatically but Im using as test board. with only a few parts fitted

1546361446532.png
with the othe stuff removed... 100k is actually 15k
1546362627990.png
 

premelec

Senior Member
Put a capacitor - say 1uF or so - between ADC input pin and V- ; NOISE of one sort or another is very common in this wonderful field of electronic measuring... ;-0
 

late_voyager

New Member
Put a capacitor - say 1uF or so - between ADC input pin and V- ; NOISE of one sort or another is very common in this wonderful field of electronic measuring... ;-0
tried 1uf.. same... 10uf, 100uf....fk it 330uf... better 29.8v to 30.1 volt on display with 30v in
1.714 on volt meter ... my new toy scope.. looks nice.. dunno what to do with it lol... shows 20mv wiggly bit :p

added pause 200......
slow things down.. should i have done this at post No1... :rolleyes:
 
Last edited:

premelec

Senior Member
I should have mentioned the digital method...... take the average of 10-20 or whatever readings.... report that and any deviatiation data if you want to get fancy... whatever works... with old d'arsonval meters we could watch the needle jitter a bit and with digital numbers we expect them to all be the same... though that +/- 1 digit is often in play. I have seen many noisey batteries - perhaps minor gurgles in their interior chemistry... 29.8 to 30.1 is about 1%... not bad for your application... hope you've got it going ok...
 

hippy

Technical Support
Staff member
Do you have a circuit diagram ? To me your battery input circuit looks suspiciously like -
Code:
                      15K     Pot
         Fuse         ___     ___
Vbat+ >--O==O----.---|___|---|___|-
                .|.           /|\
             1K |_|            `---------> ADC
                 |
Vbat- >----------^-----------------------> 0V
And that's not a voltage divider.

Added: I would take a step away from what you are doing. Take your PICAXE and build the battery monitoring circuit on a breadboard and see what results that gives. That way you should be able to tell if it is a problem with your circuit, board, the way it's laid out, or something else.
 
Last edited:

late_voyager

New Member
Yes drawing was wrong for the volt divider, i am basically doing on bread board, just happens to be on pcb with nothing else..
circuit:
1546375432122.png
 

hippy

Technical Support
Staff member
That diode between Vbat- and 0V I would guess allows the entire battery supply to float, so a lot of noise would not be that unexpected.

And on top of that you have one resistor divider between Vbat+ and Vbat- and another between its output and the PICAXE 0V courtesy of the pot and the internal ADC input pin resistance.
Code:
Vbat+ >-------.
             .|.
             |_|
              |               
              }-----.     
             .|.   .|.
             |_|   |_|
              }     |     |
Vbat- >---.---'     }---->|---.---> ADC
         _|_       _|_    |  .|.
        _\ /_      ===    |  |_|
          |         |     |   |
         -^---------^---->|---^---> 0V
 

darb1972

Senior Member
If the only way the PICaxe is grounded relies on the diode from "NEG" to the actual battery negative terminal, then the diode is the wrong polarity. Turning the doide around will then make your 5V rail rise to 5.6V. If the PICaxe (via the 5V regulator) has a seperate ground then it is best to remove the diode and make both grounds common (join them together). Separate grounds and/or poor grounding might cause weird issues to occur.
 

late_voyager

New Member
That diode between Vbat- and 0V I would guess allows the entire battery supply to float, so a lot of noise would not be that unexpected.

And on top of that you have one resistor divider between Vbat+ and Vbat- and another between its output and the PICAXE 0V courtesy of the pot and the internal ADC input pin resistance.
Code:
Vbat+ >-------.
             .|.
             |_|
              |              
              }-----.    
             .|.   .|.
             |_|   |_|
              }     |     |
Vbat- >---.---'     }---->|---.---> ADC
         _|_       _|_    |  .|.
        _\ /_      ===    |  |_|
          |         |     |   |
         -^---------^---->|---^---> 0V
the diode at the 24v input was for reverse polarity but left behind.. now removed.
i see about the pot..again originally to give adjustment.. but if program etc is ok shouldnt need...

1546448745746.png
 

AllyCat

Senior Member
Hi,

The schematic diagram still doesn't show the lower end of the 1k resistor (battery Neg) connected (directly) to the PICaxe Earth rail. This is absolutely essential. Ideally, the 1k should be wired directly across Leg 7 to Leg 20 at the PICaxe.

The reason is that the PICaxe ADC measures the ADC input (pin 7) relative to its Earth rail (Pin 20), so the Earth rail needs to be at least as "clean" as the input voltage (C1 helps to keep the two voltages "in step" at high frequencies, but not for any "wandering" at low frequency). Actually, the Earth needs to be much cleaner than the measured voltage: A 2 mV "ripple" on the earth (relative to the ADC input) will produce an error of one (LS Bit) in the output value. But it needs a ripple of 30 mV at the top of the 15k resistor (Battery +) to produce a similar 2 mV error at the input of the ADC.

Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member
I would just use this ...
Code:
           ___
Vbat+ >---|___|-----.-----.--------> C.3
           68K     .|.   _|_
                10K|_|   _ _ 100nF
                    |     |
VBat- >-------------^-----^--------- 0V
And then run this ...
Code:
#Picaxe 20M2
#Terminal 4800
Do
  ReadAdc10 C.3, w0
  SerTxd( #w0, CR, LF )
  Pause 1000
Loop
Check what sort of variance or noise you are getting.
 

darb1972

Senior Member
So did removing the diode and making both negatives/earths common (joining them together) work (as I suggested in post #59)??? I would be very surprised if this didn't provide the solution.
 

late_voyager

New Member
sorry have to work sometimes :(
i have this... W0 wanders from 9500 to 1150 ish, 9.4v to 10.1v on display
if i add a bit more pause helps take away from "digital" and for what I need is ok..

Code:
#picaxe 20m2
main:
debug
symbol batt = w0        ' symbol for w0.. b0-6
FVRSETUP FVR2048      'Set Fixed Voltage Reference = 2.048 Volts 
ADCCONFIG %011         'Set ADC to FVR
        readadc10 C.3, batt' 24v input
        batt= batt*35

    bintoascii batt ,b2,b3,b4,b5,b6
    serout C.0,N2400,(254,192)
    serout C.0,N2400,(" ",b2,b3,".",b4," volts") 
    pause 100
goto main
1546537288161.png

however thought try the average.. but i cant seem to get the code right..

Code:
#picaxe 20m2
main:
debug
symbol batta = w0        ' symbol for w0.. b0-6
symbol battb = w4       
symbol battc = w8 

FVRSETUP FVR2048      'Set Fixed Voltage Reference = 2.048 Volts 
ADCCONFIG %011         'Set ADC to FVR

      readadc10 C.3, batta' 24v input
         readadc10 C.3, battb' 24v input
        
    let w0+w4 = w8   ' error............................................................
    battc = battc*35
    
    bintoascii battc ,b2,b3,b4,b5,b6
    serout C.0,N2400,(254,192)
    serout C.0,N2400,(" ",b2,b3,".",b4," volts") 
    pause 200
goto main
 

hippy

Technical Support
Staff member
let w0+w4 = w8 ' error
battc = battc*35
Try -
Code:
let battc = batta + battb / 2
battc = battc * 35
But you would probably be better off with the following ...
Code:
battc = 0
For b0 = 1 To 35
  ReadAdc C.3, battb 
  battc = battc + battb
Next
Edited: Added previously missing 'battc=0'.
 
Last edited:

Flenser

Senior Member
late_voyager,

You said in post #65.
W0 wanders from 9500 to 1150 ish
That represents a 20% variation which seems way to high to be just as a result of noise. What are you using to provide the 10V level?
 

late_voyager

New Member
Try -
Code:
let battc = batta + battb / 2
battc = battc * 35
But you would probably be better off with the following ...
Code:
For b0 = 1 To 35
  ReadAdc C.3, battb
  battc = battc + battb
Next
tried this, same wander
Code:
let battc = batta + battb / 2
battc = battc * 35
didnt quite get this, understtod what trying to do but kept counting up.
Code:
For b0 = 1 To 35
  ReadAdc C.3, battb
  battc = battc + battb
Next
[/QUOTE]
 

late_voyager

New Member
late_voyager,

You said in post #65.


That represents a 20% variation which seems way to high to be just as a result of noise. What are you using to provide the 10V level?
using power supply, but also tried batteries..
now used my 8.4v batteries, currently 7.6v with fluke. that supply picaxe volt reg.
now 7315 to 7665 on debug
 
Last edited:

AllyCat

Senior Member
Hi,
didnt quite get this, understtod what trying to do but kept counting up.
Try a battc = 0 before the For loop. ;)

But IMHO it's not the ultimate solution and I still suspect a hardware (layout ?) problem. There's a very old computing motto: "Garbage in, Garbage out".

Cheers, Alan.
 

hippy

Technical Support
Staff member
Try a battc = 0 before the For loop
Yes; apologies for forgetting to include that in my suggestion.
But IMHO it's not the ultimate solution and I still suspect a hardware (layout ?) problem. There's a very old computing motto: "Garbage in, Garbage out".
That is my feeling as well. How well any smoothing or averaging solution works will depend on the nature of the noise and particularly its periodicity.

For example, just a few samples averaged over a short time won't help much if all samples are taken during a rise or fall in reading. One needs to sample across rising and falling noise to find what the average value actually is.

One may also need a long term average as well as an instantaneous average.

The problem is we don't know if the noise and variance in reading is inherent in the system or a result of what you have created in hardware or by design.

Because you are using a low ADC voltage reference and then a large multiplier to determine the battery voltage, just small amounts of noise will be magnified to a much larger battery voltage change.

With a 2.048V reference and a 35 multiplier, a bit change in ADC reading is caused by just 2mV of noise and that is then considered as a 70mV change in battery voltage, even if it is unchanging. You appear to be seeing a +/-175mV change in reported battery voltage; that would be a result of just +/- 5mV of noise on the input.

That +/-5mV is higher than might be expected and may be down to the tracking. Without trying a breadboarded basic circuit, with shortest wiring, it is not possible to tell what noise level would be expected or could be achieved.

Assuming it is how it is, and that's the hardware you are going to use, you could improve things by adjusting your voltage divider, using a 4.096V voltage reference and a smaller multiplier. With that, the +/-5mV noise would only appear as a +/-87mV change in battery voltage which may be acceptable, and that could be smoothed out further with averaging.
 

hippy

Technical Support
Staff member
great w0 now 10290 to 10350.....10.2/10.3 volts....:)
And what is the actual battery voltage measured with your meter ?

10.29 to 10.35 is a much better result, just an apparent +/-30mV variance. If it happened to have been 10.29 to 10.34 software rounding to one decimal place would have delivered 10.3 in both cases. Adding some averaging for one reading to the next would probably smooth that out nicely.
 

late_voyager

New Member
And what is the actual battery voltage measured with your meter ?

10.29 to 10.35 is a much better result, just an apparent +/-30mV variance. If it happened to have been 10.29 to 10.34 software rounding to one decimal place would have delivered 10.3 in both cases. Adding some averaging for one reading to the next would probably smooth that out nicely.
23.95 on meter, 23.9 on picaxe display
29.96 on meter 30.0 on picaxe
10.00 on meter 9.9 on picaxe

good enough for me... hmm you guys have more volts going in than me so all is a bit brighter!

the project so far and not finished... brain ache..

1546635699251.png
 

mikeyBoo

Senior Member
hi late_voyager,
I didn't want to confuse the issue because it looks like you already had a circuit-board layout, but the next time you do analog inputs to the Picaxe the following info may be helpful.
Take a look at the op-amp section of the attached file Kyk_tmi2_sch.pdf. This op-amp config makes it easy to design an analog input with pretty much any positive range you need. The comments on the drawing explain how to select scaling resistor RS1 & the 25-turn pot RG1 will allow precise adjustment.
The other attachment Picaxe-AI.pdf goes into detail about how it's done. Note that you can filter the input to C.7 with C1A but I’ve never needed it for measuring battery voltage.
If you use an input range of 0…+25.5v & adjust RG1 for an input of +2.048v to C.7 at full scale, the full scale bit value = 255 (meaning each bit = .1v, for 10 bits just divide the bit value by 4, this makes it very simple in software).
RS1 will need to be 245k to 270k to allow good adjustment resolution on RG1. All else as-is.
Hopes this helps. Any questions, let me know.
 

Attachments

darb1972

Senior Member
Hi mikeyBoo

I really like this approach!!!

Accurate. Scaleable. Nice setup and circuit.

Thanks for sharing!
 
Top