Comparing different types of variables


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697

    Default Comparing different types of variables

    Hi, Im trying to compare a WORD with a BYTE. Should that work in PBP? Im using "=>". When the values are actually compared the WORD value is definately less than 256. When i compare 2 BYTE values it works fine but if i change one to a WORD then it stops working.

    Im not sure if the problem is with the comparison but it looks most likely. Does anyone know anything about it?

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Hi, Im trying to compare a WORD with a BYTE. Should that work in PBP? Im using "=>". When the values are actually compared the WORD value is definately less than 256. When i compare 2 BYTE values it works fine but if i change one to a WORD then it stops working.

    Im not sure if the problem is with the comparison but it looks most likely. Does anyone know anything about it?
    if word.lowbyte => bytevalue then xxxxxx
    or
    if word.highbyte => bytevalue then xxxxxx

    Don't know why it's not working for you in the first place. It should. Works for me anyways...

  3. #3
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Im sure its worked for me in the past too. I had already tried word.byte0/1 but i tried high/lowbyte too and still no luck. The problem i have is that the byte always seems to be less than the word. I just checked it with a status light on and aparently the byte is always 0 because no serial data arrives. The word doesnt have anything to do with serial so ive no idea whats happening there :S

    Ill see if i can figure it out. I know its not the compare code now

  4. #4
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Ive found where the problem is. I commented all the relative code out then turned it back on 1 line at a time until it broke again.

    At the top i have this code
    Code:
    cServoOffTime con 255
    pServo1 var PORTA.3
    vServo1Pos var WORD
    In the interrupt handler for TMR0 i have this code
    Code:
                    if vservo1pos>=cservoofftime then
                        
                        pServo1=1
                        vservo1pos=0
                    endif
    If i comment out the if statement (not the code in it, just if-then and endif) or i change vServo1Pos to a byte then it works fine. As it is above it stops any serial data from being received. I dont get how that could possibly affect it

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Don't know if it'll make ANY difference at all but...
    Code:
                    if vservo1pos  =>  cservoofftime then
                        pServo1=1
                        vservo1pos=0
                    endif

  6. #6
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Unfortunately not, I already tried that because some languages like PHP dont like it if you put them in the wrong order. PBP doesnt seem to mind though.

    Ive been testing a different line of code that does almost the same thing
    Code:
    if vservo1pos=>vservo1+12 then
    When i use that code i can send serial data fine for about 5 seconds then it stops. It looks similar to a problem i had the other day but that was because i wasnt resetting a variable back to 0 when i should have. This code shouldnt affect that variable at all though. The PIC doesnt stop running because it still generates the pulse

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    What happens if you do this:
    Code:
    cServoOffTime var WORD
    cServoOffTime = 255
    pServo1 var PORTA.3
    vServo1Pos var WORD
    ............................................................
                    if vservo1pos>=cservoofftime then
                        
                        pServo1=1
                        vservo1pos=0
                    endif

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    if vservo1pos=>vservo1+12 then
    If vservo1 ends up being greater than 65,524, then vservo1 + 12 = 65536, which in a WORD variable ends up equalling ZERO...

  9. #9
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    vServo1 is a byte and cant go above 255.

    I will try declaring cServoOffTime as a variable instead. I think something similar to this was the reason for my thread about the datatypes of constants

  10. #10
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    That doesnt seem to work either.

    I just tried removing the constant completely and putting the value into the middle of the code and that works :S. I dont like doing that but in this case i dont really have a choice. The only problem now is the other line. vServo1 gets set by data from the serial port so i cant write the value into the code

Similar Threads

  1. Max Variables
    By shawn in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th January 2008, 04:05
  2. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34
  3. Variables not appearing in Watch Window MPLabv7.3
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th June 2006, 14:36
  4. edit names of variables
    By mischl in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th January 2005, 21:00
  5. Problems with variables
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th December 2004, 18:37

Members who have read this thread : 1

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