Machine Automation Forum
A forum addressing machine automation solutions for the complete machine lifecycle. Including offers like Machine Advisor, Modicon PLC/PacDrive, Lexium or Preventa. Discuss and share knowledge on offers relating to cloud-based service platforms, machine localization and monitoring, industrial operations control, motion products as well as safety function!
Link copied. Please paste this link to share this article on your social media post.
Posted: 2022-10-19 01:04 PM
While most of our uses of the TM171/TM172 line have been on chillers, we do from time to time need to apply them to a cold room where there´s a need to perform a time-based or temperature-based evaporator defrost strategy, besides controlling cold room temperature.
A typical cycle goes like this:
F19, F47,F13 are temperature variables and F20, F45, F44, F14 and F18 are time variables.
Is there any function block or program developed for this use ?
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2022-10-19 10:12 PM
Hi,
Try this code.
FUNCTION_BLOCK FB_Defrost
VAR
t_udiTime : UDINT;
t_xDefrost_1_active : BOOL;
t_xDefrost_2_active : BOOL;
t_xDefrost_3_active : BOOL;
t_xDefrost_4_active : BOOL;
TON_defrost_time_1 : TON; (* Timer Abtaudauer #1 *)
TON_defrost_time_2 : TON; (* Timer Abtaudauer #2 *)
TON_defrost_time_3 : TON; (* Timer Abtaudauer #3 *)
TON_defrost_time_4 : TON; (* Timer Abtaudauer #4 *)
TON_defrost_time_manual : TON; (* Timer Abtaudauer Manuell *)
R_TRIG_manual_defrost : R_TRIG; (* Flanken Auswertung Start Abtauung Manuell *)
t_xDefrost_manual_active : BOOL;
F_TRIG_defrost_1 : F_TRIG; (* Flanken Auswertung Ende Abtauung 1 *)
F_TRIG_defrost_2 : F_TRIG; (* Flanken Auswertung Ende Abtauung 2 *)
F_TRIG_defrost_3 : F_TRIG; (* Flanken Auswertung Ende Abtauung 3 *)
F_TRIG_defrost_4 : F_TRIG; (* Flanken Auswertung Ende Abtauung 4 *)
F_TRIG_defrost_manual : F_TRIG; (* Flanken Auswertung Ende Abtauung 5 *)
TP_drain_time : TP; (* Puls Timer Abtropfzeit *)
F_TRIG_drain_time : F_TRIG; (* Flanken Auswertung Ende Abtauung 5 *)
Thermostat_defrost1 : FB_Thermostat; (* Thermstat Abtauendtemperatur *)
Thermostat_defrost2 : FB_Thermostat; (* Thermstat Abtauendtemperatur *)
Thermostat_defrost3 : FB_Thermostat; (* Thermstat Abtauendtemperatur *)
Thermostat_defrost4 : FB_Thermostat; (* Thermstat Abtauendtemperatur *)
Thermostat_defrost5 : FB_Thermostat; (* Thermstat Abtauendtemperatur *)
END_VAR
VAR_INPUT
xActive : BOOL;
iAV_coil_temperature : INT; (* Verdampfer Paket Temperatur *)
iSP_defrost_endtemperature : INT; (* Sollwert Abtauendtemperatur *)
iHYS_defrost_endtemperature : INT; (* Hysterese Abtauendtemperatur *)
xDefrost_manual : BOOL; (* Handabtauung (Flanke wird ausgewertet) *)
xStop_manual_defrost : BOOL;
xDefrost_blocked : BOOL; (* Abtauung geblockt (Wenn Froster Modus) *)
udiDefrost_time_1 : UDINT; (* Uhrzeit für Abtauung #1 HH:MM *)
uiDefrost_duration_1 : UINT; (* Abtaudauer Abtauung #1 [min] *)
udiDefrost_time_2 : UDINT; (* Uhrzeit für Abtauung #2 HH:MM *)
uiDefrost_duration_2 : UINT; (* Abtaudauer Abtauung #2 [min] *)
udiDefrost_time_3 : UDINT; (* Uhrzeit für Abtauung #3 HH:MM *)
uiDefrost_duration_3 : UINT; (* Abtaudauer Abtauung #3 [min] *)
udiDefrost_time_4 : UDINT; (* Uhrzeit für Abtauung #4 HH:MM *)
uiDefrost_duration_4 : UINT; (* Abtaudauer Abtauung #4 [min] *)
uiDefrost_duration_manual : UINT; (* Abtaudauer Abtauung Hand [min] *)
uiDrain_time : UINT; (* Abtropfzeit [s] *)
END_VAR
VAR_OUTPUT
xDefrost_heater : BOOL; (* TRUE wenn Heizung aktiv *)
xDrain_time_active : BOOL; (* TRUE wenn abtropfzeit aktiv *)
uiRest_time_defrost : UINT; (* Restlaufzeit der Abtauung *)
uiRest_time_drain : UINT;
xDefrost_finished : BOOL := TRUE; (* TRUE wenn kühlung aktiv werden kann und abtauung beendet *)
uiLast_defrost_time : UINT;
END_VAR
VAR_EXTERNAL
sysClock : TypeDataTime; (* System Date and Time Read. It is a structure of type TypeDataTime composed
by the following fields:
seconds : USINT; seconds [0...59]
minutes : USINT; minutes [0...59]
hours : USINT; hours [0...23]
dayweek : USINT; day of week [0...6]
daymonth : USINT; day of month [1...31]
month : USINT; month [1...12]
year : USINT; year [10...99] *)
END_VAR
IF xActive
THEN
t_udiTime := (TO_UDINT(sysClock.hours)*3600)+TO_UDINT(sysClock.minutes*60);
//Initialisiation defrost duration timer
TON_defrost_time_1();
TON_defrost_time_1.PT := F_MUL1K(uiDefrost_duration_1)*60;
TON_defrost_time_2();
TON_defrost_time_2.PT := F_MUL1K(uiDefrost_duration_2)*60;
TON_defrost_time_3();
TON_defrost_time_3.PT := F_MUL1K(uiDefrost_duration_3)*60;
TON_defrost_time_4();
TON_defrost_time_4.PT := F_MUL1K(uiDefrost_duration_4)*60;
TON_defrost_time_manual();
TON_defrost_time_manual.PT := F_MUL1K(uiDefrost_duration_manual)*60;
R_TRIG_manual_defrost();
R_TRIG_manual_defrost.clk := xDefrost_manual;
//Initialisiation defrost thermostat
Thermostat_defrost1();
Thermostat_defrost1.iActualvalue:= iAV_coil_temperature;
Thermostat_defrost1.iHysteresis := iHYS_defrost_endtemperature;
Thermostat_defrost1.iSetpoint := iSP_defrost_endtemperature;
Thermostat_defrost1.xMode := FALSE;
Thermostat_defrost1.xActive := t_xDefrost_1_active;
Thermostat_defrost2();
Thermostat_defrost2.iActualvalue:= iAV_coil_temperature;
Thermostat_defrost2.iHysteresis := iHYS_defrost_endtemperature;
Thermostat_defrost2.iSetpoint := iSP_defrost_endtemperature;
Thermostat_defrost2.xMode := FALSE;
Thermostat_defrost2.xActive := t_xDefrost_2_active;
Thermostat_defrost3();
Thermostat_defrost3.iActualvalue:= iAV_coil_temperature;
Thermostat_defrost3.iHysteresis := iHYS_defrost_endtemperature;
Thermostat_defrost3.iSetpoint := iSP_defrost_endtemperature;
Thermostat_defrost3.xMode := FALSE;
Thermostat_defrost3.xActive := t_xDefrost_3_active;
Thermostat_defrost4();
Thermostat_defrost4.iActualvalue:= iAV_coil_temperature;
Thermostat_defrost4.iHysteresis := iHYS_defrost_endtemperature;
Thermostat_defrost4.iSetpoint := iSP_defrost_endtemperature;
Thermostat_defrost4.xMode := FALSE;
Thermostat_defrost4.xActive := t_xDefrost_4_active;
Thermostat_defrost5();
Thermostat_defrost5.iActualvalue:= iAV_coil_temperature;
Thermostat_defrost5.iHysteresis := iHYS_defrost_endtemperature;
Thermostat_defrost5.iSetpoint := iSP_defrost_endtemperature;
Thermostat_defrost5.xMode := FALSE;
Thermostat_defrost5.xActive := t_xDefrost_manual_active;
//drain time
F_TRIG_defrost_1();
F_TRIG_defrost_2();
F_TRIG_defrost_3();
F_TRIG_defrost_4();
F_TRIG_defrost_manual();
F_TRIG_drain_time();
F_TRIG_defrost_1.clk := t_xDefrost_1_active;
F_TRIG_defrost_2.clk := t_xDefrost_2_active;
F_TRIG_defrost_3.clk := t_xDefrost_3_active;
F_TRIG_defrost_4.clk := t_xDefrost_4_active;
F_TRIG_defrost_manual.clk := t_xDefrost_manual_active;
F_TRIG_drain_time.clk := TP_drain_time.Q;
TP_drain_time();
TP_drain_time.PT := 1+ F_MUL1K(uiDrain_time);
xDrain_time_active := TO_BOOL(TP_drain_time.ET);
TP_drain_time.IN := F_TRIG_defrost_1.q OR
F_TRIG_defrost_2.q OR
F_TRIG_defrost_3.q OR
F_TRIG_defrost_4.q OR
F_TRIG_defrost_manual.q;
IF TP_drain_time.Q
THEN
uiRest_time_drain := F_DIV1K(TP_drain_time.PT - TP_drain_time.ET);
ELSE
uiRest_time_drain := 0;
END_IF;
IF NOT xDefrost_blocked
THEN
//start Defrost cycle 1
IF (t_udiTime = udiDefrost_time_1) AND TON_defrost_time_1.PT>0
THEN
t_xDefrost_1_active := TRUE;
END_IF;
//start Defrost cycle 2
IF (t_udiTime = udiDefrost_time_2) AND TON_defrost_time_2.PT>0
THEN
t_xDefrost_2_active := TRUE;
END_IF;
//start Defrost cycle 3
IF (t_udiTime = udiDefrost_time_3) AND TON_defrost_time_3.PT>0
THEN
t_xDefrost_3_active := TRUE;
END_IF;
//start Defrost cycle 4
IF (t_udiTime = udiDefrost_time_4) AND TON_defrost_time_4.PT>0
THEN
t_xDefrost_4_active := TRUE;
END_IF;
//Defrost Manual
IF R_TRIG_manual_defrost.q AND TON_defrost_time_manual.PT>0
THEN
t_xDefrost_manual_active := TRUE;
END_IF;
ELSE
t_xDefrost_1_active := FALSE;
t_xDefrost_2_active := FALSE;
t_xDefrost_3_active := FALSE;
t_xDefrost_4_active := FALSE;
t_xDefrost_manual_active := FALSE;
END_IF;
//Defrost #1 function
IF t_xDefrost_1_active
THEN
TON_defrost_time_1.IN := TRUE;
uiRest_time_defrost := F_DIV1K(TON_defrost_time_1.PT-TON_defrost_time_1.ET);
ELSE
TON_defrost_time_1.IN := FALSE;
END_IF;
//Defrost #2 function
IF t_xDefrost_2_active
THEN
TON_defrost_time_2.IN := TRUE;
uiRest_time_defrost := F_DIV1K(TON_defrost_time_2.PT-TON_defrost_time_2.ET);
ELSE
TON_defrost_time_2.IN := FALSE;
END_IF;
//Defrost #3 function
IF t_xDefrost_3_active
THEN
TON_defrost_time_3.IN := TRUE;
uiRest_time_defrost := F_DIV1K(TON_defrost_time_3.PT-TON_defrost_time_3.ET);
ELSE
TON_defrost_time_3.IN := FALSE;
END_IF;
//Defrost #4 function
IF t_xDefrost_4_active
THEN
TON_defrost_time_4.IN := TRUE;
uiRest_time_defrost := F_DIV1K(TON_defrost_time_4.PT-TON_defrost_time_4.ET);
ELSE
TON_defrost_time_4.IN := FALSE;
END_IF;
//Defrost maunal function
IF t_xDefrost_manual_active AND NOT xStop_manual_defrost
THEN
TON_defrost_time_manual.IN := TRUE;
uiRest_time_defrost := F_DIV1K(TON_defrost_time_manual.PT-TON_defrost_time_manual.ET);
ELSE
TON_defrost_time_manual.IN := FALSE;
END_IF;
// Start defrost heater
IF t_xDefrost_1_active OR t_xDefrost_2_active OR t_xDefrost_3_active OR t_xDefrost_4_active OR t_xDefrost_manual_active
THEN
xDefrost_heater := TRUE;
xDefrost_finished := FALSE;
ELSE
IF F_TRIG_drain_time.q
THEN
xDefrost_finished := TRUE;
xDrain_time_active := False;
END_IF;
xDefrost_heater := FALSE;
uiRest_time_defrost := 0;
END_IF;
// Deactivating defrosting
IF TON_defrost_time_1.Q OR Thermostat_defrost1.xOutput_Active
THEN
uiLast_defrost_time := TO_UINT(TON_defrost_time_1.ET/1000);
t_xDefrost_1_active := FALSE;
t_xDefrost_1_active := FALSE;
END_IF;
IF TON_defrost_time_2.Q OR Thermostat_defrost2.xOutput_Active
THEN
uiLast_defrost_time := TO_UINT(TON_defrost_time_2.ET/1000);
t_xDefrost_2_active := FALSE;
t_xDefrost_2_active := FALSE;
END_IF;
IF TON_defrost_time_3.Q OR Thermostat_defrost3.xOutput_Active
THEN
uiLast_defrost_time := TO_UINT(TON_defrost_time_3.ET/1000);
t_xDefrost_3_active := FALSE;
t_xDefrost_3_active := FALSE;
END_IF;
IF TON_defrost_time_4.Q OR Thermostat_defrost4.xOutput_Active
THEN
uiLast_defrost_time := TO_UINT(TON_defrost_time_4.ET/1000);
t_xDefrost_4_active := FALSE;
t_xDefrost_4_active := FALSE;
END_IF;
IF TON_defrost_time_manual.Q OR Thermostat_defrost5.xOutput_Active
THEN
uiLast_defrost_time := TO_UINT(TON_defrost_time_manual.ET/1000);
t_xDefrost_manual_active:= FALSE;
t_xDefrost_manual_active:= FALSE;
END_IF;
ELSE
xDefrost_heater := FALSE;
xDrain_time_active := FALSE;
xDefrost_finished := True;
uiRest_time_defrost := 0;
uiRest_time_drain := 0;
TON_defrost_time_manual.PT := 0;
END_IF;
Maybe not the best code.
But a customer use it since a few years in a serial buisness.
You could use Deepl.com to translate the comments.
best regards
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2022-10-20 04:06 AM
Thanks for your feedback. I do know some German so it will help me practice a little bit 😅.
It is interesting to see a state machine (a CASE structure) is not used here.
I will give it a try and see how it goes. I assume you would use the boolean outputs to disable compressor if electrical defrost is used?
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.