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

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Al,
    0.7uH may give a problem at UHF, but not on your PSU.:rolleyes:

    Another option, would be to put two 0.1R's in parallel, so you will only see a 0.05V drop at 1 amp.
    Thats what I would do, a drop from say 5.00v to 4.95v on full load is insignificant.

    I have two LM358 on the shelf if we need to debug any problems on the Vadc.

    E.
     
  2. bigal_scorpio

    bigal_scorpio Active Member

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

    I could use 2 0.1r but they are the cement block ones and I would then need another 2 for the other side(var+) and I only have 2 and if I ever build one for the neg volts I would have to get a bigger case hehehe.

    The one I made is of about 16 guage winding wire and will never even become warm at 1A and its tiny! And I can make more easily! Some time ago I built a small resistance meter that is pretty accurate down to about 0.01 as luck has it, so Ihave no problem making the 0.01s unless the 0.05 would be better for some reason.

    I will be led by you in this.

    I now have the code working for choosing the display, any one of the four I want at the click of a switch. :)

    One question you may be able to answer though with your previous ownership of an electronics company is do you know of a rotary switch with 4 positions that has the positions at 90 degrees apart rather than the ones I have which are all about 10 degrees per click?

    BTW I have implemented the rail switches you suggested but had to put the switches on the rear, but so long as I know where they are, to coin a quote, thats good enough!

    Al
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
  4. dave

    Dave New Member

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


     
  5. bigal_scorpio

    bigal_scorpio Active Member

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

    Hi Eric,

    I mentioned what I was looking for to the wife and she is really good at finding things on the net.

    She has since found and purchased one for the princely sum of 1.98. :)

    If you ever need anything finding mate I will give her a nudge. Maybe its because she is an ex librarian eh?

    Thanks for looking though mate.

    Al
     
  6. bigal_scorpio

    bigal_scorpio Active Member

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

    Did you do a mock up of the OPA?

    Hope you are ok mate, you've been quiet for a day or so?

    Al
     
  7. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Al,
    No I didn't do the build, I thought all was OK at your end, is there a problem.??

    I am fine thanks.

    E.
     
  8. bigal_scorpio

    bigal_scorpio Active Member

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

    Still can't get a sensible reading from the OPA from the 5v current. Circuit is as your schematic as far as I can tell.

    Can you give it a try on breadboard or smonething just to see if its something I'm doing wrong mate?

    Al
     
  9. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Al,
    Will do that tomorrow, let you know

    Whats the problem with the readings? , so that I can compare.

    E.
     
  10. bigal_scorpio

    bigal_scorpio Active Member

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

    The reading just doesn't vary apart from going up a point when load is off.

    Al
     
  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Al,
    These are my results of today.
    My 5V has maximum current output of 0.5A, I dont have have a 0.01R so I had to use a 0.1R.

    The circuit I used and results are in this image, it looks OK to me. This was mainly to check out that the LM358 would be ok, it is.;)

    I will have to wind a 0.01R and use a different 5V source if you still have problems.

    E.
    OT:
    It will be next week before I can complete all the tests.
    Visiting my Bro in Rotherham this weekend, he is seriously ill with leukaemia, so I dont think I can pop in to see you.
     
    Last edited: Jul 12, 2012
  12. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Al,
    Done some more testing and managed to reproduce your problem.

    At switch ON the current charging the output cap is sufficient to drive the Vadc over 5V, this causes the OPA and transistor to go into a latched mode holding the Vadc close to 5V.

    As a test, make the 2N3904 emitter resistor 10K and retest the Vadc out for various load currents.

    I will try to work out a permanent solution.

    The problem occurs whatever the OPA type is.

    E.

    Before you make any changes please let me know what actual Vadc is at 0amp and 1amp output.
     
  13. bigal_scorpio

    bigal_scorpio Active Member

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

    Very sorry to hear about your brother mate, but if you need anything at all while you are here just give me a call.

    I think you have my number, if not then I will pm it to you.

    BTW the ADC at 1A load is 4.8 and rises to 4.9 at no load.

    Anyway give my best wishes to your brother if I don't see you when you come and remember I owe you big time so if you need me I will be there.

    Al
     
  14. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Al,
    That highlighted text of yours is the fault being seen by me also, leave it with me I will work out a fix it.

    Thanks for the kind words, much appreciated
    I hope the weather improves for the drive up.:(

    Eric
     
  15. circuitspecialists

    circuitspecialists New Member

    Joined:
    Jun 7, 2012
    Messages:
    47
    Likes:
    3
    Location:
    Mesa, AZ
    What is the range of values that you are trying to mesure? One option is to run the PIC "upside down"....connect the VDD terminal to GND and connect VSS terminal to a
    negative 5 volt power. Now all inputs and outputs to the PIC will be negative with respect to GND. If you can't do this (due to other circuit constraints) then you will need
    to provide a negative power supply for your op amp circuit.
     
  16. bigal_scorpio

    bigal_scorpio Active Member

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

    We solved the problem with reading negative volts mate using an OPA that Eric designed on page 2 of this thread. The present problem is now trying to measure the load current on the +5v and Variable +v rails.

    Eric has designed a circuit for this but at the moment it has just a slight hitch somewhere. Again this is an OPA circuit. Just teething problems, especially when the designer has to do it without the working circuit.

    Al
     
  17. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Al,

    Try this quick fix, connect a 5.6V zener across the 2N3904 Base to 0V as shown in this image.

    I will try it in hardware later today.

    I would recommend that you adjust the Vadc 25kpot to give a 2.48V change for 0mA to 1Amp.
    The Vadc is ~0.4V at 0mA and 2.88V at 1Amp, so in the program subtract this 0.4V offset count from the ADC value. So at 0mA the count will be 0 and at 1Amp the count will be 500.

    If you multiply the value by 2, the count will be 1000 for 1Amp, giving a resolution of 2mA per count.

    If you want a 1mA per count you could use a +Vref of 2.5V

    Try the fix and let me know the result.
    E
     
    Last edited: Jul 13, 2012
  18. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Al,
    Tried in hardware the 5V6 zener mod, it works fine for voltages from 0V thru 3.5v.

    So I would recommend setting the Vadc at 2.44V [ADC count of 500 decimal] for an output current of 1Amp,this will give a 2mA/bit resolution.

    For 1mA/bit resolution use a ADC +Vref of 2.5V, to give 1000 ADC counts

    E
     
    Last edited: Jul 13, 2012
  19. bigal_scorpio

    bigal_scorpio Active Member

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

    Just got back in so I will try this out now.

    I can't use a vref now, I have removed the 4096 one I planned on and realised anyway that the vref would steal one of my channels for ADC s I will have to stick with the internal.

    A question. When I have this one working ok I will be doing the same on the +variable. Will the same setup again be ok and will it be ok to run the new OPA from the same 18v zener supply?

    Saying that I wonder if it would be better to start again and use a new 358 for just both current circuits, it could simplify the board a little I suppose?

    Just another quick question that I can't find the answer to in the datasheet. This is for next times project. I was wondering if you can go above the Vref if it is external at say 2.5 and have an input of 5v which is within the PICs spec?

    The datasheet does not make this clear.

    Al
     
    Last edited: Jul 13, 2012
  20. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Al,
    The 18V zener should be ok for both LM358's, add another capacitor across the zener ,say a 10uF or close.

    You can use both halves of the LM358 for those functions, but as you say it would be neater and simpler.

    I have used a 2.5Vref and the Vadc has exceeded 2.5V, all that happens is that the count limits at 1023.

    E
     
  21. bigal_scorpio

    bigal_scorpio Active Member

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

    Just had another setback! What I thought was 0.01r was obviously nowhere near. I measured drop across it and its virtually nothing even with the 1A load.

    I will have to revert to the 0.1r at least with that I get a readable drop and it seems usable.
    At 1030mA i get 105.0mV across the 0.1
    At 108mA I get 10.5 across it so its fairly linear too and not so bad for the small readings. I can't forsee needind readings below about 5mA or above 1000ish so it may have to make do.

    It does however mean my low resistance meter is all but useless! It seems all below .5r read as .01 DOH!

    So can we revert to the .1 easily?

    Al
     

Share This Page