Previous PageNext Page

COUNTERS

CTU- Up Counter
The CTU function is a programmable up counter. A true on CU will cause the counter to increment by one. Once the counter (CV) equals the preset value (CV), the Q output will be true. A true on reset (R) will cause the counter reset to zero and reset the Q output. The down counter triggers on a false to true transition on the CU input.
  1. We will now use the CTU in a ladder diagram.
  2. Place EZ LADDER® in the Edit mode (if in the Monitor mode).
  3. Close any currently open ladder diagrams (save them if necessary).
  4. Create a NEW ladder diagram Project.
  5. Configure the target as follows: (if you use a different target, some of the features may not be available)
    1. PLC on a Chip, Model PLCHIP-M2-25631
    2. Install Digital Inputs : GPI0 - GPI7
    3. Install Digital Outputs : GPO0 - GPO7
    4. Install Analog Block Analog Block 0
    5. Install the Real Time Clock
    6. Install the SSI Bus
  6. Using the Insert Function drop down menu on the tool bar, select CTU or use the CTU button on the tool bar.
  7. Place the cursor on Rung 1 near the center of the ladder diagram workspace and left-click to place the object. The Function Block properties dialog box will appear. Keep the name CTU1 and leave the description blank (The name field allows you to set any name for the function while the description allows you to set a text description of what the function is used for). Click OK. The CTU1 is now placed on rung 1.
  8. Select the DIRECT CONTACT button from the tool bar.
  9. Place the cursor on Rung 1 near the left power rail and left-click to place the contact. The Contact properties dialog box will appear. Using the drop down menu in the dialog box, selct GPI0 and click OK. This finishes the placement of the contact that is tied directly to hardware input GPI0 (also named GPI0).
  10. With the DIRECT CONTACT still selected, place the cursor on Rung 2 near the left power rail and left-click to place the contact. The Contact properties dialog box will appear. Using the drop down menu in the dialog box, selct GPI1 and click OK. This finishes the placement of the contact that is tied directly to hardware input GPI1 (also named GPI1).
  11. Select the DIRECT COIL button from the tool bar.
  12. Place the cursor on Rung 1 near the right power rail and left-click to place the coil. The Coil properties dialog box will appear. Using the drop down menu in the dialog box, selct GPO0 and click OK. This finishes the placement of the contact that is tied directly to hardware output GPO0 (also named GPO0).
  13. Select the HORIZONTAL LINK tool.
  14. Draw a link from the right side of the GPI0 contact to the CU of CTU1.
  15. Draw a link from the right side of the GPI1 contact to the R of CTU1.
  16. Draw a link from the Q output of CTU1 to the left side of the GPO0 coil.
  17. We now need to insert variables to give the CTU1 setpoints. Select the INST VARS button from the tool bar.
  18. Place the cursor on Rung 3 just left of the PV (preset value) input on CTU1. Left-click to insert the variable. The Variables dialog box will appear (the only tab available will be the INTEGER tab) since this is connecting to a counter.
  19. Click the ADD button to add a new variable. The Add variable dialog box will appear. Type CNTA for the Name, select INTERNAL as the variable type an enter 10 for the DEFAULT VALUE then click OK. This sets the variable connected to the counter's preset value to 10.
  20. With the INST VARS button still selected, place the cursor on Rung 3 just right of the CV (current value) output on CTU1. Left-click to insert the variable. The Variables dialog box will appear (the only tab available will be the INTEGER tab) since this is connecting to a counter.
  21. Click the ADD button to add a new variable. The Add variable dialog box will appear. Type CVal for the Name, select INTERNAL as the variable type an leave the DEFAULT VALUE blank, then click OK. This sets the variable connected to the counter's current value to this variable (which can be used to view the current counter value when running the program on the target).
  22. Save the ladder diagram from the File menu and selecting SAVE. It is a good idea to periodically save your ladder diagram when developing it.
  23. Compile the target using the COMPILE button from the tool bar. Ensure that the compile is successful and there are no errors. If there are errors they must be corrected. Your ladder diagram should look similar to this:


  24. We are now ready to run the program on the target. Switch to the Monitor mode by clicking the MON button from the tool bar.
  25. Connect to the target, by selecting the CONNECT button from the tool bar. If a different program is running, just click OK.
  26. Download the ladder diagram to the target by selecting the DOWNLOAD button from the tool bar. If successful, the ladder diagram is now operating on the target. It should look similar to:


  27. Momentarilly close the switch that is connected to Input 0 on the Development Board. GPI0 momentarily turns red indicating power flow and the CVal variable is now incremented (provided GPI1 is open). For each momentary closure of the GPI0 input, the counter value increases. When the counter value CVal is equal to the preset value (CNTA (10)), then GPO0 will turn red indicating power flow and the actual output will also be true.
  28. Close the switch to Input 1. The counter current value (CVal) is reset to zero and the output GPO0 is also now false or off.

You have completed the CTU exercise.

  Previous PageNext Page