0% found this document useful (0 votes)
2 views3 pages

PROGRAM PumpControl

The PumpControl program manages the activation of up to five pumps based on a priority system. It uses a flag to detect changes in pump ID mapping and updates the pump priorities accordingly. The program initializes pump IDs, resets all pumps to OFF, and activates a specified number of pumps based on the current priority order.

Uploaded by

autshop168
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

PROGRAM PumpControl

The PumpControl program manages the activation of up to five pumps based on a priority system. It uses a flag to detect changes in pump ID mapping and updates the pump priorities accordingly. The program initializes pump IDs, resets all pumps to OFF, and activates a specified number of pumps based on the current priority order.

Uploaded by

autshop168
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PROGRAM PumpControl

VAR

NB_pump : INT; (* Number of pumps to activate *)

BB : BOOL; (* Flag to change pump ID mapping *)

BB_last : BOOL := FALSE; (* Tracks the previous state of BB *)

Pump1, Pump2, Pump3, Pump4, Pump5 : BOOL; (* Status of each pump: TRUE = ON, FALSE = OFF *)

ID_Pump1, ID_Pump2, ID_Pump3, ID_Pump4, ID_Pump5 : INT; (* Dynamic IDs for each pump *)

Priority : ARRAY[1..5] OF INT := [1, 2, 3, 4, 5]; (* Priority list *)

PriorityCounter : ARRAY[1..5] OF INT := [0, 0, 0, 0, 0]; (* Cycle counter for each pump priority *)

PumpOrder : ARRAY[1..5] OF INT; (* Current pump order based on priority *)

i : INT; (* Loop index *)

BB_triggered : BOOL := FALSE; (* Flag to ensure priority change happens only once *)

END_VAR

(* Detect edge of BB (TRUE on rising edge) *)

IF BB AND NOT BB_last THEN

BB_triggered := TRUE; (* Rising edge detected *)

END_IF;

BB_last := BB; (* Update BB_last with the current BB state *)

(* Update priority on first BB rising edge *)

IF BB_triggered THEN

FOR i := 1 TO 5 DO

PriorityCounter[i] := PriorityCounter[i] + 1;

IF PriorityCounter[i] > 5 THEN

PriorityCounter[i] := 1;

Priority[i] := Priority[i] MOD 5 + 1; (* Rotate priority *)

END_IF;
PumpOrder[Priority[i]] := i; (* Assign pump order based on priority *)

END_FOR;

BB_triggered := FALSE; (* Reset the flag after changing priorities *)

END_IF;

(* Set default pump IDs *)

ID_Pump1 := 2;

ID_Pump2 := 1;

ID_Pump3 := 4;

ID_Pump4 := 3;

ID_Pump5 := 5;

(* Reset all pumps to OFF initially *)

Pump1 := FALSE;

Pump2 := FALSE;

Pump3 := FALSE;

Pump4 := FALSE;

Pump5 := FALSE;

(* Activate pumps based on NB_pump *)

FOR i := 1 TO NB_pump DO

CASE PumpOrder[i] OF

1: Pump1 := TRUE;

2: Pump2 := TRUE;

3: Pump3 := TRUE;

4: Pump4 := TRUE;

5: Pump5 := TRUE;

END_CASE;

END_FOR;
END_PROGRAM

You might also like