View Full Version : Comparing different types of variables
The Master
- 11th October 2008, 17:27
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?
skimask
- 11th October 2008, 17:49
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...
The Master
- 11th October 2008, 18:08
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
The Master
- 11th October 2008, 18:36
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
cServoOffTime con 255
pServo1 var PORTA.3
vServo1Pos var WORD
In the interrupt handler for TMR0 i have this 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
skimask
- 12th October 2008, 02:48
Don't know if it'll make ANY difference at all but...
if vservo1pos => cservoofftime then
pServo1=1
vservo1pos=0
endif
The Master
- 12th October 2008, 04:06
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
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
skimask
- 12th October 2008, 04:39
What happens if you do this:
cServoOffTime var WORD
cServoOffTime = 255
pServo1 var PORTA.3
vServo1Pos var WORD
.................................................. ..........
if vservo1pos>=cservoofftime then
pServo1=1
vservo1pos=0
endif
skimask
- 12th October 2008, 04:41
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...
The Master
- 12th October 2008, 12:27
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
The Master
- 12th October 2008, 12:53
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
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.