Exact match. Not showing close matches.
PICList
Thread
'[SX] Negative back to positive angle'
2008\07\01@003719
by
TheBanditn/a
|
|
I am reading an incremental encoder to measure angle. Based on the encoder, I will INC or DEC a word I call "angle" representing the angle in tenths of degrees (3600 = 360 degrees). What I would like to happen is for the angle to switch from -999 to 2600 when decreasing and from 2600 to -999 when increasing.
I thought I could do this, but it only seems to work for increasing. When decreasing, the number just keeps decreasing.
angle VAR Word
IF angle=2601 THEN
angle=-999
ELSEIF angle=-1000 THEN
angle=2600
ENDIF
2008\07\01@043428 by bernoullin/a
|
|
Clint,
I do not have the answer for you as to why this is not working, but I have learned in using SX SIM on your code is that the compiler is taking your statement of "ELSEIF angle=-1000 THEN" and making it "ELSEIF angle=1000 THEN". Why the minus value is being made a positive value is something others will need to explain. I have checked the help file and see no numeric limits for the IF..THEN..ELSEIF..ENDIF command.
The VIEW LIST of the code for "angle=-1000" is:
182 0067 0C18 MOV angle_LSB,#(-1000 & 255) ; angle=-1000
0068 002D
183 0069 0CFC MOV angle_MSB,#(-1000 >> 8)
006A 002E
The VIEW LIST for the code of "ELSEIF angle=-1000 THEN" is:
196 007B 0CE8 CJNE angle_LSB,#1000 & 255,@__ELSE_2
007C 008D 0743 0010 0A8B
197 0080 0C03 CJNE angle_MSB,#1000 >> 8,@__ELSE_2
0081 008E 0743 0010 0A8B
I know someone will be able to help us better understand this.
Gary
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=276833#m276847
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)
2008\07\01@052002 by bernoullin/a
|
|
Clint,
As a workaround, define a CON such as TestLow, giving it a value of -1000. Then use that CON name in the IF..ENDIF area. This makes the program function as desired now, but does not explain my earlier observation.
TestLow CON -1000 angle VAR Word
START:
angle = -1000
MAIN:
IF angle = 2601 THEN
angle = -999
ELSEIF angle = TestLow THEN
angle = 2600
ENDIF
2008\07\01@182234 by TheBanditn/a
|
|
Gary - Thank you very much for giving this your attention. I will give your workaround a try :D For a second there, I thought I'd lost my marbles!
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=276833#m276993
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)
2008\07\08@202431 by TheBanditn/a
|
|
Well that worked okay, but then I realized I need a > or < to take care of situations where the angle skips over the limit (say I go from 2600 to 2610). Now it doesn't work again.
Here's what I'm trying
upperlimit CON 2600
lowerlimit CON -999
angle VAR Word 'angleIF absangle>upperlimit THEN
angle=angle-3600
ELSEIF angle<lowerlimit THEN
angle=angle+3600
ENDIF
Am I doing something wrong?---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=276833#m278334
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)
|
|
Clint,
WORD variables can only hold positive values. When you do a comparison to a negative value, the compiler takes the "two's complient" of the negative value, and uses that. This works fine for "=" and "<>", but it won't work for ">" or "<".
Bean.
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=276833#m278381
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)
More... (looser matching)
- Last day of these posts
- In 2008
, 2009 only
- Today
- New search...