The objective of this tutorial is to explain how to use the CTD function block, which is a decremental counter, in a MasterTool X project.
Components
Equipment: 1 computer/notebook.
Software: MasterTool X
Tutorial Sections
- ARCHITECTURE
- DEVELOPMENT
1. ARCHITECTURE
A computer/notebook will be required to use MasterTool X.
Figure 1. Computer running MasterTool X
2. DEVELOPMENT
CTD Counter (Counter Down)
The CTD is a countdown counter. It is used when you want to decrement a value with each event until the counter reaches zero.
CTD Functionality
The CTD works as follows:
- With each rising edge on the CD input, the counter decrements the current value.
- The counter starts counting from the value configured in PV – Preset Value.
- When the counted value (CV – Current Value) reaches zero, the Q output is activated.
- The counter maintains the current value, even if the input returns to FALSE.
- The LD (Load) input reloads the PV value into CV.
The CTD does not count levels; it counts events (pulses).
Inserting the CTD into the logic
The CTD block is a function block, therefore it cannot be inserted directly as a contact or coil.
To add it to the logic:
- Open the Toolbox.
- Access Function Blocks.
- Select CTD.
- Drag the block to the Ladder logic.
Figure 2. Inserting the CTD block
Counter variable declaration (required)
Because it is a function block, the CTD requires an instance variable to store its internal state.
Example of naming convention:
ctd_0 : CTD;Important:
This rule applies to all function blocks in MasterTool IEC XE.
Without this variable, the counter will not function correctly.
Figure 3. Declaration of the CTD block variable
CTD Inputs and Outputs
The CTD block has the following variables:
Inputs
- CD (BOOL): Count input. Each rising edge decrements the counter.
- LOAD (BOOL): Load input. When TRUE, loads the PV value into CV.
- PV (INT / DINT): Preset value. Defines the initial count value.
PV can be configured with either a constant value or a variable, depending on the application's needs.
Outputs
- Q (BOOL): Becomes TRUE when CV = 0.
- CV (INT / DINT): Current count value.
Using Variables in CTD Parameters
- The input parameters (CD, LOAD, and PV) must be instantiated, as they feed the operation of the counter.
- The output parameters (Q and CV) do not necessarily require the creation of variables, since their values can be viewed directly in the block itself during the execution of the logic.
Creating variables for the outputs is optional and recommended when you want to reuse or monitor these values at other points in the program.
Using PV as a constant or variable
- PV as a constant:Ideal when the initial count value is fixed.
- PV as a variable: Allows changing the initial value at runtime, via logic or a variable table.
Figure 4. CTD Parameterization
Practical Application
After assembling the logic with the CTD:
- Download the application.
- Put the CPU in RUN mode.
- Trigger pulses on the CD input.
- Note:
- The CV value is decremented with each pulse.
- The Q output activates when CV reaches zero.
- Press LOAD to reload the PV value.
The CTD is widely used in applications requiring regression control, such as cycle limits, counting remaining operations, and quantity-based process control.
Figure 5. CTD Block Operation
Comments
0 comments
Please sign in to leave a comment.