Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Microcontroller] Voltage Reading without ADC

Status
Not open for further replies.

zuirgham

Junior Member level 3
Junior Member level 3
Joined
Mar 19, 2019
Messages
31
Helped
0
Reputation
0
Reaction score
1
Trophy points
8
Activity points
368
How do I read an analog signal without an ADC using a digital input on the microcontroller ?

Analog Voltage Input: [ 6V - 8.4V ]
 

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
 

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.
 

Required resolution still missing.

How about using a small (e.g. 6 pin) analog MUX to share an existing ADC pin?
 
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.
 

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.
 
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
 

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
 
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.
 

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 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 ?
 

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.

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:

WindowVoltageDetector.png

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.
 

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.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top