• No results found

Tutorial: Creating a Timer

This is a tutorial for creating a Timer. An alarm is set after a delay of a preset length of time.

Inputs are connected to an AND function. The output of the AND function is connected to the IN terminal of an on-delay (TON) function block. The TON function block delays setting the alarm by a Preset Time (PT).

When both inputs to the AND gate go true, the Output is true. The true output from the AND function to the IN input of the timer starts the Elapsed Time (ET). When the elapsed time reaches the time specified by the PT input, the output Q goes true, and the alarm is set. If at any time the input IN changes to false, the timer resets, changing Q to false, and the elapsed time is reset to zero.

You will:

• Create the logic as a Function Block Diagram

• Compile the program and correct any errors

• Test the program in the Emulator

Create Function Block Diagram

1 On the File menu, click New Project.

2 Select Tricon as the platform, and then click OK.

3 Enter Safe_Test as the filename of the project. Click Save.

The libraries are attached to the project and the Application workspace is displayed.

Create a New Program

1 In the Application tree, right-click User Documents, and then click New Document.

The New Document screen is displayed.

2 Enter Timer for the filename. Keep the defaults: Program, Function Block Diagram, and Control. Click OK.

The Application tree displays the timer function under the Programs folder.

Setup Worksheet

1 On the Sheets menu, click Select Sheet Template.

2 Click SheetTemplateA, and then click OK.

3 On the Project menu, click Project Options.

The Project Options screen displays.

4 Click the Annotation tab. Check Annotation on by Default and Monitor Value on by Default, and then click OK.

5 On the Document menu, click Properties. The Document Properties screen is displayed.

6 Click the Attributes tab. Check Enable color monitoring in program documents, and then click OK.

Place the AND Function on Logic Sheet

1 Click the Select Function (Block) Tool button on the toolbar. The Select Element screen is displayed.

2 In the Find field, enter AND, and then click OK.

3 Move the pointer to the logic sheet. The pointer changes to the function graphic. Click once to place the function on the logic sheet.

4 Double-click the AND function. The Item Properties screen is displayed.

5 Check Double-space. This increases the size of the element on the sheet, which makes it easier to connect variables. Close the Item Properties screen.

Place Tagnames on Logic Sheet

1 Click the Tagname Tool button and move the pointer to the logic sheet. Connect it to the top input terminal of the AND function by clicking once.

2 Click the Tagname Tool button and move the pointer to the logic sheet. Connect it to the bottom input terminal of the AND function by clicking once.

3 Double-click the top tagname to display the Item Properties screen.

4 Enter Input_1 in the Variable Name field. Click Apply. The Declaration tab is displayed.

5 Enter SampleText in the Description field. Confirm BOOL as the Data Type and Control as the Application Type. Click Apply, and then close the Declaration tab.

6 Double-click the second tagname to display the Properties screen.

7 Enter Input_2 in the Variable Name field. Click Apply. The Declaration tab is displayed.

8 Enter SampleText in the Description field. Click Apply, and then close the Declaration tab.

Place TON Function Block on Logic Sheet:

1 Click the Select Function (Block) Tool button on the toolbar. The Select Element screen is displayed.

2 In the Find field, enter TON, and then click OK.

3 Place the TON function block on the logic sheet to the right of the AND function.

4 Double-click TON to display the Item Properties screen.

5 Enter TON_1 the Instance Name field. Click Apply.

6 Check Double Space, and then close the Item Properties screen.

7 Connect the output terminal of the AND function to the IN input terminal of the TON function block by drawing a line between the terminals.

Place Variables on Logic Sheet

1 Click the Local Variable Tool button and connect the variable to the PT (Preset Value) input of the TON function block.

2 Double-click the local variable to display the Item Properties screen.

3 Enter Preset_Time in the Variable Name field. Click Apply. The Declaration tab is displayed.

4 Select Time as the Data Type. Enter T#5000ms in the Initial Value field. This is the standard syntax for 5000 milliseconds. Click Apply and then close the Item Properties screen.

5 Click the Local Variable tool button and connect the variable to the ET (Elapsed Time) terminal of the TON function block.

6 Double-click the local variable to display the Item Properties screen.

7 Enter Elapsed_Time in the Variable Name field. Click Apply and then close the Item Properties screen.

8 Click the Tagname Tool button and connect the variable to the Q output terminal on the TON function block.

9 Double-click the tagname to display the Item Properties screen.

10 Enter Alarm in the Variable Name field. Click Apply. The Declarations tab is displayed.

11 You may enter text in the Description field. Confirm BOOL as the Data Type and Control as the Application Type. Then close the Item Properties screen.

You have completed the logic for the Timer program.

Compile the Program

1 Click Compile button .

2 Click OK to save the changes. The Comments for Audit Trail screen is displayed.

3 You may enter text for the audit trail. Click OK.

The program is compiled and the results are displayed in the Message bar at the bottom of the screen.

4 Verify there are no errors or warnings in the Message bar. If there are errors, click on the text of the message to find the location of the error. Then make the necessary corrections and compile the program again.

Specify Program Execution

1 On the Application tree, double-click Implementation. The Execution List is displayed.

2 On the Program Execution List toolbar, click the New Insert button .

3 Click the Browse Button to display the list of programs in this project.

4 Click Timer to add it to the Execution List.

Test Program Logic in Emulator Panel

1 Close the program window (not the project) before connecting to the Emulator Panel.

2 Click the Controller tab at the bottom of the Application screen.

3 Double-click Emulator Panel.

4 Click the Connect button . 5 Click the Download All button .

6 Click Yes to the Download All query. The system builds the application and displays status information in the Message Bar.

7 Click the Run button .

8 Click Yes to run application.

9 On the Emulator tree, double-click Programs to expand it, and then click Timer.

10 Click the Display Program Document button to display the program.

Forcing Points

1 On the emulator program display, double-click Input_1. The Item Properties screen is displayed.

2 In the Item Properties screen, change the Set Value Input to True. Click Confirm and close the screen.

3 On the emulator program display, double-click Input_2. In the Item Properties screen, change the Set Value Input to True. Click Confirm and close the screen.

The change in input sets the alarm.

4 Close the Emulator Panel.

2

Related documents