Displaying negative numbers
Newzed
Posts: 2,503
I am trying to get my LCD to display negative numbers indicating the position of the X or Y drive on my MF70 mill.
I have the origin set at 0, 0.· If I stay to the right of 0, the display is correct.· I can move .400 left - display = .400 - then move right .100 and display = .300.· All OK so far.
However, if I am at origin and I move the table right .100, then the display says 65436 instead of -.100.
Position is calculated by 0 -· dis, where dis is the travel after a go right command execution, or by 0 + dis after a go left command execution.
I am using SDEC modifiers.
Any suggestions?
Sid
I have the origin set at 0, 0.· If I stay to the right of 0, the display is correct.· I can move .400 left - display = .400 - then move right .100 and display = .300.· All OK so far.
However, if I am at origin and I move the table right .100, then the display says 65436 instead of -.100.
Position is calculated by 0 -· dis, where dis is the travel after a go right command execution, or by 0 + dis after a go left command execution.
I am using SDEC modifiers.
Any suggestions?
Sid
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
This is the routine that calculates travel.· It is shown for just 360 degrees:
diffd = f
IF f = 360 THEN
dis = ABS diffd*/$0046 + 2
ENDIF
dis always = 1000
to display it on the LCD, I write:
SEROUT lcd, baud, 10, [noparse][[/noparse]"B", "Travel: ", SDEC dis/1000,".", DEC3 dis, " out", 13]
To calculate the total - or net - travel (disy) from origin - 0, 0 - I write:
disy = disy - dis
To display, I write:
SEROUT lcd, baud, 10, [noparse][[/noparse]"C", "Total travel: ", SDEC disy/1000,".",DEC3 disy, 13]
The LCD displays 65.436.
If I change the display instruction to:
SEROUT lcd, baud, 10, [noparse][[/noparse]"C", "Total travel: ", SDEC disy, 13]
the LCD displays -100.· I can put a dot in front of it and get .-100 but what I want the display to say is -.100.· I have no problems as long as disy is =>0.
Is this enough of the code?
Sid
·
Sid
· temp = ABS dis
· SEROUT Lcd, Baud, 10, [noparse][[/noparse]"B", "Travel: ", " " + (dis.BIT15 * 13), temp/1000, ".", DEC3 temp, " out", CR]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax