Counter Problems
StevenG
Posts: 9
I'm sure someone has run into this problem before...
I am making a simple quadrature reader that reads the current position from the Parallax Position Controller Kit (#27906), calculates the number of "actual" units and sends it out the COM port. It does this once a second using a DS1302 time keeping chip to ensure that it is as consistent as possible.
The problem I am having is this... Going positive everything works beautifully. But going negative when DepthR crosses the zero line and goes to 65535 everything gets screwed up.
If anyone has some experience in this or a better way of doing it your help would be much appreciated!!
Code attached...
I am making a simple quadrature reader that reads the current position from the Parallax Position Controller Kit (#27906), calculates the number of "actual" units and sends it out the COM port. It does this once a second using a DS1302 time keeping chip to ensure that it is as consistent as possible.
The problem I am having is this... Going positive everything works beautifully. But going negative when DepthR crosses the zero line and goes to 65535 everything gets screwed up.
If anyone has some experience in this or a better way of doing it your help would be much appreciated!!
Code attached...
Comments
X = -1
IF ( X < 0 ) THEN
DEBUG "X is less than zero", CR ' This should print but doesn't
ENDIF
But this works
IF (X.BIT15 = 1) THEN
DEBUG "X's signed bit is set", CR ' This does print.
ENDIF
Now my code works, but directly testing the signed bit is awkward. Is there syntax in the first case that I'm missing?
I've had similar issue adding signed bytes to signed words, but worked around that by copying the byte to a word, sign extending it, and then adding the values.
I'm fine with that, but I wanted to make sure I wasn't missing some key language feature.
This is why "x=x-1 \\ 0" casues unreliable results.
I never did understand why it occasionally "lit all bits" and maxxed out insteadsof zeroing.
The signed word trips up the operation....
Thanks mike.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Before you criticize someone, walk a mile in his shoes. That way if he gets angry, he'll be a mile away and barefoot. - unknown