Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

+/-12V to 0/5V converter. Please help!

Status
Not open for further replies.

benq

New Member
I want to read +/-12VDC signal by using PIC, but the ADC input range of most microcontrollers is 0-5V.

How can I make 1 circuit to map +/-12V to 0/5V?

-12V -> 0V
0V -> 2.5V
+12V -> 5V

Please help!!!
 
benq said:
I want to read +/-12VDC signal by using PIC, but the ADC input range of most microcontrollers is 0-5V.

How can I make 1 circuit to map +/-12V to 0/5V?

-12V -> 0V
0V -> 2.5V
+12V -> 5V

Please help!!!

hi,
This circuit will do what you require.

Set it up BEFORE you connect the Vout to the PIC ADC input.:)

EDIT: opa psu correction.

EDIT2:
Refreshed the drawing, 27 July 2012
 
Last edited:
First stage voltage follower will not function with single positive supply. Its pin7 cannot go negative.

One needs a -VE power supply also for LM358 to make the circuit works.
 
eblc1388 said:
First stage voltage follower will not function with single positive supply. Its pin7 cannot go negative.

One needs a -VE power supply also for LM358 to make the circuit works.

Hi,
You are right, tried to modify an earlier opa offset drawing of mine, will correct the dwg.

Thanks.:)

Corrected dwg.
 
Last edited:
Thanks so much.

I don't know why the voltage at the pin3 of OPA2 is 1.25V. I think it should be adjusted to 2.5V. Is it right?
 
benq said:
Thanks so much.

I don't know why the voltage at the pin3 of OPA2 is 1.25V. I think it should be adjusted to 2.5V. Is it right?

hi,

No, dont forget the gain of the non-inverting input is G = 1+ Rf/Rin
So if the gain of the inverting stage is '1' the non-invert is '2'.:)

This is a well used circuit and should give no problems, choose a good opa, not say a 741.
 
Hi beng,

The sense of OPA2 output is inverted. Overall with +12V input, output is zero volt while -12V input will give +5V output.

If you want +12V to give +5V and -12V to give 0V output, you can use an inverting stage instead of a voltage follower for the first stage.
 
Last edited:
I don't know why everyone is going for the difficult solutions, when there is an easy one.

Connect a 10k :eek:hm: resistor in series with the point to be measured.
Connect the other end to the PIC A/D input
Connect a 4200 :eek:hm: from the PIC A/D input to +5V
Connect a 7200 :eek:hm: from the PIC A/D input to Ground.

More precise values are 4166.714611 :eek:hm: and 7142.857143 :eek:hm:

Having said that, I had a similar problem some years ago and I solved it with OP amps, before I realised the simple way.
 
Diver300 said:
I don't know why everyone is going for the difficult solutions, when there is an easy one.

There are many good reasons to use the opamp method:

1) The resistor values required are obscure.

2) It only has a low input impedance.

3) It actually outputs a voltage to the target, which isn't really what you want! - and could cause damage.
 
OP didn't say where the +/-12V is coming from. Maybe it's OK. Accuracy requirements weren't noted either.

1) Easily overcome with potentiometers. The 10K would become ~9k5 in series with a 1K pot (gain adjust). The 4k2 and 7k2 would be a 1K pot (offset adjust) between 3k9 and 6k8 resistors. The ~9k5 is made by placing 220k in parallel with 10k.

2) There are many ways to increase the input impedance: a single voltage follower for example. Or, depending on your ADC impedance, you might be able to scale the resistors by a factor of 10 or more.

3) A buffer will also isolate the target from unwanted bias current, if it's actually a problem.
 
Nigel Goodwin said:
There are many good reasons to use the opamp method:

1) The resistor values required are obscure.
True

Nigel Goodwin said:
2) It only has a low input impedance.
Also true

Nigel Goodwin said:
3) It actually outputs a voltage to the target, which isn't really what you want! - and could cause damage.
I beg to differ here. Yes, the resistor network presents a voltage, but that is what you want, and it shouldn't cause damage.

There needs to be a voltage in the range 0 - 5V presented to the PIC analog input, to be measured. It is just a voltage, no matter where it comes from.

The impedance should be low enough that the PIC can does not affect it. The PIC data sheets talks about sampling times and source impedance. It shouldn't be possible to have too low an impedance.

If the input voltage strays outside -12 to +12, the output will stray outside 0 - 5V, but that will be clamped by the input diodes on the PIC so it won't cause damage, unless the voltages are huge, as the 10k:eek:hm: will limit the current.
 
3) It actually outputs a voltage to the target, which isn't really what you want! - and could cause damage.
The divider network will present about 3V through 10k ohms (up to 300 microamps) at the +/-12V input. If the +/-12V input can't tolerate this, then it's a problem.
 
Diver300 said:
More precise values are 4166.714611 :eek:hm: and 7142.857143 :eek:hm:

It would be an handy alternative if one want to reads the AC voltage from say a transformer secondary.

Can you also provide a way/formula to calculate those resistance values so that others will benefit from using this method?
 
eblc1388 said:
It would be an handy alternative if one want to reads the AC voltage from say a transformer secondary.

Can you also provide a way/formula to calculate those resistance values so that others will benefit from using this method?

I don't know if I can provide a simple formula, but the way I calculated it is like this.

The first thing to know is that a potential divider produces a voltage, (obviously) and that the impedance of that voltage is the parallel combination of the two resistors (less obvious). So the pull up and the pull down (the 4166.714611 :eek:hm: and 7142.857143 :eek:hm: produce a voltage of 3.1579 V that has an impedance of 2631.598 :eek:hm: . It is just the same as a 3.1579 V source with a 2631.598 :eek:hm: in series.

I calculated the 3.1579 V and the 2631.598 :eek:hm:, and from that worked back to the 4166.714611 :eek:hm: and the 7142.857143 :eek:hm:

I chose 10k, so the 10k to 2631.598 :eek:hm: divider needs to reduce 24V swing (±12V) needs to 5V, which is how the 2631.598 :eek:hm: is decided.

10000:eek:hm: /(24-5)*5 equals 2631.598 :eek:hm:

When the input is 0V the output needs to be 2.5V, and this is how the 3.1579 V is decided.

2.5/10000*(10000+2631.598) equals 3.1579 V

Then the 4166.714611 :eek:hm: and 7142.857143 :eek:hm: can be found because

7142.857143 / ( 7142.857143 + 4166.714611 ) * 5 = 3.1579

and

1/7142.857143 + 1/4166.714611 = 1/2631.598

That actually involves a simultaneous equation, and I'm not going to tell everyone how to do that. However, it is OK to guess a value for the resistors and see what voltage and impedance you get, then modify the guesses. It only takes a few tries to get more accurate guesses than the resistors can be.
 
Diver300 said:
Connect a 10k :eek:hm: resistor in series with the point to be measured.
Connect the other end to the PIC A/D input
Connect a 4200 :eek:hm: from the PIC A/D input to +5V
Connect a 7200 :eek:hm: from the PIC A/D input to Ground.

More precise values are 4166.714611 :eek:hm: and 7142.857143 :eek:hm:

If one solves the equations, one would end up with a much easier method to calculate those resistor values.

Let's say:
Vmax=+12V (from +/-12V),
Vpic=5V,
Rin=10K (we have full control over this value and can choose one to suit the signal source),
Rvcc=?,
Rgnd=?

So we have just two unknown resistors to calculate.

Rvcc = Vpic * Rin / Vmax = 5 * 10K / 12 = 4.167K

Rgnd = Vpic * Rin /( Vmax - Vpic ) = 5 * 10K / ( 12 - 5 ) = 7.143K
 
hi beng,
Whats the source of the +/-12Vdc drive, ie: type of sensor and output impedance?
 
Diver300 said:
I beg to differ here. Yes, the resistor network presents a voltage, but that is what you want, and it shouldn't cause damage.

Funny?, I don't remember my multimeter puts out a voltage to the circuit on a volts range? - I hardly thin it's "what you want", and certainly not what I want.

There needs to be a voltage in the range 0 - 5V presented to the PIC analog input, to be measured. It is just a voltage, no matter where it comes from.

The impedance should be low enough that the PIC can does not affect it. The PIC data sheets talks about sampling times and source impedance. It shouldn't be possible to have too low an impedance.

The low part isn't for the PIC, but for the sorce, too low an impedance will affect the voltage reading.

If the input voltage strays outside -12 to +12, the output will stray outside 0 - 5V, but that will be clamped by the input diodes on the PIC so it won't cause damage, unless the voltages are huge, as the 10k:eek:hm: will limit the current.

Yes, check my PIC tutorial hardware, where I use a buffer (for all the reasoons above), plus a resistor feeding the PIC input, to limit current in case of excessive input voltage.
 
Nigel Goodwin said:
Funny?, I don't remember my multimeter puts out a voltage to the circuit on a volts range? - I hardly thin it's "what you want", and certainly not what I want.

The low part isn't for the PIC, but for the sorce, too low an impedance will affect the voltage reading.

Sorry, I misunderstood which way you were looking at it. Yes, the simple resisitor circuit puts out a voltage that will be seen by the ±12V source. A practical effect of that is that it will not read mid-scale if the input is disconnected.

Also the input impedance is quite small for some sources.

I assumed, maybe wrongly, that the ±12V source was already buffered to give that scale.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top