Negative Numbers/Virtual Ground


Closed Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Mar 2005
    Posts
    37

    Unhappy Negative Numbers/Virtual Ground

    I am currently reading an AD595 thermocouple amplifier with a PC12F675 and everything works great! I now want to read below 32F or 0C. I have added a negative power supply to allow the negative readings from the AD595. I have also added a voltage divider to the ground reference to scale all readings by say 55mv +/-. I am using GPIO.0 and GPIO.1 to monitor both then in my code I subtract the virtual ground from the AD595 reading.

    How do I handle the following in PBP for when I go below 0?

    loop:
    for sample = 1 to 20 ' 20 Samples then produce results
    ADCON0.1 = 1
    notdone:
    IF ADCON0.1 = 1 Then notdone
    adval.highbyte = ADRESH
    adval.lowbyte = ADRESL
    samples = samples + adval
    next sample
    adval = samples / 20

    ADCIN 1, virtual_ground

    if ((adval - virtual_ground) < 0) then
    ' Not Sure how to handle this
    else
    ' Not Sure how to handle this
    endif

    Thanks for any help!

    Scott

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Scott,

    If statements always assume that the number is positive. 0-65535 for words. &nbsp; So, &nbsp; "IF X < 0 then" &nbsp; will never return true.

    There are several ways to deal with it.

    One is to just see if virtual_ground is greater than adval. If it is then the subtraction will create a negative number so reverse the subtraction (virtual_ground - adval).

    Another is to just go ahead and do the subtraction then test bit15 to see if it ended up being a negative number or not. If it did, use ABS() to get the absolute value.

    1 more, subtract the two numbers and use the SDEC modifier for LCDOUT or SEROUT2 to display the negative number.

    If you need to do any multiplication or division with the result, then it can't be negative. Only add and subtract will work with negative numbers.
    <br>
    DT

Similar Threads

  1. A PIC logic 0V output is not equal to a ground?
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 17th November 2009, 18:47
  2. Connecting circuit ground to mains ground
    By The Master in forum Off Topic
    Replies: 2
    Last Post: - 12th November 2009, 22:02
  3. GROUND plane or nor GROUND plane
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 11th November 2008, 17:19
  4. Reading (ADC) negative current
    By sougata in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st November 2006, 17:38
  5. Grounding Negative voltage through I/O pin
    By Squibcakes in forum Schematics
    Replies: 2
    Last Post: - 31st July 2006, 12:12

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts