Traffic Light Control - Program-Example in LCE

Top 



In the control program below, two groups of lamps, each in the two-times traffic light set, are alight alternately according to the standard activation sequence, with possibility of the alight times to be altered, by the analogical inputs AIW0, AIW1 and AIW2; and also it's possible to deactivate the traffic light, by turning on of bit input I0.0, when then the yellow lights will be blink all time.



plc
Traffic_Light // Control of traffic light with two sets of signaler lights (simple crossing) and signaling of deactivated state: yellow lights blinking

var Q0.0   Green1,      // Red Light of the first set ...
   
Q0.1   Yellow1,
   
Q0.2   Red1,
   
Q1.0   Green2,
   
Q1.1   Yellow2,
   
Q1.2   Red2,

   
AIW0   TimeGreen1,   // Time in that the green light remains alight in the set 1
   
AIW1   TimeYellow1,
   
AIW2   TimeRed1,

   
T0   GetTimeGreen,   // Var. of time that indicates that time of the light green was reached
   
T1   GetTimeYellow1,
   
T2   GetTimeYellow2,
   
T3   GetTimeRed,

   
T4   TimeOn,      // Time (500 ms) that the yellow lights are alight in the blink when the traffic light is deactivated
   
T5   TimeOff,      // ... idem for time (500 ms) they are turned off
   
I0.0   BlinkYellows;   // Indicates traffic light inactive, with the yellow lights blinking

network 0 // Begins the control in the sequence Green1Red2 and set temporization pattern if times of operation are not supplied in the variables AIW0, AIW1 and AIW2

if ( not VarAux){
operate Initiate; // Generates the pulse in Initiate when of the beginning of the operation (1º cycle)
or (VarAux){
operate VarAux;
}
}

if (Initiate){
turn_on Green1Red2; // Activates the initial sequence when of the beginning of the operation
}

if (TimeGreen1 <= 0) { // If time is not supplied ...
TimeGreen1 := 10; // ... receive pattern value
}

if (TimeYellow1 <= 0) {
TimeYellow1 := 3; // Idem
}

if (TimeRed1 <= 0) {
TimeRed1 := 10; // Idem
}

//**************************************************

network 1 // In the sequence Green1Red2 below the lights Green1 and Green2 remain alight
sequence Green1Red2

network 2 // Control of turn on, turn off and temporization
if ( not immediate Green1 or not immediate Red2 ) {
turn_on immediate Green1;
turn_on immediate Red2;
turn_off immediate Red1;
turn_off immediate Yellow1;
turn_off immediate Yellow2;
turn_off immediate Green2;
reset GetTimeGreen;
}

when ( Green1 ) temporize    GetTimeGreen    TimeGreen1 s;

end_circuit_sequence

network 3 // Transfers running to the sequence "Yellow1Yellow2" if is deactived the traffic light
if (immediate BlinkYellows) {
turn_off immediate Green1;
turn_off immediate Red2;
turn_on immediate Yellow1;
turn_on immediate Yellow2;
transfer_sequence Yellow1Yellow2;
}

if ( GetTimeGreen and not immediate BlinkYellows) { transfer_sequence Yellow1Red2;}

network 4 // End of the sequence Green1Red2
end_sequence;

//**************************************************

network 5 // In the sequence Yellow1Red2 the lights Yellow1 and Green2 remain blinking
sequence Yellow1Red2

network 6 // Control of turn on, turn off and temporization
if ( not immediate Yellow1 or not immediate Red2 ) {
turn_on immediate Yellow1;
turn_on immediate Red2;
turn_off immediate Green1;
turn_off immediate Yellow2;
turn_off immediate Red1;
turn_off immediate Green2;
reset GetTimeYellow1;
}

when ( Yellow1 ) temporize    GetTimeYellow1    TimeYellow1 s;

end_circuit_sequence

network 7 // Transfers running to the next sequence
if (immediate BlinkYellows) {
turn_off immediate Red2;
turn_on immediate Yellow2;
transfer_sequence Yellow1Yellow2;
}

if ( GetTimeYellow1 and not immediate BlinkYellows ) { transfer_sequence Red1Green2; }

network 8 // End of the sequence Yellow1Red2
end_sequence;

//**************************************************

network 9 // In the sequence Red1Green2 the lights Green1 and Green2 remain alight
sequence Red1Green2

network 10 // Control of turn on, turn off and temporization
if ( not immediate Red1 or not immediate Green2 ) {
turn_on immediate Red1;
turn_on immediate Green2;
turn_off immediate Yellow1;
turn_off immediate Yellow2;
turn_off immediate Green1;
turn_off immediate Red2;
reset GetTimeRed;
}

when ( Red1 ) temporize GetTimeRed TimeRed1 s;

end_circuit_sequence

network 11 // Transfers running to the next sequence
if (immediate BlinkYellows) {
turn_off immediate Green2;
turn_off immediate Red1;
turn_on immediate Yellow1;
turn_on immediate Yellow2;
transfer_sequence Yellow1Yellow2;
}

if ( GetTimeRed and not immediate BlinkYellows ) { transfer_sequence Red1Yellow2; }

network 12 // End of the sequence Yellow1Red2
end_sequence;

//**************************************************

network 13 // In the sequence Red1Yellow2 the lights Green1 and Yellow2 remain alight
sequence Red1Yellow2

network 14 // // Control of turn on, turn off and temporization
if ( not immediate Yellow2 or not immediate Red1 ) {
turn_on immediate Red1;
turn_on immediate Yellow2;
turn_off immediate Yellow1;
turn_off immediate Green1;
turn_off immediate Green2;
turn_off immediate Red2;
reset GetTimeYellow2;
}

when ( Yellow2 ) temporize    GetTimeYellow2    TimeYellow1 s;

end_circuit_sequence

network 15 // Transfers running to the next sequence
if (immediate BlinkYellows) {
turn_off immediate Red1;
turn_on immediate Yellow1;
transfer_sequence Yellow1Yellow2;
}

if ( GetTimeYellow2 and not immediate BlinkYellows ) { transfer_sequence Green1Red2; }

network 16 // End of the sequence Red1Yellow2
end_sequence;

//**************************************************

network 17 // Deactivates the traffic light and remain the yellow lights blinking, indicating the deactivation
destino Desativa:

//**************************************************

network 18 // In the sequence Yellow1Yellow2, the yellow lights blinking in the two sets indicate deactivated traffic light
sequence Yellow1Yellow2

network 19 // Control of turn on, turn off and temporization
if (BlinkYellows){
turn_off immediate Green1;
turn_off immediate Green2;
turn_off immediate Red1;
turn_off immediate Red2;
}

when ( not immediate Yellow1 ) temporize    TimeOff    500 ms;

if ( TimeOff ) {
turn_on immediate Yellow1;
turn_on immediate Yellow2;
}

when ( immediate Yellow1 ) temporize    TimeOn    500 ms;

if ( TimeOn ) {
turn_off immediate Yellow1;
turn_off immediate Yellow2;
}

end_circuit_sequence

network 20 // Transfers running to the next sequence
if ( not immediate BlinkYellows ) {
turn_off immediate Yellow1;
turn_off immediate Yellow2;
transfer_sequence Green1Red2;
}

network 21 // End of the sequence Yellow1Yellow2
end_sequence;

end




As result of the compilation of the Traffic_Light program above, the SimuPLC 4.1.0 has generated, exactly, the following code, into Instruction List - IL:


// PLC    Traffic_Light
// Control of traffic light with two sets of signaler lights (simple crossing) and signaling of deactivated state: yellow lights blinking

//
=VAR   Q0.0   Green1
//
=VAR   Q0.1   Yellow1
//
=VAR   Q0.2   Red1
//
=VAR   Q1.0   Green2
//
=VAR   Q1.1   Yellow2
//
=VAR   Q1.2   Red2
//
=VAR   AIW0   TimeGreen1
//
=VAR   AIW1   TimeYellow1
//
=VAR   AIW2   TimeRed1
//
=VAR   T0   GetTimeGreen
//
=VAR   T1   GetTimeYellow1
//
=VAR   T2   GetTimeYellow2
//
=VAR   T3   GetTimeRed
//
=VAR   T4   TimeOn
//
=VAR   T5   TimeOff
//
=VAR   I0.0   BlinkYellows
// Indicates traffic light inactive, with the yellow lights blinking

NETWORK    0 // Begins the control in the sequence Green1Red2 and set temporization pattern if times of operation are not supplied in the variables AIW0, AIW1 and AIW2

LDN   VarAux
=   Initiate
// Generates the pulse in Initiate when of the beginning of the operation (1º cycle)
O   VarAux
=   VarAux

LD   Initiate
S   Green1Red2,   1
// Activates the initial sequence when of the beginning of the operation

LDD<=   AIW0,   0
// If time is not supplied ...
MOVD   10,   AIW0
// ... receive pattern value

LDD<=   AIW1,   0
MOVD   3,   AIW1
// Idem

LDD<=   AIW2,   0
MOVD   10,   AIW2
// Idem
//**************************************************

NETWORK    1 // In the sequence Green1Red2 below the lights Green1 and Green2 remain alight

LSCR   Green1Red2

NETWORK    2 // Control of turn on, turn off and temporization

LDNI    Q0.0
ONI    Q1.2
SI    Q0.0,   1
SI    Q1.2,   1
RI    Q0.2,   1
RI    Q0.1,   1
RI    Q1.1,   1
RI    Q1.0,   1
R   T0,   1

LD   Q0.0
*
D   1000,   AIW0
TON   T0,   AIW0

NETWORK    3 // Transfers running to the sequence "Yellow1Yellow2" if is deactived the traffic light

LDI   I0.0
RI    Q0.0,   1
RI    Q1.2,   1
SI    Q0.1,   1
SI    Q1.1,   1

SCRT   Yellow1Yellow2

LD   T0
ANI    I0.0

SCRT   Yellow1Red2

NETWORK    4 // End of the sequence Green1Red2

SCRE
//**************************************************

NETWORK    5 // In the sequence Yellow1Red2 the lights Yellow1 and Green2 remain blinking

LSCR   Yellow1Red2

NETWORK    6 // Control of turn on, turn off and temporization

LDNI    Q0.1
ONI    Q1.2
SI    Q0.1,   1
SI    Q1.2,   1
RI    Q0.0,   1
RI    Q1.1,   1
RI    Q0.2,   1
RI    Q1.0,   1
R   T1,   1

LD   Q0.1
*
D   1000,   AIW1
TON   T1,   AIW1

NETWORK    7 // Transfers running to the next sequence

LDI   I0.0
RI    Q1.2,   1
SI    Q1.1,   1

SCRT   Yellow1Yellow2

LD   T1
ANI    I0.0

SCRT   Red1Green2

NETWORK    8 // End of the sequence Yellow1Red2

SCRE
//**************************************************

NETWORK    9 // In the sequence Red1Green2 the lights Green1 and Green2 remain alight

LSCR   Red1Green2

NETWORK    10 // Control of turn on, turn off and temporization

LDNI    Q0.2
ONI    Q1.0
SI    Q0.2,   1
SI    Q1.0,   1
RI    Q0.1,   1
RI    Q1.1,   1
RI    Q0.0,   1
RI    Q1.2,   1
R   T3,   1

LD   Q0.2
*
D   1000,   AIW2
TON   T3,   AIW2

NETWORK    11 // Transfers running to the next sequence

LDI   I0.0
RI    Q1.0,   1
RI    Q0.2,   1
SI    Q0.1,   1
SI    Q1.1,   1

SCRT   Yellow1Yellow2

LD   T3
ANI    I0.0

SCRT   Red1Yellow2

NETWORK    12 // End of the sequence Yellow1Red2

SCRE
//**************************************************

NETWORK    13 // In the sequence Red1Yellow2 the lights Green1 and Yellow2 remain alight

LSCR   Red1Yellow2

NETWORK    14 // // Control of turn on, turn off and temporization

LDNI    Q1.1
ONI    Q0.2
SI    Q0.2,   1
SI    Q1.1,   1
RI    Q0.1,   1
RI    Q0.0,   1
RI    Q1.0,   1
RI    Q1.2,   1
R   T2,   1

LD   Q1.1
*
D   1000,   AIW1
TON   T2,   AIW1

NETWORK    15 // Transfers running to the next sequence

LDI   I0.0
RI    Q0.2,   1
SI    Q0.1,   1

SCRT   Yellow1Yellow2

LD   T2
ANI    I0.0

SCRT   Green1Red2

NETWORK    16 // End of the sequence Red1Yellow2

SCRE
//**************************************************

NETWORK    17 // Deactivates the traffic light and remain the yellow lights blinking, indicating the deactivation

LBL   Desativa
//**************************************************

NETWORK    18 // In the sequence Yellow1Yellow2, the yellow lights blinking in the two sets indicate deactivated traffic light

LSCR   Yellow1Yellow2

NETWORK    19 // Control of turn on, turn off and temporization

LD   I0.0
RI    Q0.0,   1
RI    Q1.0,   1
RI    Q0.2,   1
RI    Q1.2,   1

LDNI    Q0.1
TON   T5,   500

LD   T5
SI    Q0.1,   1
SI    Q1.1,   1

LDI   Q0.1
TON   T4,   500

LD   T4
RI    Q0.1,   1
RI    Q1.1,   1

NETWORK    20 // Transfers running to the next sequence

LDNI    I0.0
RI    Q0.1,   1
RI    Q1.1,   1

SCRT   Green1Red2

NETWORK    21 // End of the sequence Yellow1Yellow2

SCRE