negative value for a variable


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Location
    France
    Posts
    97

    Default negative value for a variable

    Hello
    I am in the process od sending datas to a serial PLL (MB88006)
    the register A should have a value between 0 and 63 ..
    as soon as this variable is out this range I must Increment or decrement another register (N)
    question :
    assuming variable A value is 0
    if I have the order
    A= A-1
    and after
    IF A < 0 then A = 63 : N = N - 1
    (for me A as the value -1 (minus 1) and the IF is working !)

    it seems NOT ...

    what is wrong on my side ?
    thanks
    Francois

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    instead of IF A < 0 then A = 63 : N = N - 1 that will not work, you should use:


    IF A.7 = 1 Then A = 63

    When A = 0 and you sutract 1 (A = A -1), A will overflow to 255. Since your count is limited to 63, you will never use bit 7 that can be used a flag.

    Al.
    All progress began with an idea

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default

    Hi,
    BYTES and WORDS are unsigned in PBP. So if A is a BYTE sized variable and has the value of the 0 then A=A-1 will result in A being 255 which isn't less than 0.....

    One way is to simply check the highest bit of A.
    Code:
    If A.7 THEN A=63
    That will tell you if A is < 0 (or >128) but since the maximum value for A is 63 it should work.

    HTH
    /Henrik.

    EDIT: A little late there but damn, that's two almost identical responses, almost scary....

  4. #4
    Join Date
    Jan 2005
    Location
    France
    Posts
    97


    Did you find this post helpful? Yes | No

    Default

    hello
    You are GREAT, and I was STUPID (I do not remember the sign or non signed variables value)
    IT WORKS, I use the Bit solution IF A.7 = 1 then xxxxx

    by the way , I am not very familar with the forum ..
    Last week I raised this question, and as far as I know, I didn't see any feedback
    here is my post

    Thanks for your message, but what do you mean by " Extended Instruction " ?

    bye the way, I have a problem, not the same but ...

    I try to use also the SHIFTOUT command to send data to a PLL (via Clock and Data pins)
    I use the mode (1 or 5) but the clock is always at HIGH level and there is just a DOWN pulse
    From the help explanation (clock idles high or low) my understanding was
    clock idles low .... clock signal is at LOW level and a positive pulse occur
    clock idles High ... clock signal is at HIGH level and a négative pulse occur
    as I said I try mode 1 or 5, and I see NO difference on the oscilloscope !

    any idea ?

    thanks
    Francois



    Originally Posted by awmt102
    UPDATE:

    PROBLEM SOLVED!

    In case anyone else has the problem I did - i.e. SHIFTOUT not generating any signals, here is how I solved it:

    I should have followed the three standard debugging rules when it comes to odd behaviour in PICs:

    1. Check the MCLR pin isn't held low (it wasn't)
    2. Check there is a clock signal (there was)
    3. Check the CONFIG bits - HERES THE PROBLEM!

    I went through all of the CONFIG options and discovered that with Extended Instruction Set enabled SHIFTOUT did not work, but as soon as it was disabled everything worked as expected!

    I guess the simulation doesn't differentiate between extended and non-extended and just works in either case.

    Hope this helps anyone who has the same problem.

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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