EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Circuit to read voltage for ADC - PIC

Started by devonsc December 14, 2004

First of all, thanks a lot for everyone's kindness in guiding me on my
doubts before this. Would like to ask regarding the following matter:

Firstly, the voltage output of my solar panel varies from 4V to 10V
(Will not exceed 10V). I intend to shut the PIC down if the output of
the solar panel is lower than 4V. Apart from that, I intend to
power-up my PIC using the power directly from the solar panel.

About reading voltage value using ADC, is there a way where I can
scale the read down the values from the solar panel output? Something
like: What ever reading value I obtain from the solar panel's output,
I make sure it is being divided by 2 before being applied to the ADC
input of the PIC using a voltage divider. If yes, do you guys mind to
guide me in this simple circuit? I tried doing some simulations to tap
the voltage from a source and divide it to obtain a half of through
simulations but fail :(

Meaning, overall, I intend do the following: By having 2 ADC inputs,
a.) one would be an input of a "limited to 5V input". At this point,
if the PIC reads a value of lower than 4V, I shut off the PIC.

b.) another would be an input of a "voltage from the solar panel
divided by two". This will be the one to control my PWM duty ratio.

By the way, the duty ratio will be used to control my on/off of a
MOSFET and I need approximately 16mA to turn it on. Would like to
confirm, about this: Does it mean that if the voltage used to power-up
my PIC is 4V, I will obtained an output current of approx. 20mA?
Whereas if it is 3V, it will be approx. 15mA?
_________________





I assume you will be using a low-drop-out regulator (like a 3940-5)
to regulate the output of the solar panel?

The 'drop-out' voltage (0.5 volts for the 3940) is how much voltage
over the desired one you must produce, for the regulator to work.

Never having done what you are trying to do, I'm not sure of the
voltage range of the PIC. It does have a 'brown-out' setting, though.

--- In , "devonsc" <devonsc@y...> wrote:
>
> First of all, thanks a lot for everyone's kindness in guiding me on
my
> doubts before this. Would like to ask regarding the following
matter:
>
> Firstly, the voltage output of my solar panel varies from 4V to 10V
> (Will not exceed 10V). I intend to shut the PIC down if the output
of
> the solar panel is lower than 4V. Apart from that, I intend to
> power-up my PIC using the power directly from the solar panel.
>
> About reading voltage value using ADC, is there a way where I can
> scale the read down the values from the solar panel output?
Something
> like: What ever reading value I obtain from the solar panel's
output,
> I make sure it is being divided by 2 before being applied to the ADC
> input of the PIC using a voltage divider. If yes, do you guys mind
to
> guide me in this simple circuit? I tried doing some simulations to
tap
> the voltage from a source and divide it to obtain a half of through
> simulations but fail :(
>
> Meaning, overall, I intend do the following: By having 2 ADC inputs,
> a.) one would be an input of a "limited to 5V input". At this point,
> if the PIC reads a value of lower than 4V, I shut off the PIC.
>
> b.) another would be an input of a "voltage from the solar panel
> divided by two". This will be the one to control my PWM duty ratio.
>
> By the way, the duty ratio will be used to control my on/off of a
> MOSFET and I need approximately 16mA to turn it on. Would like to
> confirm, about this: Does it mean that if the voltage used to power-
up
> my PIC is 4V, I will obtained an output current of approx. 20mA?
> Whereas if it is 3V, it will be approx. 15mA?
> _________________






Many PICs will operate at 3.3V - I just used a 16LF628A at this
voltage quite successfully.

A voltage divider of, say, 2 is quite simple: use two 1K ohm
resistors in series. Put one end of the string at ground, the input
voltage at the other end and the center point will be 1/2 of the
input.

Want divide by 3? Put the input into a 2K resistor (or 2 1K
resistors in series) use the same 1K resistor to ground and measure
at the upper end of the 1K, just like before.

Now, here's where it gets ugly: The input impedance of the A/D
converter is in parallel with the lower resistor, reducing its value
by probably 10%. To get a more accurate solution, you may need to
increase the lower resistor to 1.1K. You can do this with 2 2.2K
resistors in parallel.

Of course, the proper way to do this is with an Op Amp because the
output impedance of the Op Amp is quite low and the input impedance
of the A/D converter won't affect the accuracy of the division. --- In , "Allan Lane" <allan.lane@h...> wrote:
>
> I assume you will be using a low-drop-out regulator (like a 3940-
5)
> to regulate the output of the solar panel?
>
> The 'drop-out' voltage (0.5 volts for the 3940) is how much
voltage
> over the desired one you must produce, for the regulator to work.
>
> Never having done what you are trying to do, I'm not sure of the
> voltage range of the PIC. It does have a 'brown-out' setting,
though.
>
> --- In , "devonsc" <devonsc@y...> wrote:
> >
> > First of all, thanks a lot for everyone's kindness in guiding me
on
> my
> > doubts before this. Would like to ask regarding the following
> matter:
> >
> > Firstly, the voltage output of my solar panel varies from 4V to
10V
> > (Will not exceed 10V). I intend to shut the PIC down if the
output
> of
> > the solar panel is lower than 4V. Apart from that, I intend to
> > power-up my PIC using the power directly from the solar panel.
> >
> > About reading voltage value using ADC, is there a way where I can
> > scale the read down the values from the solar panel output?
> Something
> > like: What ever reading value I obtain from the solar panel's
> output,
> > I make sure it is being divided by 2 before being applied to the
ADC
> > input of the PIC using a voltage divider. If yes, do you guys
mind
> to
> > guide me in this simple circuit? I tried doing some simulations
to
> tap
> > the voltage from a source and divide it to obtain a half of
through
> > simulations but fail :(
> >
> > Meaning, overall, I intend do the following: By having 2 ADC
inputs,
> > a.) one would be an input of a "limited to 5V input". At this
point,
> > if the PIC reads a value of lower than 4V, I shut off the PIC.
> >
> > b.) another would be an input of a "voltage from the solar panel
> > divided by two". This will be the one to control my PWM duty
ratio.
> >
> > By the way, the duty ratio will be used to control my on/off of a
> > MOSFET and I need approximately 16mA to turn it on. Would like to
> > confirm, about this: Does it mean that if the voltage used to
power-
> up
> > my PIC is 4V, I will obtained an output current of approx. 20mA?
> > Whereas if it is 3V, it will be approx. 15mA?
> > _________________




Hi there, thanks for the explanation. Do you mind
checking the circuit that I've simulated (as
attached).

By the way, with reference to the Point A in the
circuit, is it a must for me to include a low
resistance resistor at Point A before tapping the
voltage off the line? If it is a must, do you mind
explaining what is the purpose of doing so as I don't
seem to find any difference in having the resistor
there or not there.

Should I just use the voltage divider circuit in my
project? As I might face difficulties in supplying my
op-amp. Is it true that most of the supply voltage of
the op-amp is -/+15V? I will not be able to power it
up with my solar panel.

Thanks in advance...

--- rtstofer <> wrote:

>
>
> Many PICs will operate at 3.3V - I just used a
> 16LF628A at this
> voltage quite successfully.
>
> A voltage divider of, say, 2 is quite simple: use
> two 1K ohm
> resistors in series. Put one end of the string at
> ground, the input
> voltage at the other end and the center point will
> be 1/2 of the
> input.
>
> Want divide by 3? Put the input into a 2K resistor
> (or 2 1K
> resistors in series) use the same 1K resistor to
> ground and measure
> at the upper end of the 1K, just like before.
>
> Now, here's where it gets ugly: The input impedance
> of the A/D
> converter is in parallel with the lower resistor,
> reducing its value
> by probably 10%. To get a more accurate solution,
> you may need to
> increase the lower resistor to 1.1K. You can do
> this with 2 2.2K
> resistors in parallel.
>
> Of course, the proper way to do this is with an Op
> Amp because the
> output impedance of the Op Amp is quite low and the
> input impedance
> of the A/D converter won't affect the accuracy of
> the division. > --- In , "Allan Lane"
> <allan.lane@h...> wrote:
> >
> > I assume you will be using a low-drop-out
> regulator (like a 3940-
> 5)
> > to regulate the output of the solar panel?
> >
> > The 'drop-out' voltage (0.5 volts for the 3940) is
> how much
> voltage
> > over the desired one you must produce, for the
> regulator to work.
> >
> > Never having done what you are trying to do, I'm
> not sure of the
> > voltage range of the PIC. It does have a
> 'brown-out' setting,
> though.
> >
> > --- In , "devonsc"
> <devonsc@y...> wrote:
> > >
> > > First of all, thanks a lot for everyone's
> kindness in guiding me
> on
> > my
> > > doubts before this. Would like to ask regarding
> the following
> > matter:
> > >
> > > Firstly, the voltage output of my solar panel
> varies from 4V to
> 10V
> > > (Will not exceed 10V). I intend to shut the PIC
> down if the
> output
> > of
> > > the solar panel is lower than 4V. Apart from
> that, I intend to
> > > power-up my PIC using the power directly from
> the solar panel.
> > >
> > > About reading voltage value using ADC, is there
> a way where I can
> > > scale the read down the values from the solar
> panel output?
> > Something
> > > like: What ever reading value I obtain from the
> solar panel's
> > output,
> > > I make sure it is being divided by 2 before
> being applied to the
> ADC
> > > input of the PIC using a voltage divider. If
> yes, do you guys
> mind
> > to
> > > guide me in this simple circuit? I tried doing
> some simulations
> to
> > tap
> > > the voltage from a source and divide it to
> obtain a half of
> through
> > > simulations but fail :(
> > >
> > > Meaning, overall, I intend do the following: By
> having 2 ADC
> inputs,
> > > a.) one would be an input of a "limited to 5V
> input". At this
> point,
> > > if the PIC reads a value of lower than 4V, I
> shut off the PIC.
> > >
> > > b.) another would be an input of a "voltage from
> the solar panel
> > > divided by two". This will be the one to control
> my PWM duty
> ratio.
> > >
> > > By the way, the duty ratio will be used to
> control my on/off of a
> > > MOSFET and I need approximately 16mA to turn it
> on. Would like to
> > > confirm, about this: Does it mean that if the
> voltage used to
> power-
> > up
> > > my PIC is 4V, I will obtained an output current
> of approx. 20mA?
> > > Whereas if it is 3V, it will be approx. 15mA?
> > > _________________ >
>

__________________________________

Attachment (not stored)
ADC Voltage Read.jpg
Type: image/jpeg


At 01:39 PM 12/14/2004, rtstofer wrote:

>Want divide by 3? Put the input into a 2K resistor (or 2 1K
>resistors in series) use the same 1K resistor to ground and measure
>at the upper end of the 1K, just like before.
>
>Now, here's where it gets ugly: The input impedance of the A/D
>converter is in parallel with the lower resistor, reducing its value
>by probably 10%. To get a more accurate solution, you may need to
>increase the lower resistor to 1.1K. You can do this with 2 2.2K
>resistors in parallel.

The statement about the a/d input impedance is off by a large
factor. Microchip specs say that source impedance must be less than 10K
for 8 bit a/d or less than 2.5K for 10 bit a/d for 1/2 LSB error. Your
source impedance is considered to be the voltage divider resistors in
parallel: 3:1 voltage divider with 2K feeding 1K is a source impedance of
about 667 Ohms - well within the allowable range.

Note 1: putting a cap in parallel with the lower resistor is always a good
idea - it both filters the input as well as providing a low impedance
source for that brief instant when the s/h switch operates inside the a/d
converter. Its not absolutely necessary but I do include them on all my
low speed a/d inputs.

Note 2: Increasing source impedance above the recommended values can NOT be
compensated for by manipulating the divider ratio. The problem is that
input impedance related errors are caused by leakage current which can be
either positive or negative and which can (will) change depending on the
input voltage.

I used to be able to cheat the input impedance specs on the older 16c71 &
16c73 / 74 chips - the leakage on those parts was extremely low and source
impedance errors were dominated by the s/h charge current. That was easily
fixed by adding a filter cap to each a/d input.

But all the newer flash parts with the smaller process geometries have much
higher leakage currents than the old OTP parts and you can't cheat that way
any more.

Its actually quite a step backwards when trying to design a very low cost
product that requires extensive filtering on the a/d inputs. I'm currently
re-designing one product that originally used a high impedance 3 stage RC
filter on the a/d inputs - now I have to add an opamp buffer to deal with
much higher a/d leakage currents (16c71 vs 16f676). The added a/d
resolution makes it worthwhile, though.

dwayne

--
Dwayne Reid <>
Trinity Electronics Systems Ltd Edmonton, AB, CANADA
(780) 489-3199 voice (780) 487-6397 fax

Celebrating 20 years of Engineering Innovation (1984 - 2004)
.-. .-. .-. .-. .-. .-. .-. .-. .-. .-
`-' `-' `-' `-' `-' `-' `-' `-' `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.



--- In , Devon Lee <devonsc@y...> wrote:
> Hi there, thanks for the explanation. Do you mind
> checking the circuit that I've simulated (as
> attached).

Your sketch didn't stay attached. No way to check it.

>
> By the way, with reference to the Point A in the
> circuit, is it a must for me to include a low
> resistance resistor at Point A before tapping the
> voltage off the line? If it is a must, do you mind
> explaining what is the purpose of doing so as I don't
> seem to find any difference in having the resistor
> there or not there.
>
> Should I just use the voltage divider circuit in my
> project? As I might face difficulties in supplying my
> op-amp. Is it true that most of the supply voltage of
> the op-amp is -/+15V? I will not be able to power it
> up with my solar panel.

A voltage divider will probably work out fine. You may have to do
some kind of calibration but that shouldn't be a problem.

The TI TLV2474 Op Amp is a quad unit that will operate from the same
supply as the PIC, either 3.3V or 5V. Dual supplies are not required.
There are variations: check www.ti.com. While you are there, get "Op
Amps For Everyone" and check out chapter 4. The book is free.

Specifically, chapter 4 deals with scaling and offset of input
signals. For example, I was once interested in battery voltages
between 20 and 28 volts. It was possible to change this to a 0..5V
input with a single op amp and a few resistors. This made maximum use
of the A/D converter because the batteries would cease to function if
they dropped below 20V anyway. Kind of like your solar panel; below a
certain level is meaningless and it is better to offset the signal and
rescale for enhanced accuracy of the important range of voltages.



The 2024 Embedded Online Conference