Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

[Microcontroller] Voltage Reading without ADC

zuirgham

Newbie level 6
Joined
Mar 19, 2019
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
163
How do I read an analog signal without an ADC using a digital input on the microcontroller ?

Analog Voltage Input: [ 6V - 8.4V ]
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
17,264
Helped
3,910
Reputation
7,818
Reaction score
3,777
Trophy points
113
Activity points
114,624
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
 

zuirgham

Newbie level 6
Joined
Mar 19, 2019
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
163
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.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
46,733
Helped
13,872
Reputation
27,992
Reaction score
12,516
Trophy points
1,393
Location
Bochum, Germany
Activity points
272,766
Required resolution still missing.

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

zuirgham

Newbie level 6
Joined
Mar 19, 2019
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
163
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.
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,109
Helped
4,674
Reputation
9,362
Reaction score
4,414
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
120,577
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.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
17,264
Helped
3,910
Reputation
7,818
Reaction score
3,777
Trophy points
113
Activity points
114,624
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
 

Aussie Susan

Advanced Member level 4
Joined
Jan 5, 2015
Messages
1,149
Helped
359
Reputation
718
Reaction score
355
Trophy points
83
Activity points
12,491
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
 

kripacharya

Banned
Joined
Dec 28, 2012
Messages
1,209
Helped
182
Reputation
360
Reaction score
175
Trophy points
1,343
Location
New Delhi
Activity points
0
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.
 

andre_teprom

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,143
Helped
1,134
Reputation
2,286
Reaction score
1,107
Trophy points
1,403
Location
Brazil
Activity points
53,066
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.
 

kripacharya

Banned
Joined
Dec 28, 2012
Messages
1,209
Helped
182
Reputation
360
Reaction score
175
Trophy points
1,343
Location
New Delhi
Activity points
0
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 ?
 

andre_teprom

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,143
Helped
1,134
Reputation
2,286
Reaction score
1,107
Trophy points
1,403
Location
Brazil
Activity points
53,066
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.
 

asdf44

Advanced Member level 4
Joined
Feb 15, 2014
Messages
1,006
Helped
353
Reputation
706
Reaction score
346
Trophy points
83
Activity points
8,408
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.
 

Toggle Sidebar

Part and Inventory Search


Welcome to EDABoard.com

Sponsor

Sponsor

Design Fast


×
Top