How to Control the Speed of a Motor Using Pulse Width Modulation
In this tutorial you will learn how to control the speed of a motor using a Maple PLC and PWM Module while utilizing ladder diagram logic in the control software (MapleLogic).
Software Required
Hardware Required
- Maple Modular PLC’S – Any Maple Modular PLC can be used.
- PWM Module + Kit – A terminal block MUST be used with the PWM Module.
- 12-24 VDC Motor
- DC Motor Drive Module
- (2) 24 VDC Power Supply (4010-0011)
Wiring and Circuit Design
Wiring and Circuit Design
1 – In the wiring example above, connect the Terminal Block (ACC-TB32M) via the Terminal Block cable (ACC-SBC15E) to the PWM Module (IO-SD0032PPWM) and the Maple PLC (PLC-ES0808P).
The terminal block cannot connect directly to the DC Motor. A DC Motor Drive Module MUST BE USED to output a PWM signal from the PWM Module (SD0032PPWM) to a DC Motor or you risk damaging the module.
Keep in mind, that you could use one power supply depending on the amount of current you are able to distribute.
2 – 24V from the Power Supply into the 24V on the Maple PLC. Power Supply 0V into the 24G on the Maple PLC
3 – 24V from the same Power Supply into the 24V on the Terminal Block (A10) and jump to (B10) to supply power to the entire Terminal Block. 0V from the same Power Supply into 0V on the Terminal Block (A20) and jump to (B20).
4 – In this wiring example there’s Frequency groups A, B and C which each have four PWM output channels (total of 12), we’re using PWM frequency A and Channel 4, which would be (B4).
5 – The PWM output signal from (B4) connects to (+) on the DC Motor Drive Module to enable the PWM on the DC Motor Drive Module. 0V from (A20) connects to (-) on the DC Motor Drive Module.
6 – Another Power Supply will provide 24V to the DC Motor Drive Module to power it ON. 0V from that same Power Supply will connect to (-) on the DC Motor Drive Module.
7 – The DC Motor Drive Module will then output the PWM signal to the (+) on the 12-24V DC Motor and 0V to the (-) on the DC Motor. *(Not included in diagram:
PWM Ladder Diagram
- In the configuration example above, we won’t be using the PWM Configuration GUI, and just Ladder Diagram logic to control the speed of a 24V DC Motor using PWM.
1 – [M00] is an internal bit used to enable Channel 4 from the PWM Module. In order to understand the use of communicating with a specific PWM output channel in an application instruction, you will need to know how to calculate hexadecimals using a Programmer Calculator and the hexadecimal chart for the PWM Module.
H0008 is Channel 4. Here is why:
- Open your Programmer Calculator on your PC
- Refer to the chart below to enter the correct numeric combination to get the hexadecimal for the PWM Output Channel 4.
- In this chart, it’s showing the PWM Module on a bit level. There are 12 bits for 12 Channels. Bit 3 therefore is Channel 4.
- Fill in the following combination for “BIN” or binary value. To just enable Ch4, enter a 1 which means “ON”, and then 0,0,0 on the calculator.
- The “HEX” will equal 8, so the hexadecimal is H0008.
- For the Application Instruction on rung 1, this will be entered as follows in your ladder diagram
—–|M00|——————-[TO H0001 0 H0008 1]—
- In the second rung of logic (R.2), (M00) is used to enable CH4 PWM output channel (H0008)
a) TO = to the PWM Module
b) H0001 = Slot 01 on the PLC chassis
c) 0 = PWM output enable bit
d) H0008 = PWM output Channel 4.
e) 1 = one word
To enable multiple channels. Channel 4 and 1. On your programmer calculator, enter 1, 0, 0, 1 which equals 9 for “HEX” so H0009 in your logic.
To enable Channels 8, 4 and 1. On your programmer calculator, enter 1, 0, 0, 0, 1, 0, 0, 1 which equals 89 for “HEX” so H0089 in your logic.
2 – On Rung 4, [M01] is used to enable a [TON] 10 second timer. It will also trigger MOV and Application Instructions to control the Duty Cycle, Frequency and Duty Cycle Ramp Time.
3 – [TON TC0 100] is a 10 second ON Timer. TC0 is Timer Bit 0. 100 is 100 milliseconds or 10 seconds. At 10 seconds, Motor Timer 1 [T0] will turn ON.
4 – The next six lines of logic on Rung 4 or (R.4) are all being enabled by (M01) and are communicating with the PWM Module (H0001).
- For the second and third lines of logic on rung 4, a value of 500 (5 sec) is being moved (MOV) to (D10) which is the register being used for the Duty Cycle Ramp Time. (33) is the buffer memory for the Duty Cycle Ramp Time.
For the fourth and fifth lines of logic on rung 4, a value of 25 (25% Duty Cycle) is being moved (MOV) to (D20) which is the register being used for the Duty Cycle Ratio. (13) is the buffer memory for the Duty Cycle Ratio. - For the sixth and seventh lines of logic on rung 4, a value of 500 (500 Htz) is being moved (MOV) to (D30) which is the register being used for the Frequency Value. (1) is the buffer memory for the Frequency Value.
5 – Finally, on Rung 5, like mentioned earlier, when the TON timer counts to 10 seconds, it will turn ON (T0) “Motor Timer 1” to Reset M01 [RST M01] and Set M02 [SET M02]. So it will turn OFF Rung 4 logic and turn ON the next piece of logic below.
To summarize the logic above:
- To enable Ch4 of the PWM Module, turn ON the PWM enable bit (H0008)
- Then trigger (M01) ON to run the logic on rung 4.
- The logic is initiating that it will take 10 seconds to increase the speed of the motor from 0 to 25% duty cycle at a frequency of 500 Htz.
1 – On Rung 7 [M02] is an internal bit used to enable another [TON] 10 second timer. It will also trigger another set of MOV and Application Instructions to control the Duty Cycle, Frequency and Duty Cycle Ramp Time.
2 – On Rung 7, [M02] is used to enable a [TON] 10 second timer. At 10 seconds, Motor Timer 2 [T1] will turn ON.
3 – The next six lines of logic on Rung 7 or (R.7) are all being enabled by (M02) and are communicating with the PWM Module (H0001).
- For the second and third lines of logic on rung 7, a value of 500 (5 sec) is being moved (MOV) to (D40) which is the register being used for the Duty Cycle Ramp Time. (33) is the buffer memory for the Duty Cycle Ramp Time.
- For the fourth and fifth lines of logic on rung 7, a value of 90 (90% Duty Cycle) is being moved (MOV) to (D50) which is the register being used for the Duty Cycle Ratio. (13) is the buffer memory for the Duty Cycle Ratio.
- For the sixth and seventh lines of logic on rung 7, a value of 500 (500 Htz) is being moved (MOV) to (D60) which is the register being used for the Frequency Value. (1) is the buffer memory for the Frequency Value.
4 – Finally, on Rung 8, like mentioned earlier, when the TON timer counts to 10 seconds, it will turn ON (T1) “Motor Timer 2” to Reset M02 [RST M02] and Set M03 [SET M03]. So it will turn OFF Rung 7 logic and turn ON the next piece of logic below.
To summarize the logic above:
- (M03) is triggered ON to run the logic on rung 10.
- The logic is initiating that it will take 10 seconds to increase the speed of the motor from 25 to 90% duty cycle at a frequency of 500 Htz.
1 – On Rung 10 [M03] is an internal bit used to enable another [TON] 10 second timer. It will also trigger another set of MOV and Application Instructions to control the Duty Cycle, Frequency and Duty Cycle Ramp Time.
2 – On Rung 10, [M03] is used to enable a [TON] 10 second timer. At 10 seconds, Motor Timer 3 [T2] will turn ON.
3 – The next six lines of logic on Rung 10 or (R.10) are all being enabled by (M03) and are communicating with the PWM Module (H0001).
- For the second and third lines of logic on rung 10, a value of 500 (5 sec) is being moved (MOV) to (D70) which is the register being used for the Duty Cycle Ramp Time. (33) is the buffer memory for the Duty Cycle Ramp Time.
- For the fourth and fifth lines of logic on rung 10, a value of 50 (50% Duty Cycle) is being moved (MOV) to (D80) which is the register being used for the Duty Cycle Ratio. (13) is the buffer memory for the Duty Cycle Ratio.
- For the sixth and seventh lines of logic on rung 10, a value of 500 (500 Htz) is being moved (MOV) to (D90) which is the register being used for the Frequency Value. (1) is the buffer memory for the Frequency Value.
4 – Finally, on Rung 11, like mentioned earlier, when the TON timer counts to 10 seconds, it will turn ON (T2) “Motor Timer 3” to Reset M03 [RST M03] and Set M04 [SET M04]. So it will turn OFF Rung 10 logic and turn ON the next piece of logic below.
To summarize the logic above:
- (M04) is triggered ON to run the logic on rung 13.
- The logic is initiating that it will take 10 seconds to decrease the speed of the motor from 90 to 50% duty cycle at a frequency of 500 Htz.
1 – On Rung 13 [M04] is an internal bit used to enable another [TON] 10 second timer. It will also trigger another set of MOV and Application Instructions to control the Duty Cycle, Frequency and Duty Cycle Ramp Time.
2 – On Rung 13, [M04] is used to enable a [TON] 10 second timer. At 10 seconds, Motor Timer 4 [T3] will turn ON.
3 – The next six lines of logic on Rung 13 or (R.13) are all being enabled by (M04) and are communicating with the PWM Module (H0001).
- For the second and third lines of logic on rung 13, a value of 500 (5 sec) is being moved (MOV) to (D100) which is the register being used for the Duty Cycle Ramp Time. (33) is the buffer memory for the Duty Cycle Ramp Time.
- For the fourth and fifth lines of logic on rung 13, a value of 20 (20% Duty Cycle) is being moved (MOV) to (D110) which is the register being used for the Duty Cycle Ratio. (13) is the buffer memory for the Duty Cycle Ratio.
- For the sixth and seventh lines of logic on rung 13, a value of 500 (500 Htz) is being moved (MOV) to (D120) which is the register being used for the Frequency Value. (1) is the buffer memory for the Frequency Value.
4 – Finally, on Rung 14, like mentioned earlier, when the TON timer counts to 10 seconds, it will turn ON (T3) “Motor Timer 4” to Reset M04 [RST M04]. So it will turn OFF Rung 13 logic and turn OFF the motor.
To summarize the logic above:
- (M04) is triggered ON to run the logic on rung 13.
- The logic is initiating that it will take 10 seconds to decrease the speed of the motor from 50 to 20% duty cycle at a frequency of 500 Htz. The TON timer will trigger a bit to turn OFF the motor.
PWM Online with Motor
Go to Online >>> Link + Download + Monitor to download and go online with the PLC and PWM Module.
To get a good visual of the motor speed changing according to the duty cycle, please watch the video attached to this tutorial.
- Click on the [M00] bit and type Shift+ Enter on your keyboard to turn ON [M00] to enable PWM Channel 4.
Click on the [M01] Bit and type Shift+Enter on your keyboard to turn on [M01] to enable the [TON TC0 100] instruction. It will count 10 seconds.
When [M01] is turned ON, the following logic will be initiated.
It will take 5 seconds (Duty Cycle Ramp Time) for the motor to increase from 0% to 25% Duty Cycle at a frequency rate of 500 Htz.
At 10 seconds [T0] “Motor Timer 1” will turn ON and reset M01 and set M02.
[M02] is now ON and it has enabled the [TON TC1 100] instruction. It will count 10 seconds.
When [M02] is turned ON, the following logic will be initiated.
It will take 5 seconds (Duty Cycle Ramp Time) for the motor to increase from 25% to 90% Duty Cycle at a frequency rate of 500 Htz.
At 10 seconds [T1] “Motor Timer 2” will turn ON and reset M02 and set M03.
[M03] is now ON and it has enabled the [TON TC2 100] instruction. It will count 10 seconds.
When [M03] is turned ON, the following logic will be initiated.
It will take 5 seconds (Duty Cycle Ramp Time) for the motor to decrease from 90% to 50% Duty Cycle at a frequency rate of 500 Htz.
At 10 seconds [T2] “Motor Timer 3” will turn ON and reset M03 and set M04.
[M04] is now ON and it has enabled the [TON TC3 100] instruction. It will count 10 seconds.
When [M04] is turned ON, the following logic will be initiated.
It will take 5 seconds (Duty Cycle Ramp Time) for the motor to decrease from 50% to 20% Duty Cycle at a frequency rate of 500 Htz.
At 10 seconds [T3] “Motor Timer 4” will turn ON and reset M04 and the motor will turn OFF.
Sample Project
The project shown above was designed for the specific hardware mentioned at the beginning of the tutorial and is intended to provide you guidance when programming your unit. If you are using models other than the ones specified in this sample project, similar steps can be duplicated within your own project.
Download MapleLogic Sample Project
Resources & Documentation
Maple PLC/MapleLogic Resources
- MapleLogic Programming Software
- MapleLogic User Manual
- Maple Modular User Manual
- PWM Module User Manual – (Refer to IO-SD0032PPWM)
- PWM Module User Manual (Coming soon)
- Maple Modular PLC Terminal Block & Cables
More
Tutorials
Sample Projects
See our Support Center for a complete list of Quick Start and Installation Guides