Previous PageNext Page

OTHER BLOCKS

CMP - Compares Variables.

The CMP function compares the P1 and P2 inputs. LT is true when the P1 input is less than the P2 input. EQ is true when the P1 input equals the P2 input. GT is true when the P1 input is greater than the P2 input. The enable (EN) must be true for the CMP function to be enabled.

  1. We will now use the CMP function 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 CMP.
  7. Place the cursor on Rung 1 near the center of the ladder diagram workspace and left-click to place the object. The CMP is now placed.
  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. Select the DIRECT COIL button from the tool bar.
  11. Place the cursor on Rung 1 near the right power rail and left-click to place the contact. 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 coil that is tied directly to hardware input GPO0 (also named GPO0).
  12. With the DIRECT COIL still selected, place the cursor on Rung 2 near the right power rail and left-click to place the contact. The Coil properties dialog box will appear. Using the drop down menu in the dialog box, selct GPO1 and click OK. This finishes the placement of the coil that is tied directly to hardware input GPO1 (also named GPO1).
  13. With the DIRECT COIL still selected, place the cursor on Rung 3 near the right power rail and left-click to place the contact. The Coil properties dialog box will appear. Using the drop down menu in the dialog box, selct GPO2 and click OK. This finishes the placement of the coil that is tied directly to hardware input GPO2 (also named GPO2).
  14. Select the HORIZONTAL LINK tool.
  15. Draw a link from the right side of the GPI0 contact to the EN input on the CMP function.
  16. Draw a link from the LT output of CMP to the left side of the GPO0 coil.
  17. Draw a link from the EQ output of CMP to the left side of the GPO1 coil.
  18. Draw a link from the GT output of CMP to the left side of the GPO2 coil.
  19. We now need to insert variables to give the CMP its parameters and output. Select the INST VARS button from the tool bar.
  20. Place the cursor on Rung 2 just left of the P1 input on CMP. Left-click to insert the variable. The Variables dialog box will appear. Select the INTEGER tab.
  21. Click the ADD button to add a new variable. The Add variable dialog box will appear. Type Num1 for the Name, select INTERNAL as the variable type and set the DEFAULT VALUE to 5, then click OK.
  22. With the INST VARS still selected, place the cursor on Rung 3 just left of the P2 input on CMP. Left-click to insert the variable. The Variables dialog box will appear. Select the INTEGER tab.
  23. Click the ADD button to add a new variable. The Add variable dialog box will appear. Type Num2 for the Name, select INTERNAL as the variable type and set the DEFAULT VALUE to 10, then click OK.
  24. 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.
  25. 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:


  26. 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.
  27. Connect to the target, by selecting the CONNECT button from the tool bar. If a different program is running, just click OK.
  28. 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:


  29. Close the switch connected to Input 0. GPI0 is true causing power flow. The CMP function is now enabled. The LT output is true (GPO0 is true and is indicating power flow). The other two function outputs are false.
  30. Double-click on the Num1 Variable. A dialog box will appear that allows you to change the actual number value of Num1.
  31. Change the number to 10 and click OK. The EQ output is true (GPO1 is true and is indicating power flow). The other two function outputs are false.
  32. Double-click on the Num1 Variable. A dialog box will appear that allows you to change the actual number value of Num1.
  33. Change the number to 11 and click OK. The GT output is true (GPO2 is true and is indicating power flow). The other two function outputs are false.
  34. Open the switch connected to Input 0. All function outputs are false.

You have completed the CMP exercise.

  Previous PageNext Page