Neal,
The function, StepCountAbs(ch):
- Returns the current absolute position of the stepper system as a 32-bit signed integer
- The argument to the function, ch, is the stepper channel number, typically, 1..8.
- The absolute position for a stepper channel is reset to a value of 0 when the PLC is reset.
- The absolute position for a stepper channel is set to a value of 0 when the "StepHome ch" statement is executed.
- If you issue a StepMoveAbs or a StepMove that results in the stepper system moving, then this will affect the current absolute stepper position.
- If you call the StepCountAbs(ch) function while the stepper system is moving, you may get an intermediate value returned.
The function, StepCount(ch):
- Returns the current relative position of the stepper system as a 32-bit signed integer.
- The relative position is the number of steps that the system has moved since either the last motion command was executed or the PLC was reset the SetHome statement was executed.
- The argument to the function, ch, is the stepper channel number, typically, 1..8.
- The relative position for a stepper channel is set to a value of 0 when the PLC is reset.
- The relative position for a stepper channel is reset to a value of 0 when the "StepHome ch" statement is executed.
- If you issue a StepMoveAbs or a StepMove that results in the stepper system moving, then this will affect the current relative stepper position.
- If you call the StepCount(ch) function while the stepper system is moving, you may get an intermediate value returned.
OK what is the use of these commands? If you use the StepStop statement to abort a motion command, then the StepCount and StepCountAbs would allow you to determine the position of the system.
OK for your questions:
Q: Is this correct so far?
A: Yes. But, "DM[1] = STEPCOUNT(1)" is not an "equality" it is an "assignment" statement. Yes, I am being a bit anal, but you asked...
Q: Also, is the number that is returned 16 or 32 bit?
A: It is a 32-bit signed value.
I would suggest that you use DM32[] rather than DM[]. You have to be very careful with DM[] because it is a 16-bit signed value. TBASIC does all of its operations as 32-bits. 16-bit things are sign-extened (promoted) to 32-bit values before they are used in expressions. Assignments from TBASIC to 16 bit things will be truncated to 16-bits.
Truncating a 32-bit signed integer to 16 bits may result in both loss of magnitude and sign (positive or negativeness) . The 16-bit result may not be very useful...
Sign extending from 16 bit to 32-bit will result in the extra 16-bits being set to 0 or 1 values based on the 16-bit value's most significant bit. Nothing gets lost in this direction, but you can write TBASIC code that fails because you forgot about this 16/32 bit behavior.
This 16/32 bit stuff is just a statement of life with integer arithmetic. Be VERY careful with this. It WILL bite you in the butt if you are not careful. You have been warned.
Q: If it is, then why do I get Error : unknown keyword:"stepcount" (or "stepcountabs") every time I run Simulation or try to download my program?
A: I can't answer that because you didn't post your code. But my guess is that you screwed up the syntax. The following code runs fine in simulation:
DM32[1] = StepCount(1)
DM32[2] = StepCountAbs(1)
You are free to look at my posted code on how I use the stepper controller:
http://www.triplc.com/yabbse/index.php?board=1;action=display;threadid=2347Best regards,
Gary D*ckinson