# RAMP function for automation

Ramp processes are most often used where there are temperature control tasks. When the temperature of an oven or any other device cannot be quickly heated or cooled by technology. I used such functions in the work of greenhouse complexes, when drying and firing bricks, when hardening metal products, in fruit ripening systems. We do not control the variable of the object itself, but we work with the value of the regulator, which regulates the temperature of the object with the help of tens, gas or other control methods.

In this article I will share a method of programming the RAMP function for linearly incremented technological processes. When it is necessary to increase or decrease the set value from the initial value to the final value for a given time interval or at a given speed, for example 2C per hour. It is important to note here that for this function to work correctly, we need a variable associated with the controller's system time. The variable is constantly changing in the code of this block. The launch process itself is based on memorizing the start time and calculating the time until which the function will follow. This program code is taken from a program written for Codesys 2.3, but with minor modifications it will work in other systems where the ST (Structured Text) language is implemented in accordance with the standard. The block begins with an ad. Be sure to comment your code. This will reduce the security of your solution, but will increase clarity and readability.

FUNCTION_BLOCK TE_CALC_SP
VAR_INPUT
TE_SP_1: REAL; (* The value we started with *)
TE_SP_2: REAL; (* The value we are going to *)
SPEED: REAL; (* The speed at which we must reach the set value *)
END_VAR
VAR_IN_OUT
START: BOOL;
END_VAR
VAR_OUTPUT
OUT: REAL; (* Output variable that is linked to the setpoint *)
State: INT; (* The number of the step we are at *)
Complite: BOOL; (* We set the flag that the ramp has finished *)
START_TIME: TIME; (* Time when the count is expected to end *)
FINISH_TIME: TIME; (* Time when the count is expected to finish *)
END_VAR

VAR
TIME_MAIN: TIME; (* Total ramp time *)
First: REAL; (* Initial value of the interval *)
Second: REAL; (* End value of interval *)
GRADUS: REAL; (* Calculate the difference in degrees *)
TON2: TON; (* Timer from hovering in the transition stage through 0 *)
Cur_Timei: DWORD; (* To calculate the transition through 00: 00: 00 *)
AM: REAL; (* Difference between setpoint and process variable *)
OS: REAL; (* Value of the process variable at the beginning of the function *)
Err: REAL; (* Decreasing error *)
tx: TIME; (* PLC current time *)
tx1: TIME; (* Remember the PLC time at the beginning of the count *)
txr_diff: REAL; (* Cumulative time in REAL format *)
fr: REAL; (* Calculated increment factor, tilt angle *)
R_TRIG: R_TRIG; (* Catch the transition, the end of the RAMP *)
END_VAR

Now a little about the code of this function block. The code is executed on the CASE statement, which is convenient for implementing a state machine. This is when at any given time some part of the program code is executed, and all the rest of the program code is in a waiting state. It is possible to make various flexible combinations like the SFC language. The transition from step to step is controlled using the integer variable State

CASE State OF
0: (* At this step we stand and wait, initialize the variables *)
OUT: = TE_SP_1; (* Assigning an initial value to the output *)
START_TIME: = T # 0m; (* Resetting the initial time *)
FINISH_TIME: = T # 0m; (* Zeroing the end time *)
IF START THEN State: = 1; END_IF; (* If the start button is pressed, then go to the next level *)

1: (* Determine the start time of the function, calculate the time and move on *)
Complite: = FALSE; (* Reset the end sign *)
GRADUS: = ABS (TE_SP_2 - TE_SP_1); (* Calculated how many degrees are the difference *)
First: = TE_SP_1; (* Memorized the first number *)
Second: = TE_SP_2; (* Memorized the second number *)
txr_diff: = 1; (* Assign 1 to the variable that is responsible for the slope of the function *)
TIME_MAIN: = (REAL_TO_TIME (GRADUS / SPEED) * 1000 * 60 * 60); (* Calculate how long it takes to increment the function *)
fr: = txr_diff / DINT_TO_REAL (TIME_TO_DINT (TIME_MAIN)); (* Time over which the function should increase or decrease. Calculates the increment / decrement factor *)
tx: = T # 0s; (* Zero the time increment *)
Err: = 0.0; (* Zero out the mismatch increment *)
AM: = Second - First; (* Calculated the distance in degrees between two points *)
OS: = First; (* Remember where we are coming from *)
tx1: = PLC_TIME; (* Remember the time before the start of the ramps *)
START_TIME: = PLC_TIME;
FINISH_TIME: = PLC_TIME + TIME_MAIN;
State: = 2;

2: (* Make RAMP from first to second point *)
tx: = PLC_TIME; (* Time accumulates cyclically *)
txr_diff: = DINT_TO_REAL (TIME_TO_DINT (tx)) - DINT_TO_REAL (TIME_TO_DINT (tx1)); (* Difference between memorized time and current *)
fr: = txr_diff / DINT_TO_REAL (TIME_TO_DINT (TIME_MAIN)); (* Time over which the function should increase or decrease. Calculates the increment / decrement factor *)
IF First <Second THEN Err: = Second - OUT; END_IF; (* 0-growth *)
IF First> Second THEN Err: = OUT - Second; END_IF; (* 1-drop *)
OUT: = AM * fr + OS; (* General linear dependence *)
R_TRIG (CLK: = Err <0); (* Waiting for zero crossing *)
IF R_TRIG.Q THEN State: = 3; END_IF;
IF NOT START THEN State: = 3; END_IF;

3: (* Rump worked *)
OUT: = TE_SP_2; (* Leave the second value at the output *)
START_TIME: = T # 0m; (* We render time variables *)
FINISH_TIME: = TIME_MAIN; (* We render time variables *)
Complite: = TRUE; (* We expose a sign that completed *)

IF NOT START THEN State: = 0; END_IF; (* Return, if the START button has stopped working, to step 0 *)
END_CASE;
END_FUNCTION_BLOCK

#RAMP, # Rampfunction, #Heatingcontrol
Ваш комментарий добавлен

Возврат к списку