The leader in industrial automation and control solutions
Watch on YouTube

In this tutorial, you will learn how to utilize a PID, Pulse Width Modulation (PWM), and a High-Speed Counter to control motor speed. The PID will function in a closed-loop system, controlling the PWM and using the high-speed counter (RPM) as the feedback response. The PID will control and maintain a precise rotation speed, all of which will be configured in the control software, MapleLogic.

Review these tutorials if you are unfamiliar with the functionalities of a PID, PWM and HSC in MapleLogic:

If you are familiar with the tutorials above, please continue on with this tutorial.

Software Required

Hardware Required

  • Maple Modular PLC’S – Any Maple Modular PLC.
  • PWM Module + Kit – A terminal block MUST be used with the PWM Module.
  • HSC Module + Kit – A terminal block MUST be used with the HSC Module. 
    See the wiring and configuration below.
  • Two-Phase Quadrature Encoder – Encoder Model used in this example: C38HG5-100B-G24N
  • 12-24V DC Motor – Motor Model used in this example: XD-3420
  • DC Motor Drive Module – Drive Module used in this example: 200206_FBA
  • (2) 24 VDC Power Supply (4010-0011)  

Wiring Diagrams

The diagram below shows the wiring required to measure motor speed using a PID loop, Pulse Width Modulation (PWM), and a High Speed Counter. The Maple Systems PLC connects to both a PWM module and a High Speed Counter (HSC) module. Each module connects to a terminal block for field wiring. A quadrature encoder connects to the HSC module through the terminal block. The PWM module sends a PWM signal to a DC motor drive module, which controls a 24V DC motor.

This example uses a second power supply. You can use a single power supply if it provides enough current for the system.

Wiring and Circuit Design

The wiring diagram below shows how to connect a Maple Systems PLC, PWM module, terminal block, DC motor drive module, and DC motor for PWM-based motor speed control.

Important: The terminal block cannot connect directly to the DC motor. A DC motor drive module must be used between the PWM module and the motor. Connecting the motor directly to the PWM module may damage the module. Depending on your available current, you may be able to use a single power supply instead of two.

Wire the PLC, PWM Module, and DC Motor Drive

Follow these steps to wire the PWM control system safely and correctly.

Instructions: Wire the PLC, PWM Module, and DC Motor Drive
  1. Connect the terminal block to the PWM module and PLC

    Connect the ACC-TB32M terminal block to the IO-SD0032PPWM PWM module using the ACC-SBC15E terminal block cable, and connect the PWM module to the Maple PLC.

  2. Power the Maple PLC

    Wire 24V from the power supply to the 24V terminal on the Maple PLC, and wire 0V from the same power supply to the 24G terminal on the PLC.

  3. Power the terminal block

    Wire 24V from the same power supply to terminal block point A10 and jumper it to B10 to distribute 24V across the terminal block. Then wire 0V to A20 and jumper it to B20.

  4. Select the PWM output channel

    In this example, PWM Frequency Group A and Channel 4 are used. That output point corresponds to terminal B4 on the terminal block.

    The PWM module has Frequency Groups A, B, and C, with four channels in each group for a total of 12 channels.

  5. Wire the PWM signal to the DC motor drive module

    Connect terminal B4 from the PWM output to the positive input on the DC motor drive module. Then connect 0V from terminal A20 to the negative input on the drive module.

  6. Power the DC motor drive module

    Use another power supply to provide 24V to the DC motor drive module, and connect 0V from that same power supply to the drive module negative terminal.

    A second power supply is shown in this example, but one power supply may be enough if it can deliver the required current.

  7. Connect the drive module to the motor

    Connect the DC motor drive module output to the motor by wiring the positive output to the positive motor terminal and 0V to the negative motor terminal.

PWM Ladder Diagram

This example does not use the PWM Configuration GUI. Instead, ladder diagram logic in MapleLogic controls the PWM module.

Enable PWM Channel 4 in Ladder Logic

Use ladder logic and hexadecimal values to enable the correct PWM output channel on the module.

Instructions: Enable PWM Channel 4 in Ladder Logic
  1. Review the PWM enable logic

    Open the ladder diagram section that enables the PWM module output channel instead of using the PWM Configuration GUI.

  2. Determine the hexadecimal value for Channel 4

    Use a programmer calculator together with the PWM hexadecimal chart to calculate the enable value for Channel 4. In this example, Channel 4 corresponds to bit 3, which results in hexadecimal value H0008.

    The PWM module has 12 output channels, so the correct bit pattern must be converted to hexadecimal before using the TO instruction.

  3. Enter the enable instruction in the ladder diagram

    Use the instruction [TO H0001 0 H0008 1] with internal bit M00 to enable PWM output Channel 4 on the module installed in slot 1.

    In this instruction, H0001 is the slot, 0 is the PWM output enable buffer, H0008 is Channel 4, and 1 is one word.

  4. Calculate hexadecimal values for multiple channels if needed

    If you want to enable more than one channel, combine the bit values in binary and convert them to hexadecimal. For example, Channels 4 and 1 equal H0009, while Channels 8, 4, and 1 equal H0089.

Example instruction:

—–|M00|——————-[TO H0001 0 H0008 1]—

To enable multiple channels, calculate the required hexadecimal value first. For example, Channels 4 and 1 equal H0009, while Channels 8, 4, and 1 equal H0089.

Ramp the Motor from 0% to 25% Duty Cycle

Use a timer and PWM buffer writes to bring the motor from stop to 25% duty cycle at 500 Hz.

Instructions: Ramp the Motor from 0% to 25% Duty Cycle
  1. Enable the first speed stage

    Turn on internal bit M01 to enable the first speed-control stage in rung 4.

  2. Start the 10-second timer

    Use TON TC0 100 to start a 10-second ON timer. When the timer completes, T0 turns on.

    TC0 is timer bit 0, and 100 represents 10 seconds in this example.

  3. Write the ramp time, duty cycle, and frequency

    Move 500 into D10 for a 5-second duty cycle ramp time, move 25 into D20 for a 25% duty cycle, and move 500 into D30 for a frequency of 500 Hz. Then write those values to the PWM module buffer memory.

    Buffer 33 is duty cycle ramp time, buffer 13 is duty cycle ratio, and buffer 1 is frequency value.

  4. Advance to the next speed stage

    When T0 turns on after 10 seconds, reset M01 and set M02 so the first stage turns off and the next logic stage begins.

This stage takes 10 seconds to bring the motor from 0% to 25% duty cycle at a frequency of 500 Hz.

Ramp the Motor from 25% to 90% Duty Cycle

Use the second timed PWM stage to increase motor speed from 25% to 90% duty cycle at 500 Hz.

Instructions: Ramp the Motor from 25% to 90% Duty Cycle
  1. Enable the second speed stage

    Use internal bit M02 to enable rung 7 and begin the second speed-control stage.

  2. Start the second 10-second timer

    Use TON TC1 100 so the second speed stage runs for 10 seconds before advancing.

  3. Write the new PWM values

    Move 500 into D40 for the ramp time, 90 into D50 for the duty cycle ratio, and 500 into D60 for the frequency value, then write those values to the PWM module.

    This stage increases the motor speed from 25% to 90% duty cycle at 500 Hz.

  4. Advance to the next stage

    When T1 turns on, reset M02 and set M03 to hand control to the next logic stage.

This stage takes 10 seconds to increase the motor speed from 25% to 90% duty cycle at a frequency of 500 Hz.

Reduce the Motor from 90% to 50% Duty Cycle

Use the third timed PWM stage to reduce motor speed from 90% to 50% duty cycle at 500 Hz.

Instructions: Reduce the Motor from 90% to 50% Duty Cycle
  1. Enable the third speed stage

    Use internal bit M03 to enable rung 10 and begin the third PWM stage.

  2. Start the third 10-second timer

    Use TON TC2 100 so the third speed stage runs for 10 seconds before advancing.

  3. Write the reduced PWM values

    Move 500 into D70 for the ramp time, 50 into D80 for the duty cycle ratio, and 500 into D90 for the frequency value, then write those values to the PWM module.

    This stage reduces motor speed from 90% to 50% duty cycle at 500 Hz.

  4. Advance to the final stage

    When T2 turns on, reset M03 and set M04 so the final speed stage begins.

This stage takes 10 seconds to decrease the motor speed from 90% to 50% duty cycle at a frequency of 500 Hz.

Reduce the Motor from 50% to 20% Duty Cycle and Stop

Use the final timed PWM stage to lower motor speed and then turn the motor off.

Instructions: Reduce the Motor from 50% to 20% Duty Cycle and Stop
  1. Enable the final speed stage

    Use internal bit M04 to enable rung 13 and begin the final PWM speed stage.

  2. Start the final 10-second timer

    Use TON TC3 100 so the final speed stage runs for 10 seconds before shutting the motor down.

  3. Write the final PWM values

    Move 500 into D100 for the ramp time, 20 into D110 for the duty cycle ratio, and 500 into D120 for the frequency value, then write those values to the PWM module.

    This stage reduces motor speed from 50% to 20% duty cycle at 500 Hz.

  4. Turn the motor off

    When T3 turns on after 10 seconds, reset M04 so the rung turns off and the motor stops.

This final stage takes 10 seconds to reduce the motor from 50% to 20% duty cycle at a frequency of 500 Hz, then turns the motor off.

PWM Online with Motor

After downloading the project, go online with the PLC and PWM module to watch the motor respond to each duty cycle stage in real time.

To see the motor speed changes more clearly, refer to the video included with this tutorial while monitoring the ladder logic online.

Monitor the PWM Logic Online

Run the PWM project online and observe how each timed logic stage changes the motor speed.

Instructions: Monitor the PWM Logic Online
  1. Go online with the PLC

    In MapleLogic, go to Online > Link + Download + Monitor to download the project and establish online communication with the PLC and PWM module.

  2. Enable PWM Channel 4

    Click the M00 bit and press Shift + Enter to turn M00 ON. This enables PWM Channel 4.

  3. Start the first speed stage

    Click the M01 bit and press Shift + Enter to turn M01 ON. This enables the TON TC0 100 instruction. The motor ramps from 0% to 25% duty cycle at 500 Hz over 5 seconds, and after 10 seconds T0 turns ON, resets M01, and sets M02.

  4. Watch the motor increase from 25% to 90% duty cycle

    When M02 turns ON, the second timer stage begins. The motor ramps from 25% to 90% duty cycle at 500 Hz over 5 seconds. After 10 seconds, T1 turns ON, resets M02, and sets M03.

  5. Watch the motor decrease from 90% to 50% duty cycle

    When M03 turns ON, the third timer stage begins. The motor ramps down from 90% to 50% duty cycle at 500 Hz over 5 seconds. After 10 seconds, T2 turns ON, resets M03, and sets M04.

  6. Watch the motor decrease from 50% to 20% and stop

    When M04 turns ON, the final timer stage begins. The motor ramps down from 50% to 20% duty cycle at 500 Hz over 5 seconds. After 10 seconds, T3 turns ON, resets M04, and the motor turns OFF.

Sample Project

This integration tutorial uses the MapleLogic sample project.

Resources & Documentation

The following guides and documentation are specific to the hardware used in this integration tutorial and will help you with setup, configuration, and programming:

Looking for additional learning resources? Explore our library of tutorials, example projects, and software tools to help you get the most out of your system:

Also, browse our Support Center for a complete list of installation guides, FAQs, and additional technical documentation.

Kyle Nicholas Avatar

System integrations can raise questions that go beyond documentation. Our knowledgeable team is available to help connect you with the right resources and guidance. If you are working with Maple Systems hardware or considering a solution, reach out and we’ll help point you in the right direction.