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.

Линейно-временная функция RAMP
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
Array
(
    [ID] => 504
    [IBLOCK_ID] => 1
    [NAME] => Ramp function on process
    [IBLOCK_SECTION_ID] => 
    [IBLOCK] => Array
        (
            [ID] => 1
            [~ID] => 1
            [TIMESTAMP_X] => 14.10.2021 23:54:30
            [~TIMESTAMP_X] => 14.10.2021 23:54:30
            [IBLOCK_TYPE_ID] => EN
            [~IBLOCK_TYPE_ID] => EN
            [LID] => s2
            [~LID] => s2
            [CODE] => articles
            [~CODE] => articles
            [API_CODE] => 
            [~API_CODE] => 
            [NAME] => Articles
            [~NAME] => Articles
            [ACTIVE] => Y
            [~ACTIVE] => Y
            [SORT] => 10
            [~SORT] => 10
            [LIST_PAGE_URL] => /articles/
            [~LIST_PAGE_URL] => /articles/
            [DETAIL_PAGE_URL] => /articles/#ELEMENT_CODE#.html
            [~DETAIL_PAGE_URL] => /articles/#ELEMENT_CODE#.html
            [SECTION_PAGE_URL] => 
            [~SECTION_PAGE_URL] => 
            [CANONICAL_PAGE_URL] => https://lapshinvr.com/articles/articles.html
            [~CANONICAL_PAGE_URL] => https://lapshinvr.com/articles/articles.html
            [PICTURE] => 
            [~PICTURE] => 
            [DESCRIPTION] => 
            [~DESCRIPTION] => 
            [DESCRIPTION_TYPE] => html
            [~DESCRIPTION_TYPE] => html
            [RSS_TTL] => 24
            [~RSS_TTL] => 24
            [RSS_ACTIVE] => Y
            [~RSS_ACTIVE] => Y
            [RSS_FILE_ACTIVE] => N
            [~RSS_FILE_ACTIVE] => N
            [RSS_FILE_LIMIT] => 
            [~RSS_FILE_LIMIT] => 
            [RSS_FILE_DAYS] => 
            [~RSS_FILE_DAYS] => 
            [RSS_YANDEX_ACTIVE] => N
            [~RSS_YANDEX_ACTIVE] => N
            [XML_ID] => 
            [~XML_ID] => 
            [TMP_ID] => 
            [~TMP_ID] => 
            [INDEX_ELEMENT] => Y
            [~INDEX_ELEMENT] => Y
            [INDEX_SECTION] => N
            [~INDEX_SECTION] => N
            [WORKFLOW] => N
            [~WORKFLOW] => N
            [BIZPROC] => N
            [~BIZPROC] => N
            [SECTION_CHOOSER] => L
            [~SECTION_CHOOSER] => L
            [LIST_MODE] => 
            [~LIST_MODE] => 
            [RIGHTS_MODE] => S
            [~RIGHTS_MODE] => S
            [SECTION_PROPERTY] => N
            [~SECTION_PROPERTY] => N
            [PROPERTY_INDEX] => N
            [~PROPERTY_INDEX] => N
            [VERSION] => 1
            [~VERSION] => 1
            [LAST_CONV_ELEMENT] => 0
            [~LAST_CONV_ELEMENT] => 0
            [SOCNET_GROUP_ID] => 
            [~SOCNET_GROUP_ID] => 
            [EDIT_FILE_BEFORE] => 
            [~EDIT_FILE_BEFORE] => 
            [EDIT_FILE_AFTER] => 
            [~EDIT_FILE_AFTER] => 
            [SECTIONS_NAME] => 
            [~SECTIONS_NAME] => 
            [SECTION_NAME] => 
            [~SECTION_NAME] => 
            [ELEMENTS_NAME] => Элементы
            [~ELEMENTS_NAME] => Элементы
            [ELEMENT_NAME] => Элемент
            [~ELEMENT_NAME] => Элемент
            [REST_ON] => N
            [~REST_ON] => N
            [EXTERNAL_ID] => 
            [~EXTERNAL_ID] => 
            [LANG_DIR] => /
            [~LANG_DIR] => /
            [SERVER_NAME] => lapshinvr.com
            [~SERVER_NAME] => lapshinvr.com
        )

    [LIST_PAGE_URL] => /articles/
    [~LIST_PAGE_URL] => /articles/
    [SECTION_URL] => 
    [CANONICAL_PAGE_URL] => https://lapshinvr.com/articles/ramp-function.html
    [SECTION] => Array
        (
            [PATH] => Array
                (
                )

        )

    [IPROPERTY_VALUES] => Array
        (
            [ELEMENT_PREVIEW_PICTURE_FILE_NAME] => ramp function on process
            [SECTION_META_TITLE] => Automation articles 
            [SECTION_META_KEYWORDS] => Automation, Articles 
            [SECTION_META_DESCRIPTION] => I met something worthy of attention during the work. It is difficult to assess the necessity of posting this or that article, I tried to clean up the obvious garbage
            [SECTION_PAGE_TITLE] => Here I published articles that may be useful to someone in the production of work
            [ELEMENT_META_TITLE] => Ramp function 

            [ELEMENT_META_KEYWORDS] => Ramp function, RAMP, Heating Control
            [ELEMENT_META_DESCRIPTION] => Description ST program code for implementation of the ramp function on heating control. You can download a ready-made working example
            [ELEMENT_PAGE_TITLE] => RAMP function for automation
        )

    [TIMESTAMP_X] => 16.11.2021 06:39:01
    [META_TAGS] => Array
        (
            [TITLE] => RAMP function for automation
            [BROWSER_TITLE] => Ramp function 

            [KEYWORDS] => Ramp function, RAMP, Heating Control
            [DESCRIPTION] => Description ST program code for implementation of the ramp function on heating control. You can download a ready-made working example
        )

    [PREVIEW_TEXT] => 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
    [PREVIEW_PICTURE] => Array
        (
            [ID] => 1919
            [TIMESTAMP_X] => Bitrix\Main\Type\DateTime Object
                (
                    [value:protected] => DateTime Object
                        (
                            [date] => 2021-11-16 06:39:01.000000
                            [timezone_type] => 3
                            [timezone] => Europe/Moscow
                        )

                )

            [MODULE_ID] => iblock
            [HEIGHT] => 178
            [WIDTH] => 355
            [FILE_SIZE] => 6379
            [CONTENT_TYPE] => image/png
            [SUBDIR] => iblock/e78
            [FILE_NAME] => auxa30oc93yf1vmlmxpgxhvnullbqv37.png
            [ORIGINAL_NAME] => ramp function.png
            [DESCRIPTION] => 
            [HANDLER_ID] => 
            [EXTERNAL_ID] => 43c78b4b04cc0dab85f48b1921ed7beb
            [~src] => 
            [SRC] => /upload/iblock/e78/auxa30oc93yf1vmlmxpgxhvnullbqv37.png
            [UNSAFE_SRC] => /upload/iblock/e78/auxa30oc93yf1vmlmxpgxhvnullbqv37.png
            [SAFE_SRC] => /upload/iblock/e78/auxa30oc93yf1vmlmxpgxhvnullbqv37.png
            [ALT] => Ramp function on process
            [TITLE] => Ramp function on process
        )

    [DETAIL_PAGE_URL] => /articles/ramp-function.html
)
Ваш комментарий добавлен

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