Counters with OpenPLC: Count Down Instructions on an Arduino Project Kit

Counting is a fundamental task for any process controller. To implement a PLC counter instruction (CTD) using an Arduino or compatible board with the OpenPLC Ladder Diagram (LD) platform .

Control


The IEC 61131- 3 Functional Programming specification uses a Function Block( FB) for furnishing a Count Down( CTD) instruction. The CTD FB allows a diminishment point used in a variety of counting event artificial operations like conveyor corridor tracking and slingingcounter-based flashers. Learn to prototype a introductory CTD counter on an Arduino compatible board with an OpenPLC CTD FB. 

 

 Count Down( CTD) Function Block( FB) 

A CTD FB allows decremented events to be tracked and used as a control medium for artificial machine operations. Imagine a conveyor system moving boxes to the packaging stage while tracking the completion of units on a planned total quantum. With the total quantum entered in a PLC counter label, the regulator will diminishment the value grounded on the completed boxes upon entering a signal from a propinquity detector. The conveyor will stop running when the cardboard boxes have been assembled and counted. A typical IEC 61131- 3 CTD FB is shown in Figure 1. 

 

PLC counter PLC counters graduation sense counter/ graduation sense counters Count Down Functional Block/ CTD FB Count Down FB/ CTD Functional Block 

 

 Figure 1. A Count Down Function Block. 

 

 The typical CTD FB legs are labeled and defined as follows. 

 

 CD( Count Down input)- an external event reductions the counter. 

 

 LD( cargo)-( occasionally called Reset) A control signal to load the Preset value to the FB. 

 

 PV( Preset Value)- The CTD FB’s counting value. generally the preset values are positive,non-zero amounts. 

 

 Q( Affair)- The affair for the CTD FB, active when CV> PV. 

 

 CV( Current Value)- The factual current value of the CTD FB. 

 

With the applicable event- touched off bias and the handed PV and LD values included in the Label table, the OpenPLC graduation illustration can fluently be erected. To illustrate this use of the CTD FB, the following PLC program will be bandied. The illustration follows the traditional format of an Allen- Bradley( Rockwell) CTD instruction program from an RS500 development interface. 

 

 Sample CTD Counter Instruction PLC Program 

A typical Allen- Bradley( Rockwell SLC 500) PLC graduation sense program is represented in Figure 2 below. This foundation will be used as a reference graduation sense program to apply as an OpenPLC control operation using the CTD FB. 

 

sample CTD control operation PLC graduation sense program, seen in Allen- Bradley RS500 interface 

 

Figure 2. A sample CTD control operation PLC graduation sense program as seen in an Allen- Bradley( Rockwell) RS500 interface. 

 

The sequence of events( SoE) for the OpenPLC program enforced on the Arduino compatible control board consists of the following way. 

 

 The Green PLT( airman light) will be ON 

 

 Press/ release the lever switch attached to the CTD Instruction 15 times. 

 

 When the preset and accumulated values are equal, the Red PLT will turn ON 

 

 The Green PLT will turn OFF 

 

 Press/ release the Switch will reset the CTD 

 

 The Red PLT will turn OFF 

 

 The Green PLT will turn ON 

 

 An OpenPLC graduation illustration will be created to perform the CTD control operation outlined in the listed SoE. The first step is to produce a Label listing for the OpenPLC CTD counter operation. 

 

 Freenove systems Kit Conundrum 

 In the former OpenPLC specialized composition, the Freenove systems tackle board was introduced. The composition handed information on the electronic subcircuits of the tackle, which allows a accessible system of prototyping graduation sense control operations using OpenPLC. As observed in the former composition, several of the board’s digital input- affair( I/ O) legs are assigned to populated PCB electronic circuits or factors. These digital I/ O leg assignments are illustrated in Table 1. 


An egregious concern is that with the digital I/ O legs and their assigned addresses, the Freenove systems Kit board may not be suitable to expand to external electronic circuits. With similar rigid wiring to the populated electronic circuits handed by the Freenove systems Kit board, external device prototyping OpenPLC graduation illustration generalities are insolvable. The result to this possible riddle is the DIP switches. The soldered DIP switches give a accessible approach to connecting or decoupling from the populated electronics by simply opening or closing thepre-mounted circuits, as shown in Figure 3. 


 electrically connecting to Transistor- Relay circuit( D7) with a DIP Switch 

 

 Figure 3. Electrically connecting to the Transistor- Relay circuit( D7) with a DIP Switch. 

 

 

As illustrated in Figure 3 and proved in Table 1, the Freenove Control board digital leg D7 is assigned to the transistor relay circuit. To operate and connect with the electronic circuit means to close the switch. The unrestricted switch will be in the ON position, thereby electrically connected to digital leg D7 of the Freenove control board. 

 

The remaining switches for inputs and labors will be placed in the applicable positions as shown below in Figure 4, substantiated from Table 1 over. 

 

 Leg D2 on the control board is address IX0.0, attached to Switch 1. 

 

 Leg D3 on the control board is address IX0.1, attached to Switch 2. 

 

 Leg D7 on the control board is address QX0.0, attached to the Relay. 

 

 Leg D13 on the control board is address QX0.3, attached to the Blue LED.  

With the tackle powered up using a USB string, the LED pointers D2 and D3 will be illuminated. Pressing either the S1 or S2 lever switch will turn OFF the I/ O LED pointers. To insure the transistor relay circuit, the Blue LED, and digital inverted sense switches are electrically connected to the applicable Freenove Control board digital legs, slide the corresponding DIP switches to the ON position. Figure 4 illustrates the DIP switches. 

 

 applicable DIP switches placed in ON position 

 

 Figure 4. Applicable DIP switches are placed in the ON position. 

 

The complete electronic circuit schematic illustration of the I/ O bias to be electrically wired to the Freenove Control Board is shown in Figure 5. With the applicable DIP switches placed in the ON position, these electronic subcircuits will be functional once the OpenPLC graduation illustration program is uploaded to the control board. Opening the DIP switches will help the correct operation of the OpenPLC graduation illustration program from being. The coming step in the OpenPLC control operation design is erecting the graduation illustration program 

 

 count down counter electronic circuit schematic illustration 

 

 Figure 5. The CTD counter electronic circuit schematic illustration.

 

 Equivalent Breadboard Circuit 

 For those who don't have the Freenove Project Kit, this circuit can fluently be constructed with two switches and two labors. For this illustration, to maintain thickness, the same leg address connections will be used as in Figure 5. 


 breadboard fellow of Freenove Project Kit 

 

Figure 6. Breadboard original, with input switches connected to D2 and D3, affair LEDs connected to D7 and D13

 OpenPLC CTD Counter Control Circuit 

The Tag listing for the OpenPLC CTD counter control operation is shown in Figure 7. The label listing provides the digital I/ O addresses for the external switches and affair control bias wired to the Freenove Control board. Notice that the cargo value and the Preset value have a 5 as the original number. This low numeric value will demonstrate the CTD FB’s counting function snappily. 


 Count Down counter operation label listing 

 

 Figure 7. CTD counter operation label table. 

 

OpenPLC CTD Counter Ladder Diagram Program 

The OpenPLC CTD graduation illustration shown in Figure 8 below is the IEC 61131- 3 original program to Figure 2. 

 

To include the CTD FB, elect the FB icon within the OpenPLC top taskbar. elect a position on the OpenPLC graduation illustration editor. The function block window will appear; elect the CTD FB from the colorful table of counters. 

 

The use of typically closed( NC) connections in the illustration below is due to the fact that the Freenove inputs are typically closedthemselves.However, typically open( NO) switches would be the correct choice to use, If you're erecting this design using breadboard switches. 

 

 OpenPLC CTD Counter control graduation illustration operation 

 

 Figure 8. OpenPLC CTD counter control graduation illustration operation 

 

 Figure 9 illustrates the way to carrying the CTD FB within the OpenPLC taskbar. 

 

 CTD FB placement 

 

 Figure 9. The placement of the CTD FB. 

 

With the CTD FB placed on the OpenPLC graduation illustration editor, upload the software to the Freenove Control board. Now you can test the operation of the control operation using the SoE handed on the graduation illustration shown in Figure 8. Then's a videotape clip illustrating the way and the operation of the count down counter control operation. 


 Coming time, exploring up counters using the Count Up( CTU) FB will be presented. 

 

 Interactive Quiz FPK Start- Stop Control LD Program Solution 

 Use address QX0.3 to operate the Blue LED with the launch- Stop Control LD program. 

 

 Specialized Quiz Solution 

 Switches S1 and S2 are digital reversed sense switches. To insure a double sense 1( 5V) is presented when pressing the switches, the reversed or negated bit instructions will give duly aligned control signals for the correct launch- Stop sense operation.