LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a standard and simple way of implementing a PLC like state machine with CVI?

Clever choosing of timers and appropriate callback functions should be much better than a succession of if statements in an endless loop.
I wish to control a pneumatic cilinders, lamps, etc, with a static digital I/O board.
Any good (or bad) experiences are welcome.
0 Kudos
Message 1 of 2
(2,998 Views)
I would recommend using a timer and set the interval for X milliseconds. The X will depend on the minimum time slice your application requires. Then within the timer call back function, have a simple switch statement that will serve as the backbone of your statemachine. Every time interval X, the state machine code will execute. A code snippet is below:
switch(State)
{
case 0:
if (temp > tempsetpoint + hysteresis/2)
{
State++;
}
else
{
DIG_Out_Line (1, 0, 0, 1); //Turn heater on
}
break;
case 1: //Turn heater off
if (temp < tempsetpoint - hysteresis/2)
{
State--;
}
else
{
DIG_Out_Line (1, 0, 0, 0); //Turn heater off
}
break;
default :
break;
}

For this example, the state machine approach is just used to control
the 2 on/off state of a heater, but this idea can easily be extended to control a much larger system. I hope this helps. Good luck.

-Steve
Message 2 of 2
(2,998 Views)