Creating a Low-Cost OpenPLC Pulse Timer Function Block HMI with an M5Stack Core
Triggering a machine by an external event often requires a pulse timer for OpenPLC Pulse Timer control. Here’s a brief tutorial on how an M5Stack Core can offer a simple, effective low-cost Arduino OpenPLC HMI solution.
Pulse Timer Function Block Basics
Pulse timers are analogous to one-shot circuits that trigger events for industrial machines or electronic appliances. In contrast to typical PLC timers, these devices function as triggerable event timers, where either a rising or falling input edge will trigger the timer to run for a specified time, regardless of input status. Figure 1 illustrates an OpenPLC pulse timer function block (FB).
Figure 1. PLC Pulse Timer FB. Image used courtesy of the author
The Pulse Timer FB’s input and output pin designators are defined next.
IN–Input: This pin accepts a trigger signal from an external switching device to initiate the pulse timing function of the FB.
PT–Preset Time: A timing value in milliseconds (ms) sets the Pulse Timer's switching output duration.
ET–Elapsed Time: This tag tracks the accumulated or elapsed time of the FB. The ET pin begins accumulating upon the input pin being triggered by an external switching device.
Q–Pulse Timer output: The timer’s output will immediately energize when the input trigger is received and remain energized until the preset duration is reached. The logic for Q is Q = ET < PT.
Figure 2 illustrates a typical timing diagram to further explain the pulse timer operation.
Figure 2. Pulse Timer Timing Diagram. Image used courtesy of the author
When the external switching device contacts are initially open, the timer’s FB output pin is at zero volts. After closing and opening the pushbutton switch contacts within 1 second, a single pulse is produced. This single pulse will trigger the timer to produce an output control signal voltage of 5VDC. The output control signal (Q) will be activated for 5 seconds, at which point the Pulse Timer’s FB output pin (Q) turns off.
Introducing the M5Stack Core
Traditionally, an electrical switch would provide the external trigger for an OpenPLC ladder diagram (LD). However, a more modern, effective approach to operating industrial machines and triggering PLC control timing events is the human-machine interface (HMI). A contemporary HMI allows multiple pages or screens, touch capabilities, and programming access to specific machine control operations.
Figure 3. A typical HMI panel. Image used courtesy of Inductive Automation
One effective way to leverage the benefits of a modern HMI in an OpenPLC industrial control solution centers on using an M5Stack Core controller. Relatively compact, the M5Stack Core comes with an ESP32 microcontroller and an industrial-grade LCD HMI display, providing the graphical interface.
Figure 4. An M5Stack Core Controller. Image used courtesy of M5Stack
Featuring three connecting ports, the controller allows various M5Stack modules to be attached using 4-wire harnesses. In the following example, a 2-channel relay unit will provide the trigger event to the Arduino OpenPLC, initiating the pulse timer operation.
Wiring the M5Stack Core to the Arduino OpenPLC Controller
The relay module’s dry contact provides a switching trigger signal to the Arduino’s digital pin 3. The OpenPLC LD will read the pulse control signal applied to the timer’s IN pin, energizing the timer FB. The output pin (Q) will activate for 5 seconds (5000 ms), then turn off.
Figure 5. The M5Stack relay module. Image used courtesy of M5Stack
The M5Stack relay module has two single pole single throw (SPDT) electromechanical relays and LED indicators mounted onto its simple platform.
One relay from the module will be wired in parallel with a tactile pushbutton switch. A pushbutton allows for quick testing of the timer before using the M5Stack Core. This approach ensures that the controller is correctly receiving the relay signal from the M5Stack Core.
Figure 6. The Pulse Timer controller electrical wiring diagram. Image used courtesy of the author
The schematic and diagrams shown in Figures 6 and 7 reference the M5Stack Core and the relay module dry contact wired to the Arduino.
Figure 7. The M5Stack Core-Pulse Timer controller electronic circuit schematic diagram. Image used courtesy of the author
Creating the M5Stack Core User Interface
Various user interfaces can be created for OpenPLC-operated Arduino controllers using an M5Stack Core. The controller uses UiFlow software, powered by Blockly, a popular graphical programming software for creating UIs. By stacking the blocks, various control devices can be built. The M5Stack Core’s UI is laid out by placing labels onto the TFT LCD design window of the UIFlow software.
Figure 8. The Pulse Timer Control Switch UI layout and Blockly code instructions. Image courtesy of the author.
By pressing the Start (A) button on the M5Stack Core, the signal to 'relay One' of the module turns on. After the 1-second wait instruction has been executed, 'relay One' turns off. Pressing the Start button will repeat the switching operation. A USB-C cable is used to attach the M5Stack Core to the programming PC. Running or executing the code from the UIFlow online programming environment allows the M5Stack Core to display the control switch UI. Figure 9 shows the final assembly of the M5Stack Core, the relay module, and the Arduino circuit.
Figure 9. The Assembled M5Stack Core-Pulse Timer Controller. Image used courtesy of the author
Arduino OpenPLC LD Setup
The final step is adding the OpenPLC ladder diagram to the Arduino. The timer LD has three primary tags for properly operating the M5Stack Core UI controller: Start_Pulse_Timer, TP0, and RED_LED. The explanation of these tags is provided next.
Start_Pulse_Timer: This tag name identifies the M5Stack relay module’s SPDT contact wired to digital pin 3 of the Arduino controller. The tag provides the control signal to start the Pulse Timer FB 5-second on-time delay timing function. The physical address location for the Arduino digital pin 3 is %IX0.1
TP0: Pulse Timer FB designator.
RED_LED: The tag provides the activation or turn-on function to operate the Red LED wired to digital pin 13 of the Arduino controller. The physical address location for the Arduino digital pin 13 is %QX0.3.
The tag listing and LD for the M5Stack Core UI controller are illustrated in Figure 10 below.
Figure 10. The Pulse Timer controller Tag Listing and LD.
Attach the Arduino to the development system and upload the LD to the embedded device within the OpenPLC environment. The OpenPLC 'Communications' tool window will display the code's successful download completion task, as illustrated in Figure 11. The Communications tool is a new feature of the latest OpenPLC software version.
Figure 11. Successfully downloaded the Pulse Timer LD to the Arduino controller. Image used courtesy of the author
With the LD successfully downloaded to the Arduino controller, pressing the M5Stack Core controller’s Start button will initiate the Pulse Timer FB. The Red LED on the prototyping board should turn on for 5 seconds.
Congratulations! You’ve Successfully Created an HMI Control Solution
If you made it this far, you have successfully built and tested a mini-HMI device using the M5Stack Core and UIFlow software to operate an OpenPLC LD!
The M5Stack Core controller can offer a straightforward cost-effective way to leverage HMI benefits to trigger pulse-time events. As a design challenge, try building an LED flasher using the M5Stack Core and Arduino OpenPLC prototyping concepts presented in this project. To get your project started on the right foot, the Pulse Timer Controller and the M5Stack Core UI block code are available from GitHub. Finally, more information about the M5Stack Core with hands-on projects can be found in this book.