1. 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.
    Dismiss Notice

Measuring negative voltages with a PIC

Discussion in 'Microcontrollers' started by bigal_scorpio, Jul 3, 2012.

  1. bigal_scorpio

    bigal_scorpio Active Member

    Joined:
    Oct 6, 2007
    Messages:
    1,072
    Likes:
    4
    Location:
    Rotherham South Yorkshire England
    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
     
  2. dougy83

    dougy83 Well-Known Member

    Joined:
    May 18, 2008
    Messages:
    2,672
    Likes:
    215
    Location:
    Brisbane, Australia
    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.
     
  3. OlPhart

    OlPhart Member

    Joined:
    Feb 22, 2011
    Messages:
    331
    Likes:
    8
    Location:
    SW Michigan (USA)
    You're needing an offset as reference. Somebody can answer this Way better than me... <<<)))
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. dougy83

    dougy83 Well-Known Member

    Joined:
    May 18, 2008
    Messages:
    2,672
    Likes:
    215
    Location:
    Brisbane, Australia

    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
     
  6. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    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. :)
     
  7. languer

    languer Active Member

    Joined:
    Oct 26, 2010
    Messages:
    193
    Likes:
    25
    Location:
    Arizona
  8. bigal_scorpio

    bigal_scorpio Active Member

    Joined:
    Oct 6, 2007
    Messages:
    1,072
    Likes:
    4
    Location:
    Rotherham South Yorkshire England
    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: Jul 4, 2012
  9. bigal_scorpio

    bigal_scorpio Active Member

    Joined:
    Oct 6, 2007
    Messages:
    1,072
    Likes:
    4
    Location:
    Rotherham South Yorkshire England
    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: Jul 4, 2012
  10. bigal_scorpio

    bigal_scorpio Active Member

    Joined:
    Oct 6, 2007
    Messages:
    1,072
    Likes:
    4
    Location:
    Rotherham South Yorkshire England
    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
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,148
    Likes:
    907
    Location:
    Rochdale UK
    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....
     
  12. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,178
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    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.
     
  13. bigal_scorpio

    bigal_scorpio Active Member

    Joined:
    Oct 6, 2007
    Messages:
    1,072
    Likes:
    4
    Location:
    Rotherham South Yorkshire England
    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
     
  14. bigal_scorpio

    bigal_scorpio Active Member

    Joined:
    Oct 6, 2007
    Messages:
    1,072
    Likes:
    4
    Location:
    Rotherham South Yorkshire England
    Morning Eric,

    Yes mate thats it!

    Al
     
  15. jjw

    jjw Member

    Joined:
    Apr 16, 2012
    Messages:
    257
    Likes:
    15
    Location:
    Helsinki, Finland
    --deleted--
     
    Last edited: Jul 4, 2012
  16. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,148
    Likes:
    907
    Location:
    Rochdale UK
    1k and 4k7 should do it. That will give you 4.8v at -125v and 1.5v at -15v

    EDIT..... missed your last post...... Go from the reference voltage then
     
    Last edited: Jul 4, 2012
  17. bigal_scorpio

    bigal_scorpio Active Member

    Joined:
    Oct 6, 2007
    Messages:
    1,072
    Likes:
    4
    Location:
    Rotherham South Yorkshire England
    Hi guys,

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

    Al
     
  18. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,178
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    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: Jul 4, 2012
  19. bigal_scorpio

    bigal_scorpio Active Member

    Joined:
    Oct 6, 2007
    Messages:
    1,072
    Likes:
    4
    Location:
    Rotherham South Yorkshire England
    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: Jul 4, 2012
  20. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,178
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    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
     
  21. languer

    languer Active Member

    Joined:
    Oct 26, 2010
    Messages:
    193
    Likes:
    25
    Location:
    Arizona
    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).
     

Share This Page