Voltage dividers and readadc10

Dawnra

New Member
Hi everyone :D I enjoy reading the messages on the forum. This is my first post however.
I have some solar panels wired to a 24v system and wish to use an 18x to log the voltage produced by the panels (in sun panel voltage can be up to 35v) and also the voltage at my lead acid battery bank. I have the 18x connected and working with rev-ed serial LCD kit and a voltage divider (as per www.thebackshed.com datalogger. Voltage to ADC pin on the 18x is taken from the junction of a 39k and 10k (to gnd) divider. I have 4v7 zener for protection against high voltage and a smoothing capacitor.

I have seen the threads re calculating voltage from the ADC value if your input voltage is under 5v. However if I input 25.5v the voltage at junction of 39k and 10k reads at 3.44 v I get an ADC reading of 700 which calculates correctly (allowing for accuracy of multimeter etc). I have noticed if I use a variable (regulated) power supply and crank up the voltage there does not seem to be a linear relationship between my input voltage of between 20v to 36v and the read ADC value. Can someone suggest a method that I could use to display a reasonably accurate voltage in that range on the LCD screen, whether by changing the resistor divider values or using code.

Many thanks

Mike
 

BeanieBots

Moderator
Welcome to the forum.

The first point to note is your zener.
At only 4v7 it is going to significantly limit your input range.
Secondly, zener diodes are magic devices which only start conducting at the specified voltage, they start much ealier (and also have a leakage current) which means using them as a "voltage clamp" in an analogue measuring system will have a non-linear impact on accuracy.

I stringly suggest AGAINST the use of zener diode clamping if analogue accuracy is of any importance.

Secondly, the PICAXE uses uses its power rail as the ADC reference.
This combined with yor zener clamp explains why you get odd results.

If you want to measure a voltage accurately, you must provide a good clean stable supply voltage and use a purely resistive potential divider.

To calculate what the ADC value will be for a given input voltage will then be very simple.

ADC_value = 256*Vin/Vcc
Where Vin = Unknown voltage on ADC pin and Vcc = PICAXE power rail voltage.
For ReadADC10, replace 256 with 1024.

You might want to reconsider your potential divider values.
An input voltage of 25.5v into 39k/10k divider will produce 5.2v at the ADC pin.
This will not damage the PICAXE because the 39k will limit the current to a safe value but you will get a full scale reading for anything over 24.5v assuming you have a 5.00v supply.

EDIT:
"However if I input 25.5v the voltage at junction of 39k and 10k reads at 3.44 v I get an ADC reading of 700"

This is way off. 25.5v will give 5.2v (without the zener).
The 4.7v zener will be clamping it down to around 3.44v which is a nice example of why they are not suitable for such a job.
 
Last edited:

Dippy

Moderator
A schematic would be really handy here.

This all sounds a bit odd, but without your code calaculations I'm running in 'guess mode' a bit here.

So, you have:

Code:
20V-36V --- 39K ---|--- 10K --------- GND(0V)
                   |
                   |----|<Zener 4v7 -- GND(0V)
                   |
                  ADC in.
Is that about right?



If so....

Well, for a start 39K/10K is not suitable. Its OK for 24V max.
Try your calcs again ... or did you just copy the values? :)

Once you start going over 24 volts your zener will do its job; shunting the excess away. So your test values will be miles out.

If I understand correctly, you will need to use a pot-div where the 'junction' voltage is no greater than the Vsupply to your PICAXE.
i.e. when voltage-to-be-sensed = 36V then the 'junction' voltage <= PICAXE Vsupply.

Maybe start by replacing your 10K with a 5K6.

So, 2 useful things for you to post would be:
1. A schematic to make it 100% clear for us.
2. The crucial part of your code which does the readadc and calcs.


Also, please remember:
1. The supply voltage to your PICAXE must be rock steady.
2. Put a decoupling capacitor or two right next to the PICAXE +v / Gnd pins. Try a 10uF electrolytic // 100nF ceramic.

Personally, I would dump the zener. Zeners are NOT magic on-off safety valves. Read Data Sheets or do your own measurements.
Get your pot-div calcs right and err on the side of caution.
Don't make the 39K much bigger as it can upset ADC operations - personally I would reduce this value proportionally reduce the other res value too.
 

Dawnra

New Member
Many thanks for both your replies there is plenty of food for thought in them.

The circuit is more or less as drawn with just a small value smoothing capacitor at the ADC input.

20V-36V --- 39K ---|--- 10K --------- GND(0V)
|
|----|<Zener 4v7 -- GND(0V)
|
|----| |-0.01uF--- GND(0V)

ADC in.

What you say about the 4v7 zener makes sense because if I used a lower input voltage of say 5 - 15v all seemed to be linear. I worry a little about not having a safety clamp as I hope at some stage to log the input from a wind turbine. However I shall give it a go without the zener with the solar panel inputs and adjust the resistor divider network accordingly. I suppose if I had used a 5v1 zener the non-linear problem would not have been as pronounced.

I will let you know how I get on. Many thanks once again;).

Mike
 

BeanieBots

Moderator
Don't bother with a 5v1 zener, it will still give you problems.
Even if you do put a few too many volts on the potential divider, the PICAXE input will be clamped by its own internal protection diodes. If you are particularly worried, you can always fit a diode between ADC input and Vcc.

I'm sure you are familiar with the equation for the divider:-
Vout = Vin*R2(R1+R2)
but you might not be so familar with the other part.

Dippy mentioned not making the top part of your divider too large. This is because the ADC must not see a total resistance of greater than about 10k.
R1*R2/(R1+R2) must be less than about 10k.
(as long as at least one of the resistors is <10k then you'll be OK).
You can also use the equation to determine what current an over-volt will put into the ADC input. It must be limited to <2mA so you should not let your potential divider resistors be too low either.
 

Dawnra

New Member
Once again thanks for the swift reply.
I will remove the zener completely and drop R2 value from 10k to 5k6 and adjust the value of R1 accordingly to suit input voltage range. I suppose I was overly cautious using the zener. I will keep the current under 2mA.
Anyway thank you both for your help and must say how much I really enjoy learning about the wonderfully versatile picaxe chips in this forum.

Mike
 

BeanieBots

Moderator
Keep us posted on how you get on and don't forget to ask if you ever get stuck or are not sure of something.
Sounds like you have fun little project going there.
 

manie

Senior Member
BB and/or Dippy:
Dippy mentioned not making the top part of your divider too large. This is because the ADC must not see a total resistance of greater than about 10k.
You sy a "total" R of <10K, as seen by the ADC input. Could you eleborate a little with a text schematic maybe ? This could explain some ADC problems I have had in the past which eventually came right after fiddling R-values. I did not note down details then, so no knowledge gained...
 

womai

Senior Member
As to "total resistance", the ADC "sees" the two partial resistances of the divider (going to VCC and GND respectively) in parallel. If interested, google the term "Thevenin resistance" to see why.

So that means that e.g. a 1:2 divider consisting of two 10 kOhm resistors has an effective resistance of 5 kOhm to the ADC input.

Wolfgang
 
Last edited:

manie

Senior Member
Thanks Wolfgang. I will google, today is another good day, something new learnt on a hobby subject I knew very little of 18 months ago.
 

BeanieBots

Moderator
@manie,
Indeed, there are TWO parts to designing a potential divider.
The obvious part, the ratio that gives the divider action.
Vout=Vin*R1/(R1+R2)

and the part most people ignore, forget or don't even realise.
The impedance seen by the ADC input. (must be <10k for most PIC inputs).
Z=R1*R2/(R1+R2).

As wolfgang explains, it's Thevenin's Theorem.
Often stated as the "Thevenin equivalent source".

The output of a POT can be considered as a new voltage source with a single series resistor. Voltage and resistance values are given by the equations above.
 

Dippy

Moderator
Exactly. Everyone should put those notes into their Grimoires.

Re-jiggling that into a commonly used setup, let's imagine a simple potentiometer connected +V & 0v with wiper to PICAXE ADC.

The effective source impedance varies between zero (at the end stops) to 1/4 of the total pot resistance at the middle.

Also, as a general note, this source impedance forms a low-pass filter icw the PICs sampling capacitor. Meaning that higher Source Impedances need a longer settling/acq time. This isn't adjustable (as far as I know easily) within PICAXE BASIC, but is a reminder that very high source impedances can compromise fast/precise ADC results.

There are ways to 'get around' these impedance limitations using small caps for slow signal inputs, but should be used with care.
 

Dawnra

New Member
To all,

Thanks for the advice. I removed the dreaded zener from the voltage divider and changed the 10k (R2) to 5K6. Everything worked as advised. I have a linear reading from the ADC and managed to convert the value to voltage (with place one of decimal) to my serial LCD. I can now monitor the output from my solar panels.

Now all I need to do is get the second bank of a 24LC1025 eeprom working.
I am trying:
i2cslave %10100000, i2cfast8, i2cword - for Block 0 (1st 512K) of the eeprom (which works)

i2cslave %10101000, i2cfast8, i2cword - for Block 1 (2nd 512k) which returns only 255's.

Possibly something else wrong with my code.

I have in mind to build a complete control system for solar, wind, inverter which includes wireless transceivers to relay the data to and from a main controller in the house to battery shed. I hope to eventually go off grid.

I'll keep plugging away. These picaxe chips are really great fun.....:D

Thanks again.

Mike
 

BeanieBots

Moderator
Good luck with it, sounds like a really great project.
Please keep us posted on your progress. There are many on here with similar interests who could both learn and contribute.

Probably best to start a new thread with an approprite title for any EEPROM related issues.
 

Dawnra

New Member
Will definitely keep you posted.

Sorted my eeprom problem. My address counter wasnt resetting to zero at the start of Block 2 of the eeprom. Simple change in code sorted it.:eek:

Mike
 
Top