Configuration Example: 32-Bit Forward Counter¶
All of the 8 channels of the DC541-CM can be used as count-up counter. In the configuration example, all 8 channels of the DC541-CM are configured as 32 bit forward counter (count-up). The channels C0…C3 operate as infinite counters (endless mode), the channels C4…C7 as limit counters (limit mode).
The 32 bit count-up counter configured as infinite counter (endless mode) corresponds to mode 1 (1 Up counter) of the high-speed counter of the digital input/output modules. In the configuration example, the counting pulses for the first forward counter are therefore applied in parallel to input C0 of the DC541-CM and counting input C24 of the DC532.
Hardware configuration
The example control system shall have the following configuration:
- Terminal base TB521 (two Communication Module slots)
- DC541-CM in Communication Module slot 1 (first slot on the left of the CPU)
- PM591-ETH CPU with internal ETHERNET Communication Module
- I/O module DC532 on the I/O bus
Wiring
The channels are connected as follows:
- DC532 / C16 ————– DC541 / C0
- DC532 / C17 ————– DC541 / C1
- DC532 / C18 ————– DC541 / C2
- DC532 / C19 ————– DC541 / C3
- DC532 / C20 ————– DC541 / C4
- DC532 / C21 ————– DC541 / C5
- DC532 / C22 ————– DC541 / C6
- DC532 / C23 ————– DC541 / C7
- DC532 / C16 ————– DC532 / C24
PLC configuration
- DC541-CM in slot 1, operating mode “Counter mode”
- Configuration: - Channel C0..C7 Forward counter
- Specification of the ETHERNET Communication Module as internal Communication Module (if available)
- DC532 on the I/O bus / parameter “Fast counter” = 1-1 Up counter
Task configuration
- Task 1: Cyclic program / Prio = 10 / Interval = t#100ms / PLC_PRG
- Task 2: Simulation / Prio = 15 / Interval = t#5ms / Simulation_Task
The cyclic program PLC_PRG contains the following functions:
- Reading the cycle of PLC_PRG Calling of block TASK_INFO;
- Reading the configuration of the DC541 Calling of block DC541_GET_CFG
- Reading the status of the DC541 Calling of block DC541_STATE
- Reading/writing the static channels of the DC541 Calling of block DC541_IO
- Calling of the sequence control for the counters Calling of program proForwardCounter
The blocks DC541_GET_CFG, DC541_STATE and DC541_IO are contained in the library DC541_AC500_V11.lib and described in detail in the library documentation DC541_Library: DC541 Library
The block TASK_INFO is contained in the library SysInt_AC500_V1.0 SysInt_Library: Internal System Library
The actual execution of the 32 bit forward counter functionality is implemented in the program proForwardCounter.
Purpose of the program proForwardCounter:
The program proForwardCounter executes the following step chain:
Counter block | DC541_FWD_CNT CNT_IO | CNT_IO | |||||||
---|---|---|---|---|---|---|---|---|---|
Step | Channel | C0 | C1 | C2 | C3 | C4 | C5 | C6 | C7 | 1 |
0 | Action | Init: SET = 0, endless counter, limit values MIN = 300 / MAX = 1300 |
Init: SET = 0, limit counter, limit values MIN = 300 / MAX = 1300 |
Init | ||||||
| Value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | Action | Reset of SET input | ||||||||
| Value | 0 | 0 | 0 | 0 | 300 | 300 | 300 | 300 | 0 |
2 | Action | Start of pulse output - 2000 pulses | ||||||||
| Value | 0 | 0 | 0 | 0 | 300 | 300 | 300 | 300 | 0 |
3 | Action | Wait until pulse output is completed | ||||||||
| Value | 2000 | 1000 | 500 | 250 | 1299 | 1300 | 800 | 550 | 2000 |
4 | Action | Selection last step: byStep = 249 | ||||||||
| Value | 2000 | 1000 | 500 | 250 | 1299 | 1300 | 800 | 550 | 2000 |
200 | Action | Manual operation | ||||||||
| Value | xxx | xxx | xxx | xxx | xxx | xxx | xxx | xxx | xxx |
249 | Action | Wait time 5 seconds, then restart from step 0 | ||||||||
| Value | 2000 | 1000 | 500 | 250 | 1299 | 1300 | 800 | 550 | 2000 |
The block Simu_Pulse is used to generate an adjustable number of pulses. Its representation in the function block diagram (FBD) is as follows:
Instance | fbSimuPulse | Instance name | |
---|---|---|---|
Ben | Input/Output | BOOL | Enabling of the pulse output |
bReset | Input/Output | BOOL | TRUE = Reset of the pulse counter, bDone = TRUE |
bAutoReset | Input/Output | BOOL | TRUE and cyclic mode - The time tResetTime is started when the number of pulses set with dwPulse is reached. After this time, the pulse output is restarted again. |
tResetTime | Input/Output | TIME | Wait time until restart, if bAutoReset = TRUE |
dwPulse | Input/Output | DWORD | Number of pulses to be output: = 0: Endless mode (pulse output continues until bEn = FALSE or bReset = TRUE) > 0: Cyclic mode (output of the specified number of pulses) |
Bdone | Output | BOOL | Completion message after the number of pulses specified at dwPulse or after bReset if dwPulse = 0 |
bToggle_0 | Output | BOOL | Output: Edge with each clock cycle |
bToggle_1 | Output | BOOL | Output: Edge with each 2. clock cycle |
bToggle_2 | Output | BOOL | Output: Edge with each 4. clock cycle |
bToggle_3 | Output | BOOL | Output: Edge with each 8. clock cycle |
dwActNumPulse | Output | DWORD | Number of pulses output |
tActTime | Output | TIME | Elapsed time in [ms] while tResetTime is running |
In the example, the block Simu_Pulse is called in a 5 ms task. The pulse output is enabled or stopped via input bEn. If input dwPulse = 0, the output of pulses is performed continuously. If dwPulse > 0, only the specified number of pulses is output. When the specified number of pulses is reached, output bDone is set to TRUE.
In the example, the block is called with dwPulse = 2000. The wait time function is not used.
The example program has a visualization implemented that displays all states:
Clicking on the button <Enable visu control> (bEnVisuControl = TRUE) causes the program to jump from the current step to step 200 (manual operation). Then, the operation of the blocks is done via the corresponding pushbuttons/switches of the individual blocks. When manual operation is switched off again (bEnVisuControl = FALSE), the program jumps to step 249 and restarts from step 0 after the wait time.