When you are doing mathematical calculations in a PLC program, you need to understand how to derive proper answers and get the desired result. Accordingly, the logic will help in keeping the calculations and answers intact.
One of the most preferred languages in PLC programming for writing equations is structured text. This is because the syntax and instruction suits them the best. In this post, we will write a sample program on how to generate output based on equations using structured text language.
Output Generation via Equations
Let us understand the case scenario first. There is a PLC digital output and two PLC inputs – one analog and one digital. The PLC output is controlled through formulae.
The analog input has a range of 0-100%. When the value of that input is more than 30%, a fixed value of 4 is added every 5 seconds.
After addition, when this value becomes more than 20, then the output turns on and the value is subtracted with a fixed value of 4 every 5 seconds. It will subtract till 0 and then, the output turns off.
Again, the cycle continues for addition and subtraction. During this sequence, if the value of the analog input goes less than 30%, then the whole cycle stops. The digital input is an emergency button, which when received, will reset the whole cycle.
PLC Structured Text Program
Now, we will write the logic for the same. Refer to the below image. We take a common timer of 5 seconds for the whole logic.
The timer runs when the value of analog input is more than equal to 30 and the emergency input is healthy. We use the negate done bit of timer for making the timer self reset and run again.
Now, when the timer is done and the value has not reached 20 yet, then the value is added with 4. For checking whether the value of 20 has been reached or not, we use a bit add_done with negate condition.
When the value becomes 20, we set the bit add_done and turn on the motor output, by writing a value of 1 to them.
Now, when the timer is done and the value has not reached 0 yet, then the value is subtracted with 4. For checking whether the value of 0 has been reached or not, we use the bit add_done.
When the value becomes 0, we reset the bit add_done and turn off the motor output, by writing a value of 0 to them. Due to this, the second condition is activated once again and the cycle repeats.
In any instance, when the value of analog input becomes less than 30 or if the emergency is pressed, then all the bits and values are reset and the cycle becomes zero.
We have used if-else statements in the whole program for execution. Due to this, the logic becomes easier to write and understand.
In this way, we saw how to operate a PLC output using equations in structured text language.
Read next:
- Structured Text for two-tank level application
- Tanks Draining Control in PLC Programming
- Functional Block Diagram for Oil and Water Logic
- Structured Text for Measuring Event Duration
- PLC FBD Example for Tank Liquid Heating Logic