You are on page 1of 4

Control Techniques

Division of Nidec Motor Corporation


7078 Shady Oak Road
Eden Prairie, MN 55344-3505 USA
T: +1 952 995-8000
www.controltechniques.com

Programming
PowerTools Pro
Applications using
State Machine
Techniques

7078 Shady Oak Road, Eden Prairie, MN 55344-3505


+1 952 995-8000 www.controltechniques.com
1
Introduction

Most all programmable devices can benefit from using a State Machine programming technique. The
general concept of a State Machine is to structure the program so that it simply moves from one state
to the next, without the ability to move anywhere else.

Program flow is very easily tracked and documented, and race conditions in program logic can be
eliminated.

This application note show how a State Machine is programmed into a user program, where the master
axis, which contains the state machine program, issues Modbus Master commands to a slave axis.
While Modbus Master messaging is used in this example, any type of commands or machine control
can be sequenced with a State Machine.

This application note simply is intended to show the reader the State Machine techniques, it does not
detail how the Modbus message commands function, how user variables are configured or how the
program syntax functions.

Basic Setup
To understand our application example, a few screen shots are show below.

Map the Slave’s Modbus Parameter Configuration


The Y axis is the slave to the Modbus Master commands coming from the X axis. In order for the X axis
to know what Modbus messages to send to the Y axis, the Network view, Modbus RTU/TCP view of the
Y axis is shown here:

Explanation:
When the Y axis receives a binary one on Modbus register 1, the Y axis will initiate its home routine.

When the Y axis receives a status request on Modbus register 10001, the Y axis will return a 1 if the
AbsolutePositionValid register is true, or will return a 0 if false.

Now that the Y axis registers are mapped, the X axis can be programmed with the state machine.

7078 Shady Oak Road, Eden Prairie, MN 55344-3505


+1 952 995-8000 www.controltechniques.com
2
Program the State Machine
Below is a portion of the state machine code. To see how it operates assume the program has just
been started.
1. The variable var.MachState is set to 0
2. The program enters the Do While loop, if the Yaxis cam is not running
3. The program’s Switch/Case code is entered and executes Case 1.
4. The Modbus message command is loaded with the correct parameters to issues the Home
command to the Y axis.
5. The state machine then enters state 2 and execute Case 2 during the next program scan
6. Case 2 resets the home request and forces the state machine to state 3
7. Case 3 request the Home Complete status from the Y axis. Case 3 will continue to be called
every program scan until the Modbus slave device returns a 1 (in the bit.RWbitInst bit
register) and then State 4 will be entered. Because the messages can be issued very
quickly with each program scan, a time delay is inserted to slow the rate of communications
with the slave device.

7078 Shady Oak Road, Eden Prairie, MN 55344-3505


+1 952 995-8000 www.controltechniques.com
3
Notes

The program location and flow can easily be monitored by monitoring the var.MachState variable in the
watch window. A state machine can be forced into a particular state by simply using the watch window
and writing the desired value to the variable var.
MachState

The entire state machine program can be viewed in the PowerTools application files accompanying this
application note.

Resources: can be found on our website: www.controltechniques.com


For help contact techsupport.cta@mail.nidec.com, or
call Technical Support at 952-995-8000, 24/7/365

7078 Shady Oak Road, Eden Prairie, MN 55344-3505


+1 952 995-8000 www.controltechniques.com
4

You might also like