Application of the easyE4 programmable relay to build people counter.
- Programming in the FBD language
- EasyE4 and easySoft 7 connection
- Developing a new project in the easySoft 7 environment
- easySoft 7: Program development – display operation, activating buttons
- Resetting the CURRENT counter value back to zero.
- Setting the permitted number of people
- Programming the easyE4 relay
In the previous article dedicated to Eaton’s easyE4 controller, we have proposed how to build a people counter and briefly presented what the new relay can offer.
This time we will focus on the development of the application and its launch. The first necessary step is the download and installation of the easySoft 7 programming environment. In this article, we won’t present all of the options available in the menu. Instead, we will focus on the counter design itself, so if the actions described require any additional information, you should visit the website of the manufacturer of the controller or consult one of numerous manuals shared online by its users.
Programming in the FBD language
In order to develop the counter application, we chose the FBD language, as it’s the easiest one to comprehend the logic applied in the program and the connections between individual modules. Understanding this method requires of the programmer the knowledge of digital features (logic functions), such as logic gates, registers and flip-flops.
The FBD language available in the easyE4 environment differs from the one we encounter in competitive products e.g. Siemens Logo! or Mitsubishi Alpha. It requires more thought-out program development, because in terms of structure it consists of interconnected, single networks exchanging data via references or markers. Since the networks are rather small, it is easy to introduce changes in the program. On the other hand, outputting the signal (outside the network) requires adding a marker and reading it by another network. When it comes to the competitive solutions, you only need to draw a line, while the FBD layout resembles a circuit diagram.
After this introduction, let us begin the development of a people counter program. Let us divide our work into several stages, which will allow us to add subsequent elements and gradually monitor the results.
- The first step will show how to display messages on the screen embedded in the easyE4 controller and how to use the buttons mounted on the front panel. Here, we will show you how static and dynamic texts are displayed, including input and output status, counter values and the like.
- The second step will explain the method of operating the cursor buttons mounted on the controller, and we will provide an example method of entering counter settings and limiting their values. Additionally, we will describe the modules of the counter, the comparator, the logic gate, as well as contacts and coils (inputs and outputs).
- The third step will describe the logic of the counter. Here, we will also develop a movement direction detector. This is the most difficult part of the task, as we need to predict many situations which may occur during the use of the device. Unfortunately, with such unsophisticated sensors as light barriers, one can’t be protected against everything that the user might do, and thus error-free operation of the counter cannot be guaranteed.
The whole program can be developed and checked with the help of a simulator embedded in the easySoft 7 programming environment without the need to use the programmable easyE4 relay offered by Eaton.
Connecting easyE4 and easySoft 7
The computer that we applied to develop the program used two network interfaces: wireless Wi-Fi to connect with the home network, and Ethernet to program the easyE4 controller. In order to avoid connectivity problems, the IP v4 addresses of the Ethernet interface were entered manually:
- PC address: 10.10.0.5.
- EasyE4 relay address: to 10.10.0.2.
- Shared 8-bit subnet mask 255.0.0.0 (/8) and gate: 10.10.0.1.
Of course, the PC was connected via an Ethernet cable, “straight on” from socket to socket, and there was no gate in the network. However, remember that the newest version of Windows does not allow to enter only the IP address and the mask.
EasyE4 settings menu is available in the stop mode, after pressing OK. You can choose the options with up/down arrow keys, confirm with OK, and cancel (quit or leave the current menu) with the ESC key.
By default, easyE4 works in an automatic setup mode. In order to enter the IP address manually, you need to use menu SYSTEM.OPT –> ETHERNET –> ADDRESS MODE and choose STATIC IP. Now, the address can be entered using a higher level menu, that is IP ADDRESS. In this menu, there are other items that can be entered manually: IP ADDRESS (just to remind you – 10.10.0.2), SUBNET MASK (CIDR Suffix: /8, i.e. 255.0.0.0), GATEWAY ADDRESS (10.10.0.1). You can omit the DNS SERVER parameter.
If the Windows system requires the DNS address, enter the one used for the gate, that is 10.10.0.1. In fact, it doesn’t really matter, because for our application we only need the Ethernet to program the relay and we will most likely not be interacting with it in a vast network with a server translating the name into an IP address.
Connect the PC to the easyE4 relay and run the easySoft 7 programming environment. After that, you can also set up the relay with the help of the easySoft menu.
Developing a new project in the easySoft 7 environment
When developing a sample program, we used the easyE4 controller version with transistor outputs. After it is launched, the easySoft 7 development environment opens a list of basic devices on the left. There, you can choose the type of your controller – in our example it’s EASY-E4-DC-12TC1. Click on its name and, with the left mouse button pressed, drag it to the right, to the “Project” tab. You will see a window saying: “Add new device” (figure 1), in which you have to choose the version of the firmware. In the case of easyE4 used in this example, it was the V1.0 version.
EasyE4 relay firmware selection box
The selection of firmware should be well thought-out, because further downgrades are not possible. Developing a program for newer firmware usually entails better functionality, but when it’s newer than the one installed in the controller, it cannot be sent and launched. In such a situation, you will have to update the firmware of the device. |
In order to check which version of firmware is supported by our programmable relay, you need to use the following menu: easyE4 INFORMATION –> SYSTEM. It will display a screen with the basic information regarding the relay, including the type and version of firmware (OS). The relay parameters can be also viewed using easySoft 7, but in order to do it, you will need to find the controller on the Internet and go into an online mode.
Once you have chosen the model of the programmable relay and the version of its firmware, a graphic illustrating the chosen model will be displayed in the Project tab. Now, you can begin the development process.
easySoft 7: Program development – display operation, activating buttons
Four buttons, allowing the easy choice of the operation mode, are located in the bottom right corner of the easySoft 7 window. If you want to edit the program click Programming, to simulate its operation click Simulation, to forward it to the relay choose Communication, and in order to make changes to the relay network or enter their parameters click Project.
In order to create a program, click Programming. During the first launch, a box will be displayed asking the user to choose the programming method. Select Function Block Diagram (FBD) and click OK (figure 2). Next time, the development environment will simply allow you to edit the program.
Programming method selection box
To begin with, let’s develop an information screen. On the manufacturer’s list of modules located on the left side of the screen, find Other function blocks –> D – Text display. Click on its icon and, with the left mouse button pressed, drag it to the white space, which should be displayed on the top of the screen as no. “0001”. This is our first step to create a program in a new environment, so in order to make things easier, check what the result will look like in figure 3.
Text display function block placed in the network no. 0001 tab.
The text display function block is used for displaying messages for users. The messages might be static or dynamic, contain markers, values, symbolic constants, progress bar, etc. For example, the logic level of the output or input might be signalled only by a square symbol or a symbolic constant (e.g. ON/OFF) defined by the programmer. The relay manufacturer made sure that Polish characters are available as well, which makes the user communication more comprehensible and demonstrates manufacturer’s attention to detail.
When developing the program, you may need to use many text display function blocks, so they are turned on/off by the EN input. In this example we will only use one screen with dynamic messages, so the module can be activated by connecting a static logic level “1” to the EN input. To do so, locate Contacts –> Constant 1 on the list, and then drag the icon and drop it on the EN input of the D01 module. The result should be as shown in figure 4.
Connecting a logic value “1” to the text module of the EN input.
After clicking on the D01 block, already placed in the first network of the program, the parameters of the block will be displayed in the lower section of the screen. We only use a single message block, so there’s no need to set any parameters on this screen, except for activating the “P” buttons. We will use the (P1…P4) cursor and DEL (P7) buttons, tick the squares located next to them. That is not enough to activate the buttons, but it will allow us to use them when the interlinked text display function block is active, which is a very useful feature of the block.Sometimes, when a user doesn’t know what to press, they will enter some random menu options. Here, the user can be allowed to e.g. use the cursor buttons and refused access to the rest.
In our counter program, the buttons will have the following functions: left/right – decreasing/increasing the permitted number of people, up/down – decreasing/increasing the current counter value, DEL – resetting the number of the people counted. Resetting will also be possible with the use of the I08 input of the relay, to which we will add a proper button. It is more convenient for the user than searching for the small buttons on the relay panel. What is more, it protects the device from being accidentally damaged.
In order to display the messages on the screen, click on the Text display editor button located in the text display parameters (bottom of the screen). The editor box with a proposed appearance of the counter screen is illustrated in figure 5. You won’t be able to enter all of the values yet, because you have just begun to develop the program and variables don’t exist yet, but you can place static messages on the screen.
The proposed appearance of the counter during operation
In order to put the “PEOPLE COUNTER 1.1” message on the top of the screen, click on the Static text on the left of the displayed box and drag it to the desired place on the screen – here, to the first line of the display. Then, in the lower section of the screen, in the Text box, enter “PEOPLE COUNTER 1.1” .Click on the text box that you’ve just added to the screen and, using the markers in the corners, extend it so that the text fits in screen. In the same way, put the remaining messages in other boxes, the messages being a horizontal line consisting of “-” characters and the “CURRENT:”, “PERMITTED:”, “ENTER:” label. Finish this stage by clicking OK. Dynamic text messages will be defined in the following steps.
Resetting the CURRENT counter value back to zero
The people counter can be reset or adjusted with buttons. In order to reset the device, we will use the NO type button connected between +24 V DC current and the I08 input of the easyE4 controller or the DEL button on its panel. We create a network generating the reset signal as follows:
- Use the right mouse button to click on the white box of the 0001 network containing the message you want to define. Select Insert network after(Ctrl+T).
- Move the Contacts–> Make icon to an empty, newly open network.
Contacts are nothing but inputs of the controller. The “make” or NO contact is the NO input, while the “break” or NC contact is the NC input. We have already been acquainted with symbolic constants (we have Constant 1 and Constant 0, corresponding to the high/low logic levels). In the program, Analog contact will allow us to enter the values of settings’ thresholds.
- Click on the block placed in the network. At the bottom of the screen, an input parameter box will open, in which you need to set:
- Type: Bit inputs/outputs and markers.
- Comment: DEL.
- Bit logic: Make.
- Operand: P-Device button.
- Number: 7-DEL.
- Move the OR gate to the output of the P07 block. The gate can be found in Logic gate–> OR.
- Move another “Make” contact to the input of the gate – it will be the I08 input of the relay. Click on the block and set the following parameters in the same way as in the case of the previous contact:
- Type: Bit inputs/outputs and markers.
- Comment: External button.
- Bit logic: Make.
- Operand: I – Input.
- Number: 8.
- Move the Coils–> Contactor icon to the output of the gate. Click on the block and set the following parameters:
- Type: Bit outputs and markers.
- Comment: RESET C02.
- Coil function: Contactor.
- Operand: M – Marker.
- Number: 3.
Contacts are nothing but outputs, physical or logic, connected only within the program. For this program, we will only be using: Contactor – bit NO output, Negated contactor – bit NC output. Using the program’s functions, we have created an internal marker – a virtual output, which can be connected within the remaining blocks.
In the network tab, you can add a description, which will later, along with the comments put next to contacts and coil names, make it easier for us to analyse the program and remember the functions of the individual signals. The description is best added by using the Ctrl+R shortcut. The current result should look like figure 6.
Beginning of the counter program – networks 0001 and 0002
Entering the permitted number of people
The counter will add people entering the room or zone to the current value and it will deduct individuals leaving. The value counted will be compared to the pre-set, permitted number of people, and the outcome of the comparison will control the Q1/Q2 outputs connected to the signalling devices: Q1 – red, Q2 – green (or to a relay which turns on/off the heating, ventilation, lighting, etc.).
The permitted number of people will be set with the use of the “left”/“right” arrow keys, so it’s easiest to use a bidirectional counter which stores the value entered. In this way, the “left” key could decrease and the “right” key could increase the counter value by 1.
We can use this method in our program, as among the modules we can find Counter modules –> C – Counter module which can count up and down. For this purpose, it was equipped with a C_ clock input path and a D_ counting direction input path. There are other functionalities, too, but we don’t need them at this stage. In one of the subsequent networks, we will also use the RE input, which resets the counter value.
We add a new network by using Ctrl+T. Its development needs to be started in the counter block, because we will channel individual signals to its inputs. On the list, we need to find Numerical function blocks –> C – Counter relay. Place it in the network no. 0003 tab. Click on the block and type PERMITTED in the Comment box. It will simplify the identification of the module during the later stages of development. Connect the OR gate to the pulse counter input _C, because the value decreasing/increasing pulses will come from two buttons, and we have only one clock input path. Whether we add or subtract is decided by the logic level on the direction input.
You need to connect the buttons which decrease/increase of the counter value to the OR gate inputs. The counter has a high, 2-byte capacity. It allows to count values within the range of 0…65535. For this counter application, it was estimated that the permitted number of people won’t exceed 1000. If needed, it can be easily changed by way of modifying the constant that is available in the program. Setting the range below 0 also doesn’t make sense – it’s useless to do so. On the other hand, a figure below 0 causes a counter overflow and sets the value to maximum. That is why it seems logical to enter certain limitations in the program, which will cause the setting range to extend from 0 to maximum, and the program won’t allow the threshold values to be exceeded by the person entering the settings.
Since we are dealing with a counter, we can use the so-called gating to block the counting inputs. Gating is well known to those who have ever built a frequency meter. When gating is applied, the signal is put through a logic gate – usually AND, which is only “transparent” when the gating input has a high logic level.
In the depicted network, two AND gates were used, with one of them having two signal gating inputs (CO1>0 and C01< CONSTANT) and the other one having one input (C01>0). You need to connect the output of the first AND gate to one of the inputs of the OR gate. It is easy to notice that something is missing here, as there are only two inputs on the gate, while we need three of them (two gating signals and the button). In order to add another input, click “+” on its symbol – every click will add one input (and every click on “-” will remove one).
We will connect the button for decreasing the counter value (left) to the first input of the gate. In order to do it, put a contact at the input of the AND gate, click on it and set the following parameters:
- Type: Bit inputs/outputs and markers.
- Comment: LEFT.
- Bit logic: Make.
- Operand: P – Device button.
- Number: 1 – <.
Next, we need to add two contacts to the remaining, free AND gate inputs and set their parameters:
- Contact at the second AND gate input:
- Type: Bit inputs/outputs and markers.
- Comment: C01 < CONSTANT.
- Bit logic: Make.
- Operand: M – Marker.
- Number: 2.
- Contact at the third AND gate input:
- Type: Bit inputs/outputs and markers.
- Comment: C01 > 0.
- Bit logic: Make.
- Operand: M – Marker.
- Number: 1.
Here, you need to add an AND gate to the button output to block the button’s operation when the value set is lower than 0 or higher than the maximum permissible value.
Next, just to be safe, you have to put an AND gate at the D_ input of the C01 counter (PERMITTED). It will block down-counting, if 0 is reached. In theory, a gate like that is not needed, but it has been added for the safety of application, so that the direction change input is also blocked even when the “left” arrow key is pressed. Connect two contacts to the AND gate inputs and set their parameters in the following manner:
- Contact on the first AND gate input:
- Type: Bit inputs/outputs and markers.
- Comment: LEFT.
- Bit logic: Make.
- Operand: P – Device button.
- Number: 1.
- Contact on the second AND gate input:
- Type: Bit inputs/outputs and markers.
- Comment: C01>0.
- Bit logic: Make.
- Operand: M – Marker.
- Number: 1.
The effect of our work is presented in figure 7. The next step will be to create a network with a comparator that will monitor the settings entered into the counter.
Network no. 0003 – counter storing the permitted number of people
By pressing Ctrl+T, add the network no. 0004. We will use it to compare whether the counter value (setting) is higher than 0. First, we place the comparator block, which can be found in: Manufacturer function blocks –> Arithmetic and analogue function blocks –> CP – Comparator. Now, connect two analogue contacts to the comparator inputs (Contacts –> Analog contact), and the coil to the GT output. Now, in an already familiar manner, by clicking on the contacts and coils, set their parameters:
- Contact on the first comparator input:
- Type: Function block outputs.
- Comment: PERMITTED.
- Bit logic: Make.
- Operand: C – Counter module.
- Number: 1.
- Function block outputs: QV – Analog output of the function block.
- Contact on the second comparator input:
- Type: Constant.
- Constant: 0.
The comparator has 3 outputs: LT – active (status 1), if I1 < I2, EQ – active, if I1 = I2, GT – active, if I1 > I2. In our application, we will use the active GT output, if the input value I1, and therefore the counter value C01 (PERMITTED), is higher than 0. Now, place a coil at the GT comparator output and set the following parameters:
- Type: Binary outputs and markers.
- Comment: C01>0.
- Coil function: Contactor.
- Operand: M – Marker.
- Number: 1.
Similarly, let’s create a network which will check whether the entered setting is lower than the maximum value. To make things simpler, you can use the copy-paste method.
Click Ctrl+T and create a network no. 0005. Move to network no. 0004 and select the network components by pressing the left mouse button and drawing a rectangular box. Then, press Ctrl+C and move to the still empty network no. 0005. There, press Ctrl+V. Unfortunately, this time we will use the LT output, so you must remove the coil connected to the GT output, drag a new one and connect it to the LT output. Now, you only need to enter the values of contacts and the coil connected to the output.
Thanks to the copy-paste method, the contacts should have the right parameters. You only need to change the constant value and enter e.g. 1000 instead of 0, the former being the maximum permitted number of people that can be set. Now, let’s deal with the coil connected to the comparator’s LT output and set the following parameters:
- Type: Binary outputs and markers.
- Comment: C01 < Constant.
- Coil function: Contactor.
- Operand: M – Marker.
- Number: 2.
The effect of our work should look like the one illustrated in figure 8.
Networks with comparators maintaining the setting within the range of 0…maximum
We need to explain how to control the C01 (PERMITTED) counter block. Increasing the value of the block is obvious – we need to direct the pulses to the C_ input. Decreasing means that we need to additionally provide a logic “1” to the D_ input. When it comes to hardware solutions, e.g. executed with the 74193 counter, it was often enough to just feed the same pulse to the counter direction input and clock pulses, but in the case of the former one it was straight-away, while in the case of the clock input it was slightly delayed e.g. with two gates connected in series. The same output was used to feed the pulses from the buttons to the counter block: the pulse from the P01 coil is transmitted through two gates to the C_ input and through one gate to the D_ input. It turns out that the execution of logic elements by the program also generates the necessary delay and works great on the FBD.
The next article will explain the operating principles of the people counter and the methods of detection of movement direction. At this stage, the next step is to create one more network, put only one unconnected counter block there, set its parameters and return to the information screen, finish your work and test the application by forwarding the program to the relay.
You need add the network no. 0006 (Ctrl+T). Next, drag the counter from the list of blocks (Manufacturer function blocks –> Numerical function blocks –> C – Counter relay) and set the following parameters:
- C: 2.
- Comment: CURRENTLY (IN THE ROOM)
- No EN is needed to release the function block.
Now, return to network no. 0001, click on the text display function block and then on the “Text display editor” button. Here, add to the previously saved messages the display of the current value of both counters and the Q1 output, to which the red light is connected.
From the list on the left side of the editor, select Value display and move it to follow the colon after the “CURRENT:” label. A box showing number 99999 will be displayed. Now, at the bottom of the box, select the Associated variables tab and enter the following values into the boxes:
- Type: Function block inputs and outputs.
- Operand: C – Counter relay.
- Number: 2 – >>CURRENTLY (IN THE ROOM)<<.
- Function block inputs and outputs: QV – Analog output of the function block.
Now you need to do exactly the same for the “PERMITTED:” box/label. Put the Value display to follow it, and then, in the Associated variables tab, we set the following parameters:
- Type: Function block inputs and outputs.
- Operand: C – Counter relay.
- Number: 1 – >>PERMITTED<<.
- Function block inputs and outputs: QV – Analog output of the function block.
As a caption to follow the “ENTER:” label we will display YES, if it is permitted, or NO, if it’s not. In order to do so, we have to select Message text from the list and place it to follow the colon of the label. Then, extend the box to 3-4 characters and set its values, as shown in figure 9:
Message text box setup
- Tab Message text:
- Type: Bit.
- Language selection: Untitled.
- Display type: Normal.
- Mode: Exact value.
- Variable type (table): Status value: 0, Message text: YES; Status value: 1, Message text: NO.
- Tab Associated variable:
- Type: Bit inputs/outputs and markers.
- Operand: Q – Output.
- Number: 1.
Programming the easyE4 relay
We only need to set one more option. The need for it to be switched on would be signalled at the stage of program inspection, but in order to save time, we will handle it right now. In the left bottom corner of the box, click on the Project button and select the System settings tab. On the right side, find the P buttons box and tick the square located next to it. In this way, we have activated a bit, which allows us to use the buttons on the relay panel.
Now, you can check whether the fragment of the program we you developed works or not. To do so, click the Programming button in the bottom left corner and in this way return to the program editor. Next, by pressing F10, you can perform a plausibility check on the program. An error-free message should be displayed, containing some warnings at the most. A program like that can be sent to the easyE4 controller.
For this purpose, click on the Communication button in the bottom left corner of the screen. Then, having the IP v4 protocol parameters set in the controller and in the PC, click on the Search button. In the box on the right, select the Ethernet interface, to which the relay is connected, and then select New search on the left. We need to wait for the operation result, which will be displayed in a table. We click on the located item and on the Save as IP profile button. A message about a new profile with the address/name 10.10.0.2 and the time and data of its creation should be displayed. Click OK to close the message box and Close in order to close the search box (figure 10). On the left, in the top part of the screen, if the newly created profile is not displayed in the IP profile box, select it from the list and click on the Online button – to connect to the controller.
A search box for finding a relay withing the Ethernet network
Now, by clicking on the Program/Configuration list, and then on PC => Device , you can send the program to the relay. Finally, if a message asking to run the program is not displayed, click on the RUN button and run the program you’ve developed. At this stage, you may test its operation using the cursor buttons and the DEL button. The I08 resetting input should also work.
We encourage you to see the article devoted to the possibilities offered by the EasyE4 controller.
Text prepared by Transfer Multisort Elektronik Sp. z o.o.
The original source of text: tme.eu