Programming an Up/Down Counter in the Selec MIBRX PLC

This article will cover the assembly of a PLC circuit that will be programmed to perform a simple counting operation in both up and down directions. Additionally, the article will describe the programming used to control the PLC and explain how the counter block functions. Furthermore, this article will outline the process of downloading the program into the Selec Selpro software.

Selec MIBRX PLC at the start-up of the counter program

Project Hardware

The parts that will be used in this article is the assembled Selec MIBRX-2M-1-0-0-24VDC from previous articles, a 1A circuit breaker, a NO selector switch, a NO pushbutton, a NC pushbutton, a red 22mm LED panel light, a workbench, a switch plate, and miscellaneous hardware.

Tech Tip: PLC must have a working HMI in order to download a program.

The link below will bring you to the cart with all the parts used in this project
https://www.digikey.com/short/n0c1jqpw

Assembly of the Hardware

The first thing to do is to assemble all the parts on the workbench, starting by attaching the switch, pushbuttons, and LED to the switch plate. Next, attach the switch plate to the workbench using hex standoffs, screws with washers, and plastic thumb screws to hold the switch plate down. Then, attach the DIN rail to the workbench using screws, nuts, and washers to hold it in place. Finally, attach the PLC, circuit breaker, and end blocks to the DIN rail mounted to the workbench.

Connecting the Wires

With all the components in place, it is time to begin wiring the components together to create the circuit. Starting with the 24 Volt positive side of the power supply, attach a wire that runs from the positive side of the power supply to the circuit breaker and then connect the other side of the circuit breaker to the positive input of the PLC. Additionally, there is a second wire connected to the circuit breaker that will run up to the input side of the red LED since all the inputs are set up to be a sinking configuration. From the red LED, the selector switch and pushbuttons will have their input power sides daisy chained off each other. This is done by connecting individual pieces of wire between each of the components so that there will be two wires in one input slot, with one wire going to the components on either side.

All positive/24Volt connections

For the ground connections of the PLC, there is a custom-made wire harness that goes from the negative side of the power supply to the PLC’s negative input, then up to both common connections on the relay output module (C0 and C1). The reason that the common connections of the relay module are connected to ground is that it is set up in a sourcing configuration where the positive voltage goes to the load, then the signal from the load goes to the PLC, and the PLC completes the circuit with the ground connection.

The next connections are the I/O pins, which are both the inputs and outputs of the PLC. These connections are the built-in DI_0 for the selector switch, the built-in DI_1 for the green pushbutton, the digital input expansion module’s DI_0 for the red pushbutton, and R0 on the relay module for the red panel indicator. The last connection being made is the RS485 cable, which is connected to the +/- RS485 ports on the PLC with red to the + and black to the -.

Input and output connections for the MIBRX PLC, and the custom-made wiring harness for the ground connection.

Tech Tip: Make sure you connect you power supply to the +/- port of the PLC and not the +/- RS485 port on the PLC

Writing the Program

The first line of the program is a normally open (NO) contact that has DI_0 set as its variable, and it connects to a coil that has DO_0 set as its variable. This line simply turns on the red panel LED when the selector switch is activated.

The second line starts the inputs to the Up/Down Counter block, and this line has an NO contact with DI_1 as its variable connected to the up input of the counter block. The third line has a normally closed (NC) contact with DI_3 as its variable connected to the down input of the counter block. The reason that the NC contact is used instead of a NO contact is that the red pushbutton has a NC contact. The fourth line is a NO contact that is connected to the reset input of the counter block with DI_0 set as the variable, and DI_0 is used twice in this program. The sixth line has a global integer variable used to control how high the counter block can count.

On the output side of the counter block, there is only one global integer variable used to store the count so that it can be used to display the count on the HMI.

The counter block program in Selpro

The counter block program in Selpro

Counter Blocks

In the Selec Selpro software, there are three main counter blocks: an up counter, down counter, and up/down counter. There are other specialty types of counters within the Selec Selpro software, but these are the main counters. Each counter is very self-explanatory: the up counter only counts up, the down counter only counts down, and the up/down counter can count both up and down.

All the counters in the Selec Selpro software use Boolean data type for the inputs of the count and reset in the counter blocks. The data type used in the up counter and down counter for the count variable is unsigned integers and unsigned double integers. Unlike the other two counters, the up/down counter uses an integer and double integer as its count data type. What this means is that the up counter and down counter can only count with positive numbers, whereas the up/down counter can count in both positive and negative numbers.

HMI

The MIBRX-DSP-2M-7-1-04-A is programmed directly in the Selec Selpro software under the HMI drop-down. When the HMI is selected in the dropdown, it will bring up a new screen that will show the HMI that was selected when the program was created on the right and a Page Properties tab on the left. This Page Properties tab is where you can name the page, give a description of the page, set up local events, and set up the LEDs.

To edit the HMI’s pages, click on the Edit Page button at the top left of the screen, which will allow changes to be made to the first page of the HMI screen. In edit mode, clicking the Local LED section will bring up a pop-up window that will allow changes to the LEDs on the HMI. This window is where the global variables are set for each LED as well as whether the LED is set to stay on or blink and at a set speed. Clicking on the image of the 7-segment display will change the Information tab on the left so that the 7-segment display can be edited. This tab is where the value being used for the display is set, the format of the display setup, and the type of characters used for the display.

When done editing the page, click the Save Page button icon to save the edits made to that page of the HMI. To add more pages to the HMI, select Add a New Page, which can be done at the top left of the page by clicking on the green plus symbol or, when done editing a page, clicking the green arrow, which will save the changes made to that page and add a new page to the HMI.

Tech Tip: There are 2 save buttons in the HMI programing page one is to save the program and the other is to save the page you are editing.

LEDs

Along with displaying the count on the HMI, the program is also set up to show the count on the six LEDs at the bottom of the HMI. To do this, each individual LED has to have its own global Boolean variable to activate the LED when it is called in the main program. The next step in the main program is to set up six individual Equal blocks, one for each of the LED variables used in the HMI program. To activate the LED variables, an equal block is set to activate its output when the output from the counter block equals a preset number variable. This number variable is set to be the same number as the number printed above the LED on the HMI of the PLC.

An alternative program that could be used for the LEDs is a binary counter, and it would use the same concept as this LED program. The difference would be how many of the LED variables are called at a time for each equal block instead of only a single output for each block.

Programing the PLC.

Now that the program has been written, the next step is to get it downloaded into the PLC itself. With the PLC connected to the computer, you will need to have the power off to your PLC, press and hold the ENT button on the HMI, turn the power on to the PLC, and wait 3 seconds before releasing the ENT button. The reason you have to do this is to bring the PLC into its Bootloader mode so that the program can be downloaded.

The next step is to compile and download the program to the PLC, and you can do it one of two ways. The first way is to compile the program using the Compile button or F5, then download the program using the drop-down menu or pressing F3. The second way is by selecting Compile and Download in the Download drop-down menu or pressing F7.

Once the download starts, the HMI will show DNLD on the 7-segment display, and you can see the progress of the download by looking at the LEDs on the HMI as they will move from left to right like a normal status bar. When the download is complete, the HMI and its LEDs will change to match the home screen of the program that has been downloaded. There is no need to restart the PLC once the program has been downloaded because it will automatically close the Bootloader mode and go back to the normal run mode.

Tech Tip: read the operating instruction of the HMI you are using since each HMI has a different way to enter the bootloader mode. The MIBRX-DSP-2M-7-1-04-A operating instructions

The Completed Project

With the program downloaded, you can now disconnect the programming cable from the PLC and the PC. When you look down at the HMI, you should see a 0 on the 7-segment display, and none of the LEDs should be illuminated. If everything is working correctly, when you push the green button, the count will go up, and the LEDs on the HMI will move from left to right, matching the number on the HMI to the LED number. When you push the red button, the count will go down, and the LEDs on the HMI will move from right to left, matching the number on the HMI to the LED number. When you turn on the selector switch, you will see that the 7-segment display resets to 0, all the LEDs on the HMI will turn off, and the red panel light will illuminate

The downloaded program shows a up count and reset of the count.

Summary

This article covered difference between the various counter blocks that can be used in the Selpro software, how each counter block works, and the variables the counter blocks use. It also explained how to write a basic counter program in Selpro and how to download that program into the Selec MIBRX PLC. The article explained how to program the HMI in the Selpro software and how variables can be used between the main program and the HMI program. More to come in future articles about the different Selec MIBRX PLC modules, using different function blocks in the Selpro software, and using different types of sensors for inputs to the Selec MIBRX PLC.

About this author

Anthony Fish is a passionate and skilled technician with five years of experience in the electronics industry. He graduated from Northland Community & Technical College with a degree in electronics technology and automation systems. Fish is currently working as an electronics technician at DigiKey, with a focus on automated and industrial control systems. He enjoys the challenge of answering your technical question via phone, chat, or this forum.