network 1 // Initializes the variable Falling, enables the treatment of interrupts and attachs the events to be treated to the handles.
if (immediateEnab_Interrup) {
if (notimmediateInício) {
enable_interrupt;
attachRising_Falling_I0.0 to_the interruptrising_edge_I0.0;
attachRising_Falling_I0.0 to_the interruptfalling_edge_I0.0; // Note that two events can be treated by the same interrupt handle.
turn_onStart;
if (immediatePulse_Input) {
setimmediateFalling; // Initializes the variable Falling according to value of I0.0 in the beginning of the operation, to, independent of I0.0 to be on or off in this moment, the measurements of the widths of its on and off pulses haven't got interchanged.
}
}
}
else{
turn_offimmediateStart;
}
network 2 // Handling of the I0.0 rising and falling events, the beginning of counting time at this point remains in high or low level
interrupt_handleRising_Falling_I0.0 ( )
if (Enab_Interrup) {
Anterior_Time :=Edge_Time;
}
when (Enab_Interrup) temporizeEdge_Time 1 h; // The time 1 h is arbitrary. It's enough that it is the major time than the maximum width to be measured.
As result of the compilation of the Pulses_Width_Measurer program above, the SimuPLC 4.1.0 has generated, exactly, the following code, in Instruction List - IL:
// PLC Pulses_Width_Measurer // Measures the widths of the pulses entered in the input I0.0 (whether the turned on (in 1) or the turned off (in 0) parts)
NETWORK1// Initializes the variable Falling, enables the treatment of interrupts and attachs the events to be treated to the handles.
LDII1.0
LDNIInício ALD ENI ATCHRising_Falling_I0.0, 0 ATCHRising_Falling_I0.0, 1 // Note that two events can be treated by the same interrupt handle. SStart, 1
LDII0.0 ALD SIQ0.0, 1 // Initializes the variable Falling according to value of I0.0 in the beginning of the operation, to, independent of I0.0 to be on or off in this moment, the measurements of the widths of its on and off pulses haven't got interchanged.
LDII1.0 NOT RIStart, 1
NETWORK2// Handling of the I0.0 rising and falling events, the beginning of counting time at this point remains in high or low level
INTRising_Falling_I0.0
LDI1.0 MOVDT0, VM0
LDI1.0 TONT0, 3600000 // The time 1 h is arbitrary. It's enough that it is the major time than the maximum width to be measured.