Voltage monitor and decision circuit

Discussion in 'The Projects Forum' started by mtstudent, Oct 10, 2009.

  1. mtstudent

    Thread Starter New Member

    Oct 10, 2009
    2
    0
    Hello,
    I am working on a project that uses a microcontroller to make a decision based on the input voltage. The input comes from a 12V battery bank. The microcontroller will be used to turn lights on or off depending on what the battery voltage is. For example. If the voltage is this much, turn this light on, if the voltage is now this much, turn the first light off and turn this light on, etc... The microcontroller only accepts an input from 0-5V. So how do I build a circuit that will have an output from 0-5V and an input from 0-say 13.6V. I know I could use a voltage divider circuit and then have the controller do the math to calculate the voltage but is there any other way that some of you electronics experts may be able to come up with to do this.

    Thanks for all your help.
     
  2. CDRIVE

    Senior Member

    Jul 1, 2008
    2,223
    99
    Actually, that's the way it should be done. Why complicate it? ;)
     
  3. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    If you're doing this for an automotive application, keep in mind that the initial charging voltage may get up to 15v, and you may have peak voltage "spikes" up to around 40v.

    Typical auto electrical system voltage when engine is running and battery is charged is around 13.8v.

    A PIC uC has ESD protection diodes on it's inputs, but with limited current handling capabilities; perhaps 5mA. If you plan for peak voltage spikes of 60v, then your high side voltage divider resistor will need to be (60v-Vcc)/5mA = 11k Ohms or higher to provide adequate protection.

    But to keep things simple, use 20k for the upper side of the divider, and 10k for the lower side. This will give you a range of 0-15v in, 0-5v out. Use a 0.1uF cap at the junction to provide both noise filtering, and a low-impedance source for the uC's ADC to sample.
     
  4. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    I agree with CDRIVE. The resistive divider is a very reasonable way to tackle this signal monitoring task.

    If you arrange to use a divide by 4 attenuator rather than one that gets you to the 0 to 5 volt range, you can make the math very simple. All you need to do is shift left 2 bits and you have it. There will be loss of resolution but as the designer you can decide which is more important, code efficiency at the expense of resolution or resolution at the expense or greater code complexity. Trade-offs are the essence of engineering.

    The reduced resolution will amount to +/- 0.2 volts versus +/- 0.05 volts.

    hgmjr
     
  5. CDRIVE

    Senior Member

    Jul 1, 2008
    2,223
    99
    Ah, but Sgt. Wookie, being the good Marine that he is, gave good advice regarding a spike cap. Actually, I always use a small cap on the ADC input of Micros. A reverse biased protection diode won't hurt either. ;)
     
  6. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Yes indeed. This is a good place to include protection against the likely occurrance of a voltage that exceeds the maximum input voltage range on the micro.

    hgmjr
     
  7. russ_hensel

    Well-Known Member

    Jan 11, 2009
    818
    47
    I almost always use an op amp because it is easy to have overvoltage protection and low output impedance. If you use a voltage divider calculate the output impedance and compare to the max impedance expected by the ADC. Roughly the output impedance is equal to the resistor connected to the ground in the divider.
     
  8. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    The requirement to have a low impedance at the ADC input is at frequencies near where the Successive Approximation Switching is taking place (~100kHz), the d.c. impedance is not too important. If you are sampling a slowly varying input like battery voltage, a relatively high-impedance resistive divider with a large capacitor between the ADC input to ground works just fine...
     
  9. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    True, you could make a 4:1 divider using a 30k and 10k resistor which makes the math a bit easier - but with the 3:1 divider, you can still go with the Vdd as a 5v reference, and just take the result, save it in a register, shift the result left 1 bit, and then add in the saved register to effect a multiply by three. You wouldn't lose any more resolution that way, and the math is not terribly complicated. Much better than including math.h and slinging the * operator around to see your code bloat.

    With a 10-bit ADC, your resolution will be around 14.648mV.
    With an 11-bit ADC, resolution will be around 7.324mV.

    If you're going to go with the 4:1 divider, you should use a precision 3.75v reference for the ADC to minimize the loss of resolution.
     
  10. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    This is somewhat true, which is why I suggested using the cap to present a low input impedance source to the ADC. However I forgot to mention anything about the RC time, and time between ADC samples (tsk, tsk). :rolleyes: ;)

    With the top resistor being 20k, the lower 10k, and a 0.1uF cap, you should allow a minimum of 10mS between ADC samples for the voltage to stabilize.
     
    Last edited: Oct 10, 2009
  11. mtstudent

    Thread Starter New Member

    Oct 10, 2009
    2
    0
    Hey guys thanks for the input, I have decided to use the resistor divider scheme although it is for a wind generator application and the charge controller should limit any voltage spikes from the battery if I understand the operation of the charge controller completely. I am also using an arduino controller because honestly it appears to be very easy to program and I have limited programming knowledge. I didn't think about a blocking diode or cap though and that is not a bad idea. Thanks for the help.
     
Loading...