Your cart is currently empty!
How to Configure a Custom Function Block
In this tutorial, you will learn how to create and configure a Pulse Width Modulation function block to control the speed of a motor and add it into your ladder diagram in the control software (MapleLogic).
Software Required
Hardware Required
- Maple Modular PLC’S – Any Maple Modular can be used
- PWM Module Kit – A terminal block MUST be used with the PWM Module.
- 12-24V DC Motor – Model used in this example: XD-3420
- DC Motor Drive Module – Model used in this example: 200206_FBA
- (2) 24 VDC Power Supply (4010-0011)
Wiring Diagram

This wiring diagram is also used in the How to Control the Speed of a Motor Using Pulse Width Modulation Tutorial page. To review a detailed description, please visit the link.
Custom Function Block Configuration

In MapleLogic, on the left side of the program, right click on “User Library [Function Block Sample]” to add an FB.

- Name the FB
- Enter a Password (optional)
- Press OK

The FB is created and stored in the “User Library”.
Import and Export Function Block

To import or export a custom function block, right click on the function block under the User Library and select either Import FB or Export FB.

To export an FB, you can either click “Yes” to save it to the system library in MapleLogic or click “No” to save it as a file under the project directory.

If you choose System Library, it’ll be saved under the User System Lib.

If you choose to save it as a file, by default it’ll be saved in the projects directory under the “FB_ITEM” folder. Click “Save”.

To import that file or any other custom FB, right click on the FB under the User Library and choose Import FB. Select the FB file in the projects folder and click “Open”.

Configure the Function Block Variables
- Click the “+” next to the “PWM FB”
- Double click on “Variable”

1- Add Inputs, Outputs or I/O by clicking on “Add Input” and “Add Output”.
2 – Name the variables
3 – Choose whether the variable is a Bit, Word, Double Word or Float.
4 – Enter the description of the variable to display in a ladder diagram.

To review the PWM Module buffer memory in more detail, please refer to the How to Control the Speed of a Motor Using Pulse Width Modulation tutorial page.

Function Block Program Configuration
1 – Add an open contact. Use “EN” to enable the function block.
2 – Add “TO” application instruction to enable the PWM buffer memory.
- TO – To the PWM Module | H0001 – Slot 1 | 0 – Buffer Memory for the PWM Output Enable | H0008 – Hexadecimal for PWM Output Channel 4 | 1 – Stored as 1 word
- Add a “TO” application instruction to enable the Channel 4 Duty Cycle.
- TO – To the PWM Module | H0001 – Slot 1 | 13 – Buffer Memory for Channel 4 Duty Cycle | DUTY – Input Variable from the Function Block | 1 – Stored as 1 word
- Add a “TO” application instruction to enable Channel 4 of Frequency A.
- TO – To the PWM Module | H0001 – Slot 1 | 1 – Buffer Memory for Frequency A Channel 4 | FREQ – Input Variable from the Function Block | 1 – Stored as 1 word
- Add a “TO” application instruction to enable Channel 4 Duty Cycle Ramp Time.
- TO – To the PWM Module | H0001 – Slot 1 | 33 – Buffer Memory for the Channel 4 Duty Cycle Ramp Time | RAMP – Input Variable from the Function Block | 1 – Stored as 1 word
3 – A comparison application instruction for the motor – If DUTY is greater than or equal to 90% Duty Cycle, ALARM output will turn ON.
elect the FB file in the projects folder and click “Open”.
Ladder Diagram

1 – An open contact “M01” initiates the custom function block and turns ON “M10” output to verify that the logic is complete.
2 – Double click on the function block to open the variable window. Now you can add the device registers.
Online Simulation

In the Device Monitor, add the device registers and enter the values, 25 % Duty Cycle, 500 Hz, and 200 ms.
The frequency, duty cycle and ramp time are displayed in the “PWM FB”.
Motor Simulation

Type Shift+Enter to enable M01. The Motor will ramp up to 25% Duty Cycle.

Change the Duty Cycle value in the Device Monitor to 75. The motor will ramp up to 75% Duty Cycle.

Change the Duty Cycle value in the Device Monitor to 0. The motor will ramp down to 0% Duty Cycle and turn off.
LED Light Simulation

Change the Duty Cycle value in the Device Monitor to 500 and the Frequency to 1 Hz. The LED Light will blink at 50% Duty Cycle at 1 Hz.
The frequency and duty cycle are displayed in the “PWM FB”.

Change the Duty Cycle value in the Device Monitor to 900. The LED Light will blink at 90% Duty Cycle at 1 Hz.
The frequency and duty cycle are displayed in the “PWM FB”.
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)
- Maple Modular PLC Terminal Block & Cables
More
Tutorials
Sample Projects
See our Support Center for a complete list of Quick Start and Installation Guides

About the Author