Menu

Tier 4 Practical Application


Storing the Inhibit Switch State using the MEMORY object

This example is provided as a practical application to the Tier 4 Application Video. It will illustrate an additional feature discussed in the video, which focuses on storing the inhibit switch state and preserving it across power cycles. The main elements which achieve this process are the objects MEMORY and TIMERCOUNTER (shown below in Figure 1-1), as well as implementing C-scripting to simplify the visual schematic (shown in Figure 1-3).

Objects
Figure 1-1

Download the attached file below and open the CANcreate project (Tier4-Generic-DemoRevised.ccs). Remember to import the CANcreate Image Pack by accessing Tools>Open Image Library>Import Image Pack, open the (Tier4-Generic-DemoRevised.cip) file, and refresh/reload the library.

Before running the simulator, remember to compile the C-script first by clicking Publish>Compile.

After running the simulator, the project should appear (as shown below in Figure 1-2), where the blue wires indicate integers and the green and black represent Boolean logic values true and false, respectively. The switch state BITMAP visible in Figure 1-2 corresponds to the green wire coming out of the DECODER object (value 0). When it is clicked, it will switch to the DECODER output value 1 to show a highlighted white border instead of red, and a “HOLD 3 SECONDS” message will be displayed (as the TCH_REGION is released it will switch back to the red border BITMAP and the display message will be cleared.) Notice the contents (highlighted in yellow in Figure 1-2) as the cursor hovers the different colored wires (specifically, the blue wires connected to the MEMORY object are both 0.) When the TCH_REGION is held for at least 3 seconds, the display message will be cleared and the inhibit switch state BITMAPS will appear (DECODER output values 2 and 3). Also notice that the blue wires connected to the MEMORY object are now both 1.

Figure 1-2

To view the C-script, go to View>Code Script.
Alternatively, a code editor can be used to produce an external script (as illustrated in Figure 1-3). The code script file should then be imported by clickingView>Design Properties>Browse while enabling ‘Auto import external script on compile’.

The code below (in Figure 1-3) consists of three functions, Init () , Update(), and bmp_value() .

Tier4-Generic-DemoRevised
Figure 1-3

The Init() function is only called when the circuit is first loaded. It must be called again on a power cycle from the Update() function. The Init() function initializes the circuit into a smart initial state, where the state of the inhibitor is loaded first from memory since it is reset to 0 on a new power cycle. HOLD_MSG is set to 0, assuming the button is not being held down, and COUNTER_RESET is set to 1, assuming that when the button is being held down, the 3 second timer will be restarted.

The Update() function will pulse a RESET when the system has been rebooted. It then needs to be properly initialized. If the TCH_REGION is being touched, the counter will not be reset (otherwise, the counter will be reset, the inhibit state will not be saved, the HOLD_MSG will be cleared, and the flashing state will be false). If the flashing state is false, the counter will increment until 3 seconds have passed. After 3 seconds, the HOLD_MSG will be removed, the flashing state will be true, and the inhibit state will be changed (if it hasn’t been 3 seconds, the HOLD_MSG will still be visible). After 3 seconds of holding the button down, the inhibit state will be saved to memory for a restore on a power cycle. Lastly, the Bitmap value will be determined from the bmp_value() function and will return a value of 0,1,2, or 3.

The bmp_value() function will return a value depending on the bitmap corresponding to the inhibit state. The value will switch between 0 and 1, or 2 and 3, after the 3 seconds (while the button is still being held down).
When 0, the inhibit state is off.
When 1, the inhibit state is off and the THC_REGION is being held down for less than 3 seconds.
When 2, the inhibit state is on.
When 3, the inhibit state is on and the TCH_REGION is being held down for less than 3 seconds.