Configuration Example: Pulse Width Modulation (PWM)¶
In the configuration example, channel 0 of the DC541 is configured for pulse width modulation (PWM). The output signal is measured using the function Time and frequency measurement Usage for Time and Frequency Measurement of the DC541-CM.
The following on-off ratio shall be used:
PULSE | PAUSE | CYCLE | Result (x = number of cycles of the DC541) |
Cycle time of DC541 = 100 µs | |||
1 | 2 | 2000 | 20 x TRUE / 40 x FALSE / 20 x TRUE / 40 x FALSE / … i.e. 2000 µs = TRUE and 4000 µs = FALSE |
Hardware configuration:
The example control system shall have the following configuration:
- Terminal base TB521 (two Communication Module slots)
- DC541 in Communication Module slot 1 (first slot on the left of the CPU)
- PM591-ETH CPU with internal Ethernet Communication Module (configuration using SYCON.net)
- I/O module DC532 on the I/O bus
Wiring:
The channels are connected as follows:
DC541 / C0 ————– DC541 / C1
PLC configuration:
- DC541-CM in slot 1, operating mode “counter mode” | |||
- Configuration: | - Channel | C0 | PWM |
C1 | FREQ | ||
C2…C7 | Input | ||
- Specification of the Ethernet Communication Module as internal Communication Module (if available) (Ethernet Communication Module configuration using SYCON.net) |
Task configuration:
- Task 1: Cyclic program / Prio = 10 / Interval = t#1ms / PLC_PRG
Purpose of the cyclic program PLC_PRG:
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 PWM and FREQ Calling of program proPWM_FREQ
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
Calling the pulse width modulation functionality as well as measurement and acquisition of measured values are performed in the program proPWM_FREQ. The program proPWM_FREQ contains the calls for the function blocks DC541_PWM: DC541_PWM DC541_PWM and DC541_FREQ: DC541_FREQ DC541_FREQ as well as the acquisition of the measured values. The function block DC541_FREQ is configured in a way that it measures the time between each edge change.
The example program has a visualization implemented that displays all states:
Input EN_VISU of the function block DC541_FREQ is TRUE. Therefore, the inputs of the block can be modified using the buttons <Enable>, <En 0>, <En 1> and <En Freq> in the visualization.
The measured values are 2000, 4000 or 6000 µs depending on which edges were considered for measurement.