Mark,
I think what you really what to know is when is the stepper controller busy and when the stepper controller has completed a move operation.
Please note that the argument "r" in the step move command allows you to specify an internal PLC RELAY to set when the STEPMOVE has issued "count" pulses to the stepper channel specified by "ch".
STEPMOVE ch, count, r
The STEPMOVE and STEPMOVEABS statements are "non-blocking". These statements execute quickly and the TBASIC goes on to the next part of the program before any step pulses are issued. The actual movement of the stepper might take from a few milliseconds to a few millennia depending on number of steps in the "count" argument. You don't want the PLC hung up waiting for the stepper movement to complete.
For Stepper channel #1, I define a RELAY named Ch1CmdCmp and issue a stepper command like this:
StepMove 1,Ch1Arg1,Ch1CmdCmp
The RELAY named Ch1CmdCmp will be reset to 0 by the execution of the StepMove statement. The same RELAY will be set to 1 when the stepper motion has completed. So when the CH1CmpCmp RELAY is 1 then you can issue a new StepMove or StepMoveAbs command. When the CH1CmpCmp RELAY is 0 the CH1 stepper controller is busy moving the stepper.
There is a small issue with the StepMove and StepMoveAbs, and this is that if the count argument would result in no stepper pulses being issued (no motion) then the RELAY, "r", will be cleared but will not be set to 1. This is how I make the behavior of the RELAY consistent:
' The StepMove statement will not set the Ch1CmdCmp RELAY if the
' the statement will result in no physical motion of the stepper motor
'
' The fix is to execute the StepMove statement and then
' set the Ch1CmdCmp RELAY
'
StepMove 1,Ch1Arg1,Ch1CmdCmp
if (Ch1Arg1 = 0)
SetIO Ch1CmdCmp ' set the command completion RELAY
endif
' The StepMoveAbs statement will not set the Ch1CmdCmp RELAY if the
' statement will result in no stepper motion
'
' The fix is to test if the current absolute position is the same
' and the position specified in the argument to StepMoveAbs and after
' the StepMoveAbs statement is executed, set the Ch1CmdCmp RELAY to indicate
' that the statement completed
'
s = StepCountAbs(1) - Ch1Arg1 ' s is the distance to the new position
StepMoveAbs 1,Ch1Arg1,Ch1CmdCmp ' issue the stepper command
if (s = 0)
SetIO Ch1CmdCmp ' the Ch1CmdCmp Relay will not be set, so force it.
endif
I have posted a full up stepper motor test system on this forum. I have included documentation, PLC firmware as a .pc6 and firmware to support a the MT8050iE HMI that TRI offers on their website.
This code provides a full stepper test system for a single stepper. The PLC code is very small and very fast and uses all of the stepper commands. The code can be run without hardware with the simulator and if you have no HMI, you can run the code on real hardware using On-line monitoring. I think that I put hints in the documentation on these things.
Look for the topic: "Stepper Motor Demo Code".
The posting date was May 02, 2018, 03:10:38 PM.
http://www.triplc.com/yabbse/index.php?board=1;action=display;threadid=2347Best regards,
Gary D*ckinson
[Forum Editor's Note]: Have edited this post and removed the funny characters that were present in the original post.