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,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi Al,

    A DS18B20 would be handy, I could send it back when I have finished playing, any bits on your wish list you would like that I might have on the shelf.??

    Eric
     
    Last edited: Jul 28, 2012
  2. bigal_scorpio

    bigal_scorpio Active Member

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

    I will send one on monday, yours to keep mate. Just wish I had more bits you needed, I owe you much more than one tiny IC after all the things you have sent me and helped me with.

    One bit of info on them though, there is a DS1820 and a DS18X20 and they are NOT compatible at all. I spent half a day once trying to get one to work only to discover the difference is not just a letter! ;)

    So now I look at them very carefully when I grab one from my box! hehehe

    Al

    On another tack, could I use the same sort of cap and zener setup as in the one that powers the OPAs to power the LEDs that show the rail is active. I realised when starting to implement the LEDs you suggested for the rail power that though the 5v one is simple enough, I would not be able to use the standard approach with the variable rails.

    So if its viable what combination of Zener and cap would you recommend? I have them starting from 2v. I would only require a few mA for the LEDs, they don't need to be bright.

    Al
     
    Last edited: Jul 28, 2012
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

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

    This is how I would do the Var LED's , fairly constant brightness, from 2V to 15V

    Any general purpose transistors will do.

    E
     
  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,

    Done and built! Works like a dream!

    Thanks again Eric.

    BTW the rain here has just started so I hope its ok down there for your paint.

    Al
     
  6. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

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

    Here is the modified hex program, als_psuV1.hex

    If its not spot on, I will wait for the DS18B20 before finalising.

    Do you have an unused half of a LM358 on your pcb's.??

    Eric
     
  7. bigal_scorpio

    bigal_scorpio Active Member

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

    Thanks for that mate, I will try it now.

    I would like a look at the basic i possible mate. I'm still trying to understand some of it and it may help if I can see the changes. :)

    As to the 358. Yes I do have a spare half mate. What do you have in mind?

    Also you still have me wondering why you asked about the serial port the other day?

    PS hope your painting went well.

    Al
     
  8. bigal_scorpio

    bigal_scorpio Active Member

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

    Just checked the hex and sadly no fan at all now. Still I'm surprised that you got it going at all without the actual sensor on hand.

    Anyway it should be with you by tuesday mate. Still intrigued by the serial though mate.

    Al
     
    Last edited: Jul 29, 2012
  9. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi Al,
    I found my error, I had decided to only sample the DS18B20 tempr at roughly 1 second intervals, so added a counter. I put the counter reset outside the loop... duh.:eek:

    Try this hex,, I have also attached the Basic.

    Ref the serial, I was going to suggest that you output the data on the PIC's UART to the PC, you could log your values.

    The AN4 is [Pos4] on the Mode sw, I have set it for 1000 adc counts = +20.00V.
    So you could use the spare LM358 as a buffer and voltage divider [20V to 4.888V] , in that way you could measure your project voltages.

    When I get the DS18B20 I will tidy up the program.
    Eric
     
    Last edited: Jul 30, 2012
  10. bigal_scorpio

    bigal_scorpio Active Member

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

    That has it sorted mate! Works fine now on any setting.

    I see the circuit is almost the same as the on for the neg volts measurement but this time not inverting.

    As it happens the way I did it was to use both amp measurements on one OPA and the other has just the neg voltage measurement on one side so its ideal for what you planned. :)

    The 18B20 is on its way mate, and by the way how did the fourth bridge go?

    Thanks, Al
     
  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi Al,
    Thats good news.

    If I have done my sums right, that Pos4 subr should work ok in your project when you add the LM358.
    As a test you could put 0V to 4.888V directly on that AN4 input pin and select Mode4, it should display about 0V to 5V [ dont try over 5V with the divider]

    Let you know when the DS arrives, still have not seen your components wish list.?

    OT: I am about 75% across the bridge.;)

    Eric
     
  12. bigal_scorpio

    bigal_scorpio Active Member

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

    I don't have a wish list but rather a DOH I don't have one of those and Craplins don't have them - list. Did you know that they had opened a shop at Parkgate retail park? Though it only has the odd bad of resistors and caps, its mainly the ready built Chinese electrical junk that everyone sells. Hey, I just realised that the Chinese used to have junks - now they just have the singular and send it over here! hehehe

    Rest assured mate I know that you would always help me if I didn't have a part and you did. :)
     
  13. bigal_scorpio

    bigal_scorpio Active Member

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

    Glad it arrived ok.

    I was thinking,(don't say "that's dangerous!" ;) ), but I wondered why have an OPA circuit at all for the probe?

    All I have for reading the positive volts from the supply is a potential divider, wouldn't that be ok to read the probe or is there a reason for using the OPA? Is it a protective measure?

    Al
     
  14. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi Al,
    Consider a typical simple resistive divider of say a 5k and a 5k.

    Say you used the divider to measure the Base voltage of a transistor, it would mean the Base would be loaded by 10K to 0V.

    As an example say the transistor had base biassing of 100K from the +Vs rail and 47K to 0V, as soon as you probed the Base the 10K of the divider would be in parallel with the 47K, so the voltage being measured would be pulled down and the reading would be incorrect.

    In the OPA version we can use high value resistors that will minimise the loaded of the circuit by the dividers 622k resistance.

    The PIC's ADC requires a source impedance of less than 10K, so the 622K would be well out of spec.

    The OPA output impedance is around 100R, the 1K in series with the output is there to limit the current into the PIC if the voltage input exceeds +5V
     
  15. bigal_scorpio

    bigal_scorpio Active Member

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

    Ah I see, all clear now. Didn't realise that measuring something would have that effect. I should have really as recently I saw a program on quantum physics that showed that even looking at some things changes the way they are and behave.

    Anyway one of the reasons I asked for was that I had built the circuit and for some reason I'm not getting anything out of it at all. I will go through it again with a fine toothed comb. :)

    OT: Hope the bridge is done mate?

    Al
     
  16. bigal_scorpio

    bigal_scorpio Active Member

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

    I have discovered that the problem lies with the Pic or program. I am getting a voltage difference from the4 OPA circuit but the AN4 setting on the PSU just shows around 7v regardless of the input from the OPA. It even shows this with it disconnected altogether.

    From what I can glean from your code, which is quite different from PBP I think that the AN4 is still trying to access the 18B20? If so then it makes sense that the reading would be wrong?

    BTW this is happening on both 16F872 pics that I have. I tried another as I thought that one might have a faulty pin.

    What do you think mate?

    Al
     
    Last edited: Aug 1, 2012
  17. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

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

    Are you using pin #7 of the PIC for AN4.??, thats for AN4 [ not pin6 as you would think]

    This DS18B20 you sent me is a DS18B20P [ parasitic mode only] , how is your working DS18B20 connected and is it a P .??

    Eric
     
  18. bigal_scorpio

    bigal_scorpio Active Member

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

    Sorry mate, I bought 4 of them and thought they were all alike. Looking at them with the jewellers eyepiece I can see that another is an 18B20P and the last is an 18B22. Pure chance that we got them working at all. Saying that doesn't the actual IC work the same but just derives its power from the data line?

    I am definately using pin 7 mate. I realised straight away when trying to figure out this project that the ANs have a gap for "tockI"! just like an IC maker to split up a set of pins like that! Why not put TockI on the next pin and have a row of 5 ADC pins? Planners eh! But the code below from yours seems to use AN4 for temperature if I read it right. Its from the latest build.

    Anyway sorry about the 18 mate, I honestly didn't realise there were any different ones.

    I will send you the 1822 mate, it works exactly the same as the 18B20. I know as I just swapped them around and it still shows exactly the same temp. Next time I buy from Ebay I will check more closely eh! ;)

    Al

    Code (text):
    Case 8
    ADCON0 = 69h  'Set AN3=4
    Gosub get_adc  '4.88v = 60000 counts
    tempr = avg_sum  '' 125C= [1000 counts * 2]

    tempr = tempr / 30  'adjust tempr for integer values only when setting
    b2avall = tempr.LB
    b2avalm = tempr.HB
    Gosub bin2asc
    Lcdcmdout LcdLine1Home
    Lcdout "AN4= "ascbfr3, ascbfr2, "."ascbfr1, ascbfr0, "V     "
    Lcdcmdout LcdLine2Clear
    Case Else
     
  19. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi Al,
    I will check the ADC addresses.
    E

    EDIT:

    The AN5 address should be 61h not 69h

    ADCON0 = 61h 'Set AN=4

    Can you use Oshonsoft to change it.? and recompile, if not I will post a new hex.

    E.

    BTW: do you have +5V connected to the DS18B20 power pin.??

    Checked my project board I am using a 16F877 PIC [dont have a 16F872] I had the AN4 wire in the next hole down!.
    Thats why it worked for me at addr 69h.
     
    Last edited: Aug 1, 2012
  20. bigal_scorpio

    bigal_scorpio Active Member

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

    I can't get the Oshonsoft running at all mate. So if you could recompile I would be grateful.

    Yes I do have 5v to the power pin mate.

    Al
     
  21. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    Ok I will post a new hex.

    I cannot get the DS18B20P working correctly, I can write and read to it, but the temperature is always the default power up value 85Cdeg

    The d/s states that a strong pull up using a MOSFET is required during the conversion cycle because the parasite power is inadequate.
    So without that I read the default tempr, anyway I will keep playing.

    Eric

    EDIT:
    Modified program.
     
    Last edited: Aug 1, 2012

Share This Page