+ Post New Thread
Results 1 to 13 of 13
  1. #1
    Newbie level 4
    Points: 187, Level: 2

    Join Date
    Mar 2019
    Posts
    9
    Helped
    0 / 0
    Points
    187
    Level
    2

    [Microcontroller] Voltage Reading without ADC

    How do I read an analog signal without an ADC using a digital input on the microcontroller ?

    Analog Voltage Input: [ 6V - 8.4V ]

  2. #2
    Super Moderator
    Points: 79,246, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,084
    Helped
    3644 / 3644
    Points
    79,246
    Level
    68

    Re: [Microcontroller] Voltage Reading without ADC

    Hi,

    With usual microcontroller there is no chance to input higher voltages than VCC to any I/O pin.

    *****
    I don't understand:
    * Your microcontroller has no (built in) ADC?
    * or you don't want to use the built in) ADC? If so: why not?

    In either case you should give additional information:
    * what's the frequency range of the input signal
    * how often (period time or frequency) do you need a converted signal in your SW?
    * what resolution do you expect?

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  3. #3
    Newbie level 4
    Points: 187, Level: 2

    Join Date
    Mar 2019
    Posts
    9
    Helped
    0 / 0
    Points
    187
    Level
    2

    Re: [Microcontroller] Voltage Reading without ADC

    My intention is to monitor battery voltage at any given point of time. Voltage of battery falls in between [6v - 8.4v]. Accuracy is not a concern.
    I'm using 3.3V operating voltage PicController. I have used all the ADC Pins, and only 4 digital pins are left out.



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 262,101, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,810
    Helped
    13929 / 13929
    Points
    262,101
    Level
    100

    Re: [Microcontroller] Voltage Reading without ADC

    Required resolution still missing.

    How about using a small (e.g. 6 pin) analog MUX to share an existing ADC pin?


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  5. #5
    Newbie level 4
    Points: 187, Level: 2

    Join Date
    Mar 2019
    Posts
    9
    Helped
    0 / 0
    Points
    187
    Level
    2

    Re: [Microcontroller] Voltage Reading without ADC

    I have already multiplexed ADC pins with other Sensors. Suggest me something simple where i will know the battery voltage through Software.
    Also suggest Resolution for the above voltage limits according to solution.



  6. #6
    Super Moderator
    Points: 82,046, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,461
    Helped
    4492 / 4492
    Points
    82,046
    Level
    69

    Re: [Microcontroller] Voltage Reading without ADC

    For accuracy there is no substitute for an ADC. If you have two spare digital pins you could consider adding an external I2C one.

    If you want simplicity but not accuracy, you can do it by timing how long it takes to charge a capacitor from the battery voltage. It will be subject to the tolerance of the components, especially the capacitor and the exact logic threshold of the digital pin but it will give a rough idea of the voltage:

    Connect the battery voltage through a resistor so it charges a capacitor, I would suggest aiming for a time constant of about 200mS up to 1 second and keeping the resistor > 10K. Connect the digital pin from the junction of the R and C and start the program with the pin driven low. This should keep the voltage across the capacitor close to zero volts. When you want to take the measurement, change the pin to an input and start a timer. When it goes to logic 1 state, stop the timer and immediately drive the pin low again to prevent it going over-voltage. The timer value will be proportional to the current that charged the capacitor and therefore the voltage providing the current. You will have to do the math to work out the voltage according to the values you used. For safety, add a low value resistor in series with the digital pin (~100 Ohms) to limit the discharge current when you drive the pin low after the measurement.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  7. #7
    Super Moderator
    Points: 79,246, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,084
    Helped
    3644 / 3644
    Points
    79,246
    Level
    68

    Re: [Microcontroller] Voltage Reading without ADC

    Hi,

    no one can tell you which resolution you need. You need to decide it on your own.

    Every time we give a suggestion you come with another information against it. This is time consuming for you and for us.
    --> Thus I recommend you give all informations in one post.

    ***
    With the currently given informations: Use an external ADC with serial interface - maybe in bit banging mode.

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  8. #8
    Advanced Member level 4
    Points: 7,924, Level: 21

    Join Date
    Jan 2015
    Posts
    1,109
    Helped
    349 / 349
    Points
    7,924
    Level
    21

    Re: [Microcontroller] Voltage Reading without ADC

    If all you are interested in is if a voltage is above or below a given value, then use a comparator and a stable voltage source (e.g. a zener or you want something cheap and nasty). T
    That can feed a digital port - (say) high = voltage over the limit, low = voltage under the limit.
    Susan


    1 members found this post helpful.

  9. #9
    Advanced Member level 4
    Points: 6,247, Level: 18
    kripacharya's Avatar
    Join Date
    Dec 2012
    Location
    New Delhi
    Posts
    1,209
    Helped
    182 / 182
    Points
    6,247
    Level
    18

    Re: [Microcontroller] Voltage Reading without ADC

    Quote Originally Posted by betwixt View Post
    For accuracy there is no substitute for an ADC. If you have two spare digital pins you could consider adding an external I2C one.

    If you want simplicity but not accuracy, you can do it by timing how long it takes to charge a capacitor from the battery voltage. It will be subject to the tolerance of the components, especially the capacitor and the exact logic threshold of the digital pin but it will give a rough idea of the voltage:

    Connect the battery voltage through a resistor so it charges a capacitor, I would suggest aiming for a time constant of about 200mS up to 1 second and keeping the resistor > 10K. Connect the digital pin from the junction of the R and C and start the program with the pin driven low. This should keep the voltage across the capacitor close to zero volts. When you want to take the measurement, change the pin to an input and start a timer. When it goes to logic 1 state, stop the timer and immediately drive the pin low again to prevent it going over-voltage. The timer value will be proportional to the current that charged the capacitor and therefore the voltage providing the current. You will have to do the math to work out the voltage according to the values you used. For safety, add a low value resistor in series with the digital pin (~100 Ohms) to limit the discharge current when you drive the pin low after the measurement.

    Brian.
    This is the time tested way to measure slow moving Voltage, or an unknown Resistor, or an unknown Capacitor using a single Tri-stateble digital I/O pin and timer.



  10. #10
    Super Moderator
    Points: 29,873, Level: 42
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,917
    Helped
    1130 / 1130
    Points
    29,873
    Level
    42
    Blog Entries
    9

    Re: [Microcontroller] Voltage Reading without ADC

    A comparator is the default choice in these cases, but if you do not need more than one, you might want to consider doing that with a precision shunt regulator (e.g TL431), few components needed.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisement

        
       

  11. #11
    Advanced Member level 4
    Points: 6,247, Level: 18
    kripacharya's Avatar
    Join Date
    Dec 2012
    Location
    New Delhi
    Posts
    1,209
    Helped
    182 / 182
    Points
    6,247
    Level
    18

    Re: [Microcontroller] Voltage Reading without ADC

    Quote Originally Posted by andre_teprom View Post
    A comparator is the default choice in these cases, but if you do not need more than one, you might want to consider doing that with a precision shunt regulator (e.g TL431), few components needed.
    A comparator would provide only a single set-point which could be monitored. I assume OP wants to linearly measure/ monitor entire range between 6v to 8.4v, where scheme outlined by @betwixt in post #6 is actually the more common choice.

    It's not clear how a regulator can help with this ? Could you explain the scheme ?



  12. #12
    Super Moderator
    Points: 29,873, Level: 42
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,917
    Helped
    1130 / 1130
    Points
    29,873
    Level
    42
    Blog Entries
    9

    Re: [Microcontroller] Voltage Reading without ADC

    Quote Originally Posted by kripacharya View Post
    A comparator would provide only a single set-point which could be monitored. I assume OP wants to linearly measure
    From what was posed so far, indeed not clearly, it is assumed that OP wants to simply detect the battery low-level (supposedly lead-acid, given the above values), for which he certainly is not aware of how such range is inadequate. Based on this accuracy, I support the same approach suggested by Aussie Susan, where a simple threshold could solve.

    My intention is to monitor battery voltage at any given point of time. Voltage of battery falls in between [6v - 8.4v]. Accuracy is not a concern.

    Quote Originally Posted by kripacharya View Post
    It's not clear how a regulator can help with this ? Could you explain the scheme ?
    The TL431 can be used as comparator, it is not too difficult to find implementations of this, as said, it can save space if compared with a standard comparator package. If you are referring to the hypothesis of detecting more than 1 voltage levels, search the web for shunt regulator in the "window detector" topology, as can be found here:

    Click image for larger version. 

Name:	WindowVoltageDetector.png 
Views:	4 
Size:	17.8 KB 
ID:	154400

    Anyway, the RC approach covers the midterm world, take the voltage in a widest scale if compared with the single point detector.

    Options given, let's him choose the one that meets his need.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  13. #13
    Advanced Member level 3
    Points: 6,274, Level: 18

    Join Date
    Feb 2014
    Posts
    904
    Helped
    298 / 298
    Points
    6,274
    Level
    18

    Re: [Microcontroller] Voltage Reading without ADC

    Quote Originally Posted by betwixt View Post
    For accuracy there is no substitute for an ADC. If you have two spare digital pins you could consider adding an external I2C one.

    If you want simplicity but not accuracy, you can do it by timing how long it takes to charge a capacitor from the battery voltage. It will be subject to the tolerance of the components, especially the capacitor and the exact logic threshold of the digital pin but it will give a rough idea of the voltage:

    Connect the battery voltage through a resistor so it charges a capacitor, I would suggest aiming for a time constant of about 200mS up to 1 second and keeping the resistor > 10K. Connect the digital pin from the junction of the R and C and start the program with the pin driven low. This should keep the voltage across the capacitor close to zero volts. When you want to take the measurement, change the pin to an input and start a timer. When it goes to logic 1 state, stop the timer and immediately drive the pin low again to prevent it going over-voltage. The timer value will be proportional to the current that charged the capacitor and therefore the voltage providing the current. You will have to do the math to work out the voltage according to the values you used. For safety, add a low value resistor in series with the digital pin (~100 Ohms) to limit the discharge current when you drive the pin low after the measurement.

    Brian.
    Input voltage thresholds are very widely specified however. Perhaps adding 50% worst case error.

    Could be improved by adding a comparator with reference to the scheme.


    Another scheme is to use a dac (do you have any?) or a filtered PWM ouptut as a crude dac and compare it to your unknown signal with a comparator.


    Finally a voltage-to-pwm circuit is another option that can accurately get an analog value into a single digital pin. LTC6992 is the best.



--[[ ]]--