adc stability for volt meter

#1
hi using volt divider circuit to measure 24 volt battery
requirements 10v to 30v, even with 1v accuracy be good. but its wandering so much? decimal read is 10 to 50..

5v zenier
2k7 resistor
----------------- v out
39k resistor

Code:
init:
#picaxe 20M2
pause 200
FVRSETUP FVR2048     'Set Fixed Voltage Reference = 2.048 Volts 
ADCCONFIG %011         'Set ADC to FVR
symbol batt= w0        
symbol level= 10
main:

serout C.0,N2400,(254,128) 
serout C.0,N2400,("volt test    ")


readadc10 C.3, batt ' 24v input
     batt= batt* level

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

darb1972

Senior Member
#2
Hello

Have you measured the voltage on the divider? Is it acting as expected? You might be best to use a divider with no zener in series, but instead use the zener on the PICaxe pin to protect against over-voltage should your resistor/s fail. If the resistors are calculated for worst case (voltage) then your divider voltage should never exceed 5V, or a lower predetermined level (but use the zener as suggested to protect the PICaxe).

I'll have a look at the code (but no pro here), although definitely check the divider first.
 

darb1972

Senior Member
#3
Not in front of my laptop but the code looks ok as I skim through it. Are you running the 20M2 on 5V? The 5V zener will only be useful for pin protection if the chip is running on a Vcc of 5V.

You should be able to get more than enough accuracy with 2048 steps over the range required.

As said, not a pro at code, nor am I near my laptop so I can't test further. Others might spot potential issues.
 

darb1972

Senior Member
#4
One thing I have spotted is that you will have to move your FVRSETUP command into your "main" routine as once you issue a "readadc" command, the FVRSETUP needs to be reissued (each time) as the readadc command turns off the FVR module to save on power consumption.
 

darb1972

Senior Member
#6
Hello.

To regulate from 4.5V to 3.3V you will need an LDO regulator. Good idea to regulate, otherwise things might change with the battery Vcc slowly falling with usage. Eventually though, the LDO regulator will stop working as it needs some voltage drop across the input to output to function correctly.

My understanding is that with your setup, you divide your Vcc (3.3V in your case) by the reference (2048 in your case) to give you your ADC voltage per step. I would suggest you remove the zener and setup a simple resistive voltage divider so that when your battery voltage is worst case (you said 30V?) then the voltage at the divider is 3V. Conversely, when the voltage is at its lowest (you said potentially 10V) then the voltage at the divider will be 1V.
 

hippy

Technical Support
Staff member
#7
Code:
readadc10 C.3, batt ' 24v input
batt = batt * level
That, where 'level' is 10, probably won't give you a number which represents the battery voltage.

The number read by READADC10, 'Nadc', can be determined from -

Nadc = ( Vin * 1023 ) / Vref

So to turn the Nadc read by READAC10 back to 'Vin' that would be -

Vin = ( Nadc * Vref ) / 1023

And then you need to multiply that by a value which represents your hardware input divider -

battery voltage = ( Nadc * Vref * Kdiv ) / 1023

Those Vref, Kdiv and 1023 values are all constants so you can calculate a 'level' value as -

level = ( Vref * Kdiv ) / 1023

But I am not sure that would 10.

Given you want to display a nominal 25V battery voltage to 1V resolution, equivalent to 5V at 200mV resolution, you should be able to do that by running the PICAXE from a regulator and just using READADC10 without using the FVR.

I would probably run the pICAXE from a 5V regulator and use a divider input as below. This will allow up to 28V without exceeding the 5V input limit -
Code:
          ___
Vbat >---|___|---.------> ADC
          47K   .|.
                | |
                |_| 10K
                 |
  0V >-----------^------> 0V
Remove the FVR stuff and then use ...
Code:
ReadAdc10 C.3, batt
batt = batt ** 18257
bintoascii batt ,b2,b3,b4,b5,b6
serout C.0,N2400,(254,192) 
serout C.0,N2400,(" ",b4,b5,".",b6," volt   ")
The 18257 may not be entirely correct for the regulator and supply voltage you have and the maths for determining it is fairly complicated to describe but I would try that and see how it goes.
 

AllyCat

Senior Member
#8
Hi,

5v zenier
2k7 resistor
----------------- v out
39k resistor
I'm not clear what circuit connections you're actually using (nor why a reply came from a "different" member) but in principle a simple two-resistor divider should work perfectly well. BUT ....

- Is there a decoupling capacitor (0.1 - 10 uF) across the PICaxe supply pins (1 - 20) ?

- Don't use a "5 volt" zener diode. They are not a simple "voltage reference" (because their voltage drop varies considerably with the current flow) and will probably give poor accuracy.

- The higher resistance should be "at the top", i.e. one end to the 24 volt battery. I would use a 33k + 2k2 divider (lower resistor between ADC input and Ground). That will give a 1/16 division ratio and reduce 30 volts to 1.875 volts, corresponding to a reading of 937 using READADC10 with a FVR of 2.048 volts.

- I'm not aware that the FVR setup is affected by a READADC command (but it is by the CALIBADC command). However, it does no harm to repeat the FVR settings within the main loop.

Since a 30 volt input should give an ADC10 reading of 937, you basically need to divide by about 31 (937 / 30) to give volts. For better resolution multiply the ADC reading by 10 (or up to 50) first and then divide/scale the result as required.
Or a more elegant (and accurate) method is to manually calculate 65536 * 30 / 937 (= 2098) and calibrate the ADC10 value using ** 2098 for volts. Or ** 20983 for tenths of a volt.

Cheers, Alan.
 
#9
Hi,



I'm not clear what circuit connections you're actually using (nor why a reply came from a "different" member) but in principle a simple two-resistor divider should work perfectly well. BUT ....

- Is there a decoupling capacitor (0.1 - 10 uF) across the PICaxe supply pins (1 - 20) ?

- Don't use a "5 volt" zener diode. They are not a simple "voltage reference" (because their voltage drop varies considerably with the current flow) and will probably give poor accuracy.

- The higher resistance should be "at the top", i.e. one end to the 24 volt battery. I would use a 33k + 2k2 divider (lower resistor between ADC input and Ground). That will give a 1/16 division ratio and reduce 30 volts to 1.875 volts, corresponding to a reading of 937 using READADC10 with a FVR of 2.048 volts.

- I'm not aware that the FVR setup is affected by a READADC command (but it is by the CALIBADC command). However, it does no harm to repeat the FVR settings within the main loop.

Since a 30 volt input should give an ADC10 reading of 937, you basically need to divide by about 31 (937 / 30) to give volts. For better resolution multiply the ADC reading by 10 (or up to 50) first and then divide/scale the result as required.
Or a more elegant (and accurate) method is to manually calculate 65536 * 30 / 937 (= 2098) and calibrate the ADC10 value using ** 2098 for volts. Or ** 20983 for tenths of a volt.

Cheers, Alan.
i have the 100nf cap on supply
I Have removed zenier, and have 33k and 2k2, reading 1.8v
W0 is only reading 40 decimal

Code:
init:
#picaxe 20M2
pause 200

symbol batt= w0        

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

serout C.0,N2400,(254,128) 
serout C.0,N2400,("volt test    ")


readadc10 C.3, batt ' 24v input
     batt= batt  

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

AllyCat

Senior Member
#10
Hi,

Even with a full Vcc Reference (i.e. not using the FVR as suggested by hippy) you should get a reading of many hundreds (when using READADC10) so the most likely cause is that the wrong pin is being measured, or it is not connected. The input impedance of CMOS pins is so high that "stray" electric fields can produce an apparent input voltage on an "unused / open" pin and could explain the wild variations.

Check your connections carefully and that the divider is connected to "Leg 7".

EDIT ; Looks like your code is not displaying b6, so the reading is actually 400 ? A SERTXD of #w0 to the terminal emulator is usually the easiest way to check things like this.

Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member
#11
I Have removed zenier, and have 33k and 2k2, reading 1.8v
W0 is only reading 40 decimal
That would suggest a battery voltage of 28.8V, which would read 1.8V on the ADC input.

That 1.8V should read as around 900 with the 2.048V Vref enabled.

That fits with the numbers AllyCat suggests in post #8. I would go for "** 20994" to get to one decimal place ...
Code:
    FVRSETUP FVR2048     'Set Fixed Voltage Reference = 2.048 Volts 
    ADCCONFIG %011         'Set ADC to FVR
    serout C.0,N2400,(254,128) 
    serout C.0,N2400,("volt test    ")
    readadc10 C.3, batt ' 24v input
    batt = batt ** 20994
    bintoascii batt ,b2,b3,b4,b5,b6
    serout C.0,N2400,(254,192) 
    serout C.0,N2400,(" ",b4,b5,".",b6," volt    ")
 

darb1972

Senior Member
#12
- I'm not aware that the FVR setup is affected by a READADC command (but it is by the CALIBADC command). However, it does no harm to repeat the FVR settings within the main loop.
Unless I am misunderstanding this statement (Page 69 Manual 2), it says;

"Note that the 1.024V reference may not be used as the Vref+ of the ADC (only 2.048 or 4.096 may be used for this purpose). See the adcconfig command for more details. To reduce power use the FVR module is also automatically disabled after a readadc command, so reissue the fvrsetup command again after the readadc if that feature is still required."
 

AllyCat

Senior Member
#13
Hi,

Don't believe everything you read in a (PICaxe) manual, or even a Microchip data sheet. ;)

Yes indeed, Microchip do "recommend" that FVR1024 is not used for the ADC reference voltage, but in many cases it works perfectly well. Certainly it should be used "with caution" (and only when needed) but, particularly for a novice, it's probably a far better way to double the ADC sensitivity/resolution than attempt to add an external Op-Amp, or similar. Another advantage is that the FVR1024 is more accurate (has a closer tolerance) than the FRV2048/4096 references (according to the Microchip data sheet).

I don't have suitable hardware to hand for testing at the moment, but I believe it's been discussed before that the ADC command may not switch off the FVR. I'm not saying that it never happens, but there have been many different versions of PICaxe and Compiler / Editor. Perhaps somebody will test a recent version and report their observations (not forgetting to specify their PICaxe and Editor types, etc.). ;)

Cheers, Alan.
 

Flenser

Senior Member
#14
From post #9
your code is this:
bintoascii batt ,b2,b3,b4,b5,b6

the bintoascii command syntax is this:
BINTOASCII wordvariable, tenthousands, thousands, hundreds, tens, units

Your serout is this:
serout C.0,N2400,(" ",b4,b5," volt ")

You appear to be sending the digits for hundreds and tens via serout but interpreting them as tens and units.
You report "W0 is only reading 40 decimal" so the value is likely 400, not 40.
 

darb1972

Senior Member
#15
Hi,

Don't believe everything you read in a (PICaxe) manual, or even a Microchip data sheet. ;)

Yes indeed, Microchip do "recommend" that FVR1024 is not used for the ADC reference voltage, but in many cases it works perfectly well. Certainly it should be used "with caution" (and only when needed) but, particularly for a novice, it's probably a far better way to double the ADC sensitivity/resolution than attempt to add an external Op-Amp, or similar. Another advantage is that the FVR1024 is more accurate (has a closer tolerance) than the FRV2048/4096 references (according to the Microchip data sheet).

I don't have suitable hardware to hand for testing at the moment, but I believe it's been discussed before that the ADC command may not switch off the FVR. I'm not saying that it never happens, but there have been many different versions of PICaxe and Compiler / Editor. Perhaps somebody will test a recent version and report their observations (not forgetting to specify their PICaxe and Editor types, etc.). ;)

Cheers, Alan.
Ok Alan, thanks. Don't really know who or what to trust anymore. I'm starting to feel a bit like Fox Mulder from the X-Files. Trust no one!!!
 

AllyCat

Senior Member
#16
Hi,

Perhaps the best starting point is "Don't believe anything you read on the Internet". ;)

Decide which sources you find are "usually reliable" but still use a critical eye. Generally the PICaxe Manuals are very good for their intended audience but sometimes they can be "misleading", perhaps due to an oversimplification. Also there have been many different PICaxe chips developed and they might not all behave in exactly the same way. Finally the manuals have probably been written mainly by a single person (they usually are ! ) and it's amazing how one can write something "incorrect" and then "proof read" it numerous times without noticing the error (been there, got the Tee Shirt).

As far as Microchip (and most other manufacturers) are concerned, their Data Sheets are trying to "protect their backs". It can be extremely embarrassing to have a product coming off a production line every few minutes (or even seconds!) with every one failing Final Test because of a specification error. So some of the parameters in the Data Sheets are incredibly pessimistic (for example the "Watchdog Timer period" which is used for the PICaxe NAP/SLEEP commands).

On the subject of the READADC/FVRSETUP interaction, I was fairly sure that I had written code snippets which use a "tight" READADC loop (to average the value). But in my search came across this thread. where the code looks remarkably similar to that used by the OP. ;)

But, back to the original topic: The OP has implied that the ADC is reading a 1.8 volt level as a value of 40 (of 1024) which is almost "impossible" (because the reference voltage would need to be almost 50 volts, and "release the magic smoke"). So we need to discover what "implied" detail is incorrect ; it might be related to hardware, software, understanding or (our) assumptions. We can't do it by "remote control" so can only offer a list of possiblities in the "most probable" (and/or easiest) sequence. My brief list is:

- The divider chain is not connected to the (correct) PICaxe pin (Hardware). = Easy to check with a multimeter probing between the resitors' junction and the PICaxe pin (NOT the socket or PCB). A "floating" input would also explain the large variations reported in #1.

- Software - Is the code listing EXACTLY (and all) that has been loaded into the PICaxe? Is the reported "w0" actually what is being written to the LCD?

- The PICaxe might be damaged = I put this last because it is very unusual. But sometimes OPs do later admit that they had previously connected an excessively High or Reversed voltage, or shorted some pins together, etc..


Finally, a "lost" final digit (i.e. w0 = 40x) doesn't fully explain the observations because the value should be 700+. However, if the ADC input is 1.8 volts AND the FVR is not enabled, then we can predict that the Supply Voltage (Vcc = ADC reference) should be about 1.8 * 1024 / 40x = 4.5 volts, which is very plausible. ;)

Cheers, Alan.
 
Last edited:

marks

Senior Member
#17
Hi late voyager,
as Allycat has hinted
it looks like serout command is reseting the adc channel

the voltage divider is the same ratio 16:1 as before
perhaps try
Code:
init:
#picaxe 20M2
#terminal 4800
pause 200
symbol batt= w0        
serout C.0,N2400,(254,1):pause 10
main:
serout C.0,N2400,(254,130)
serout C.0,N2400,("test    ")
FVRSETUP FVR2048    'Set Fixed Voltage Reference = 2.048 Volts
ADCCONFIG %011      'Set ADC to FVR
readadc10 c.3, batt ' 24v input
Sertxd (13,10,"ADCvalue ",#batt)
 batt= batt*32  ' Multiply by Vin (Fullscale 32v)(R1 150K)(R2 10K)(0.1uf across R2)
  Sertxd ("    Volts ",#batt)' 032 resolution
 
    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
 

hippy

Technical Support
Staff member
#18
One test for whether the correct pin is being read is to do a simple READADC10 without using FVR and report the result of that.. In fact one can read all ADC channels and determine which pin it likely is connected to -
Code:
#Picaxe 20M2
#Terminal 4800

Do
  For b0 = B.0 To B.6
    Gosub Check
  Next
  For b0 = C.1 To C.3
    Gosub Check
  Next
  SerTxd( CR, LF )
  Pause 1000
Loop

Check:
  ReadAdc10 b0, w2
  b1 = b0 / 8 + "B"
  b2 = b0 & 7
  SerTxd( b1, ".", #b2, " = ", #w2 )
  If w2 > 388 Then
    w3 = w2 - 388
  Else
    w3 = 388 - w2
  End If
  Select Case w3
    Case <  50 : SerTxd( TAB, "****" )
    Case < 100 : SerTxd( TAB, "**" )
    Case < 150 : SerTxd( TAB, "*" )
  End Select
  SerTxd( CR, LF )
  Return
The one with the most stars should be the pin which is reading the battery voltage.
 
#19
Hi late voyager,
as Allycat has hinted
it looks like serout command is reseting the adc channel

the voltage divider is the same ratio 16:1 as before
perhaps try
Code:
init:
#picaxe 20M2
#terminal 4800
pause 200
symbol batt= w0       
serout C.0,N2400,(254,1):pause 10
main:
serout C.0,N2400,(254,130)
serout C.0,N2400,("test    ")
FVRSETUP FVR2048    'Set Fixed Voltage Reference = 2.048 Volts
ADCCONFIG %011      'Set ADC to FVR
readadc10 c.3, batt ' 24v input
Sertxd (13,10,"ADCvalue ",#batt)
batt= batt*32  ' Multiply by Vin (Fullscale 32v)(R1 150K)(R2 10K)(0.1uf across R2)
  Sertxd ("    Volts ",#batt)' 032 resolution

    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
tried this...
1546019456714.png
 
#20
One test for whether the correct pin is being read is to do a simple READADC10 without using FVR and report the result of that.. In fact one can read all ADC channels and determine which pin it likely is connected to -
Code:
#Picaxe 20M2
#Terminal 4800

Do
  For b0 = B.0 To B.6
    Gosub Check
  Next
  For b0 = C.1 To C.3
    Gosub Check
  Next
  SerTxd( CR, LF )
  Pause 1000
Loop

Check:
  ReadAdc10 b0, w2
  b1 = b0 / 8 + "B"
  b2 = b0 & 7
  SerTxd( b1, ".", #b2, " = ", #w2 )
  If w2 > 388 Then
    w3 = w2 - 388
  Else
    w3 = 388 - w2
  End If
  Select Case w3
    Case <  50 : SerTxd( TAB, "****" )
    Case < 100 : SerTxd( TAB, "**" )
    Case < 150 : SerTxd( TAB, "*" )
  End Select
  SerTxd( CR, LF )
  Return
The one with the most stars should be the pin which is reading the battery voltage.
no stars for me.... ?

1546019786826.png
 
#24
strange. i unplug the 10 k and still stable?
Ive used same figures in main prog and had to use multiplier 640... eeek.. but it work... and now stable to less than half volt so a bit confused...

not the whole code but the bits being playing with..
using 150k and 10k

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


    readadc C.3, batt' 24v input
        batt = batt *640

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

AllyCat

Senior Member
#25
Hi,

The 0, 1 and 2 values in #19 are virtually zero (noise?) and the "Volts" just multiplied by 32. But note exactly which variables Marks used in his code:

Code:
 bintoascii batt ,b2,b3,b4,b5,b6
    ....
    serout C.0,N2400,(" ",b2,b3,".",b4," volts")
In post #23 it looks as if you have "forgotten" the 10 in the READADC10 command [update, yes it looks as if I guessed correctly]. As I said earlier we really need to know exactly what program code you're using, we can't always guess. ;)

I would have expected even a 10k resistor to Vcc to give an ADC{10} value higher than 952 {or 244}. But it appears to confirm that, for some reason, the FVR is NOT being used (because the FVR should certainly give values of 1023 or 255).

On your latest post, * 640 is much too large (even using READADC without the 10 AND a Vcc reference), so something is still obviously "wrong".

Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member
#26
1k and straight in to c3..
Seeing C.3=952 shows the PICAXE is able to see that input so suggests the test code is working as expected.

So the question must be why it isn't also seeing the 1.8V you say is there from your divider fed by the battery, which should be showing a reading of about 390.

Did you measure the 1.8V on the actual PICAXE C.3 pin as well as the divider output ? If it is on the PICAXE pin then the PICAXE should be reporting its presence.
 

AllyCat

Senior Member
#27
Hi,
Seeing C.3=952 shows the PICAXE is able to see that input so suggests the test code is working as expected.
Except that the most recent code from the OP still shows the ADCCONFIG command setting the ADC reference to the 2 volt FVR.
---
Also, an amusing addendum to my comment in para. 2 of post #16 about "mistakes". Later in that post I linked to a code snippet by a very experienced and respected member, which has been viewed over 4000 times in the past 5 years. In that post he helpfully shows code and a voltage divider for 24 volts dc, i.e. almost exactly as required for this thread.

However, his calculation is wrong, but nobody has commented in those 5 years! He suggested a potential divider of 12k + 1.5k , but 24 volts would deliver around 2.67 volts to the ADC, which clearly exceeds the maximum range of 2.048 volts set by the FVR. :oops:
---
To summarise; A divider to detect a maximum voltage of 30 volts, when using FVR2048 as reference, needs a minimum division ratio of 14 : 1. Make that 15 : 1 (e.g. 15k : 1k or 33k : 2k2 , etc.) for convenience and to allow for some adverse tolerances. Then, the ADC voltage calibration multiplier needs to be 32 / 1024 (for integer volts) or 320 / 1024 (for tenths of a volt resolution). The latter corresponds to ** 20480 , which should need adjusting by no more than +/- 10% , and in most cases < +/- 5%. [ E & OE :) ]

Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member
#28
Except that the most recent code from the OP still shows the ADCCONFIG command setting the ADC reference to the 2 volt FVR.
I simply ignored that and its results; 255*640 overflows, and the least significant two digits aren't being sent to the LCD.

We're going off in too many tangents. We need to simplify and get back to basics -
Code:
#Picaxe 20M2
#Terminal 4800
Do
  ReadAdc10 C.3, w0
  SerTxd( #w0, CR, LF )
  Pause 1000
Loop
What does that show, and with what battery voltage and what divider circuit ?
 
#30
I simply ignored that and its results; 255*640 overflows, and the least significant two digits aren't being sent to the LCD.

We're going off in too many tangents. We need to simplify and get back to basics -
Code:
#Picaxe 20M2
#Terminal 4800
Do
  ReadAdc10 C.3, w0
  SerTxd( #w0, CR, LF )
  Pause 1000
Loop
What does that show, and with what battery voltage and what divider circuit ?

I have 30v in and 1.05 volt after 150k and 10k.. and 1.05 at chip... could it be cheap resistors...
for info,
have removed fvr and adconfig command
have multiplier at 64 and get 12v displayed
if i put back fvr and adconfig i get 30v :)

so it works, but im clueless to my first post, i basically have same code as first post and now not wandering.. all i have really done is changed resistor value to 150k - 10k (from 39k - 2k7) and display b2/b3 now...??

Code:
main:
debug
symbol batt = 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*64 

    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
#32
I have 30v in and 1.05 volt after 150k and 10k.. and 1.05 at chip... could it be cheap resistors...
30V into 150K/10K should give 1.88V

30V into 150K/5K would give 0.97V which is pretty close to what you are measuring, just 80mV difference, and would be the case if you have your 150K/10K external to a board which has a 10K pull-down fitted.

What PICAXE board or hardware are you using ?

have removed fvr and adconfig command
have multiplier at 64 and get 12v displayed
if i put back fvr and adconfig i get 30v :)
It would be more helpful if you could just say what results the code in post #28 gives.

Using the code in post #28, reading 1.05V on the pin, with no FVR and a 5V supply, should show a READADC10 reading of about 214. Do you get that ? If not what do you get ?

---

Similarly, using the code you seem to have in post #30, reading 1.05V on the pin with no FVR and a 5V supply, should also give a READADC reading of 214.

( 1.05 / 5 ) * 1023 = 214.83 = 214

Multiplying 214 by 64 would give 13696. Putting that up on the display as you do should show "13.6 volts". That doesn't seem to be "12V" to me.

---

Reading 1.05V on the pin, with a 2.048V FVR, should give a READADC10 reading of around 524.

( 1.05 / 2.048 ) * 1023 = 524.48 = 524

Multiplying 524 by 64 would give 33536. Putting that up on the display should show "33.5 volts". That again doesn't seem to be "30V" to me.

---

Obviously 64 is roughly in the right ball park, though I calculate the multiplier should be 57.25 when using the 2.048V FVR.

The numbers actually read, calculated and displayed, will always be somewhat different to what the calculations suggest.

But it's very difficult to tell where the discrepancies between what you say you are seeing and what you should be seeing are coming from. That's why knowing what the full raw value being read with no FVR, no multiplying, is so important.
 
Last edited:

AllyCat

Senior Member
#33
Hi,

. could it be cheap resistors...
.... all i have really done is changed resistor value to 150k - 10k... and display b2/b3 now..
Unlikely to be the resistors, much more probably you improved a bad (dry) solder joint or cleaned up a "dirty" connection. A 150k + 10k divider is at the high end recommended for a PICaxe ADC input and perhaps is too high for the multimeter you're using. Much better to use 15k + 1k or a similar ratio.

30v / 12v when with / without the FVR is exactly as expected (if a 4.5 volt battery) but how much is "wishful thinking". As hippy says, much better to show the raw ADC numbers. The scaling / truncation of the values is potentially hiding valuable information.

Maybe we're getting to the realm of "Measurement Technique" now. Presumably it's a digital multimeter; if it reads 1.05 volts on (say) the 20 volt range, what does it read on the 2 volt and 200 volt ranges? By how much does the multimeter reading change if you add a 1 k resistor in series with the probe? When you touch the probe onto the PICaxe input,, by how much does the value shown by the PICaxe (SERTXD) change? It should change, maybe by only a little or maybe a lot.

You should really be satisfied only when you can estimate the "Ohms per volt" of the multimeter and the percentage errors in the voltage divider ratio and the FVR voltage. Then you/we can incorporate those figures into the calibration / calculation for the final program.

Cheers, Alan.
 

Flenser

Senior Member
#34
late_voyager,
In Post #30 you said:
have multiplier at 64 and get 12v displayed
if i put back fvr and adconfig i get 30v
Where do you get these voltages from?

Your code in post #30 does not calulate volts so your serout command:
Code:
serout C.0,N2400,(" ",b2,b3,".",b4," volts")
does _not_ display volts.

The readadc10 command does not return volts. It returns a binary integer with a value between 0 and 1023.

A voltage has to be calculated from this raw ADC number and that calculation uses the FVR you chose plus the values of your voltage divider as is discussed in some of the other posts.

Your code in post #30 does not do this calculation so what you display is not a voltage. It is, a part only, of the raw ADC value which is between 0 and 1023. I say it is a a part only because you report only two digits ("12v" and "30v") where we need at least 4 digits displayed to see this raw value

Your bintoascii ccomand coverts this raw adc value into a set of 5 digits.
Code:
bintoascii batt ,b2,b3,b4,b5,b6
                  ^  ^  ^  ^  ^
                  |  |  |  |  +-- 0-9 digit for Units
                  |  |  |  +----- 0-9 digit for Tens
                  |  |  +-------- 0-9 digit for Hundreds
                  |  +----------- 0-9 digit for Thousands
                  +-------------- 0-9 digit for Ten Thousands
If you are reporting the raw ADC value in batt then you could change your serout command to report at least 4 digits, something like this:
Code:
serout C.0,N2400,(" ",b3,b4,b5,b6,"readadc10 value in variable batt")
You don't need to use bintoascii at all so you could also use the simpler:
Code:
serout C.0,N2400,(" ",#batt,"readadc10 value in variable batt")
This will allow everyone else to confirm that you are getting a value back from the readadc10 commmand that is correct for your 24v battery, the voltage divider values you use and the FVR value in your code.

As READADC10 returns a value between 0 and 1023 the digit for ten thousands in b2 is always going to be zero.
 
Last edited:
#35
as per post 28...which i seemed to miss?
this code with 1k and 15k divider,
5v picaxe input via reg
10volt input
0.57v at picaxe pin using a fluke meter.

AND ERM sorry OOOPS.... the variable resistor that i forgot i put in for fine adjust!!!

1546164469680.png
 

Flenser

Senior Member
#36
late_voyager,
These values are reasonably consistent, which is good. The variation is likely to be noise but we can worry about that after we can calculate a value of 0.57v from these raw ADC values.

Measuring the voltage on the C.3 pin was a good idea. It allows us to investigate how to calculate a voltage of 0.57v from the raw ADC value without having to worry about the voltage divider at all.

FYI. if these are 5% resistors and the 1K happened to be 950R and the 15K happened to be 15750R then I calculate the voltage would be 0.57v!

Howver, I cannot calculate a voltage around 0.57v using the raw ADC values in the range 114-120 and any of the FVR settings . I'm going to have to give this some more thought.

Would you post the code that you used to get these raw ADC values 114-120 so that we have the code to match the results.
 
#37
late_voyager,
These values are reasonably consistent, which is good. The variation is likely to be noise but we can worry about that after we can calculate a value of 0.57v from these raw ADC values.

Measuring the voltage on the C.3 pin was a good idea. It allows us to investigate how to calculate a voltage of 0.57v from the raw ADC value without having to worry about the voltage divider at all.

FYI. if these are 5% resistors and the 1K happened to be 950R and the 15K happened to be 15750R then I calculate the voltage would be 0.57v!

Howver, I cannot calculate a voltage around 0.57v using the raw ADC values in the range 114-120 and any of the FVR settings . I'm going to have to give this some more thought.

Would you post the code that you used to get these raw ADC values 114-120 so that we have the code to match the results.
as per post 28
Code:
main:

#Picaxe 20M2
#Terminal 4800
Do
  ReadAdc10 C.3, w0
  SerTxd( #w0, CR, LF )
  Pause 1000
Loop
 

marks

Senior Member
#38
Hi late voyager,
you have just proven what hippy wrote at post #32
your board must also be fitted witha 10k pulldown resistor
a 15k and 1k equates to a 16 to 1 ratio ie @10v should equal 10/16 =0.625v
if a 10k resistor is in parallel with 1K this would become 909 ohms
so 15k and 909ohms equates to a ratio of 17.5 ie 10/17.5=0.57v
 

Flenser

Senior Member
#39
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.
 
Top