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.

Measuring negative voltages with a PIC

Status
Not open for further replies.

bigal_scorpio

Active Member
Hi to all,

I just realised that the PIC datasheets say that a negative voltage cannot be measured and unfortunately thats what I need to do!

I have seen one answer that uses an op-amp to invert the voltagebefore the PIC but I can't seem to do it in practice. The circuit I saw didn't mention a particular op-amp so I just looked at the specs of the ones I have and chose one that said it would work on 3 to 5v supply.

I set up the circuit on breadboard and it did seem to invert the voltage but not on a volt for volt basis When the negative voltage is varied from 0 to -5v all I see on the output is about + 4.26 v which seemed to hold steady at that and not mirror the variation in negative volts at all.

I am not at all sure about op-amps so if anyone can point me at a simple circuit or tell me that a particular one is good for my needs I would be grateful.

Thanks Al
 
If you choose an opamp that accepts input voltages including ground, then a simple inverting amplifier configuration with +ve input to ground should be fine.
 
You're needing an offset as reference. Somebody can answer this Way better than me... <<<)))
Why would you need an offset if the input range includes 0V?

You should be able to use opamps like LM358 or LM324, or there are plenty of CMOS rail-rail opamps you can use
 
You can use a 2 resistor voltage divider connected to +5v Vdd, with the bottom of it connected to the -ve voltage you are measuring. The rest is done in software. :)
 
Hi Guys,

From what I read the circuit below should convert my negative voltage to a positive one with 0 gain?

But all I get at the output is 4.22v positive which doe not change at all when I vary the neg volts in.
EDIT the voltage does drop slightly to 4.16 when the input is at its lowest - about -.04v.
Any suggestions as to why this doesn't work?

Al
 
Last edited:
You can use a 2 resistor voltage divider connected to +5v Vdd, with the bottom of it connected to the -ve voltage you are measuring. The rest is done in software. :)

Hi Roman,

I'm not following that at all mate? How does connecting the +5 do the trick?

Sorry if this is a daft question but I've been up all night, sleeplessness again!

Edit: I don't mean that your suggestion is not right, just that at this stage I need yo to draw it out so I can understand it.

Al
 
Last edited:
Look at **broken link removed** It has information on the different configurations of OpAmps used to condition signals. http://ww1.microchip.com/downloads/en/appnotes/00990a.pdf from Microchip is also useful.

Something like the AD820 or MCP601/MCP6001 should work in an inverting application.

Hi mate,

Sorry but I got stuck on the first equation on that link! Math is not my forte and I have never seen the | sign used before as in R3 = R1 | R2 does it mean divide?

Must be something I missed in school or maybe the lack of sleep is causing me to hallucinate! ;)

Many of the designs I have seen seem to omit R3 and connect the +in pin to 0v, which is right?

Al
 
Hi Roman,

I'm not following that at all mate? How does connecting the +5 do the trick?

Sorry if this is a daft question but I've been up all night, sleeplessness again!

Al

Its basically the same as measuring voltages HIGHER than 5V.... Imagine a 18v input.... Two resistors bring the voltage levels to a value between 0 - 5v.... Well!! just do it the other way round. two resistors from the 5v rail down....
 
Morning Al,
Is this for your the new PSU that you are building,? , if yes, I guess you are wanting to display -1.25V thru -15V, using the PIC's ADC.

Lets know if this is the case.

E.
 
Hi guys,

Roman and Ian,

I think I see what you mean. So with my neg15v I would need the large res to the neg side and the small one to the pos5v, but won't that give me a 0 to 10 scaled down?

Need sleep! ;)

Al
 
Morning Al,
Is this for your the new PSU that you are building,? , if yes, I guess you are wanting to display -1.25V thru -15V, using the PIC's ADC.

Lets know if this is the case.

E.

Morning Eric,

Yes mate thats it!

Al
 
Hi guys,

Just to say I'm using a precision 4.096 voltage reg on +v ref in on the 16F872

Al
 
Hi guys,

Just to say I'm using a precision 4.096 voltage reg on +v ref in on the 16F872

Al

Hi Al,
I would not use a 4.096Vref [ which I would normally use on a 12Bit ADC], the PIC is only a 10Bit ADC. The internal Vref should be fine for the PSU you are building.

The resistor divider for the -1.25V thru -15V works OK when used to measure the low resistance outputs of your PSU.

But if you plan to use the divider to measure other voltages you could have problems if the source resistance of the voltage you measuring is higher than a few tens of ohms.

This circuit shows an OPA option.
E.
 
Last edited:
Hi guys,

I get it now. I only plan to measure the actual voltage present so the divider will do. The only problem I have now is that the inverted voltage is inversly proportional to the actual voltage. I'm affraid thats another thing that has me stumped.

If it is difficult to do the math in basic would it be better to go with the setup Eric suggested with the op-amp?

I have been studying op-amps and got nowhere with them. I now understand the circuits for them a little but for the life of me I can't figure out the specs of them in the datasheets! There is so much info for what seems like a simple item. Why can't they tell me in plain English what the actual voltage required to run them is?

Anyway I shall await your replies and try to do the simplest option.

Al

BTW did anyone else find the site down yesterday? I didn't manage to get on till just after midnight (wednesday a.m)
Al
 
Last edited:
If it is difficult to do the math in basic would it be better to go with the setup Eric suggested with the op-amp?

Hi Al,
You could subtract the measured count of the ADC from 1024 to make the count values proportional to the negative voltage.

The site was down for hours yesterday. no idea why yet.

Eric
 
From what I read the circuit below should convert my negative voltage to a positive one with 0 gain?

Wow, LM741; really? That is like the dinosaur of OpAmps :)

If you must use that; it does not work out of a +0V rail. So you need bipolar supplies - and they need to be higher than +5V most likely because that amp has nasty rail capability. You're using a Bettle to run the Indy500. To use that you will need like +10V / -10V on the supply rails. My recommendation; step into the 21st century and use something designed to work on single supply rails and down to +3V or +5V supply rails. You've been given some example parts - and the 741 was not among them. Get a copy of LTSpice and use it along with the apnotes mentioned above and some other googling to learn (at least in principle) how OpAmps work. These are very basic building blocks - right after the diodes and transistors.

In summary; the circuit you show should work - but only if you use the right parts (again; you can't expect a VW Bettle to win the Indy500).
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top