(****** QuickLD compiler *******************************)
(****** Copyright Rockwell Automation Canada, Ltd ******)
(****** ST *********************************************)

(*************** Rung **********************************)
(*Example 8.2 
Generate FIFO shift pulse.*)
__STEPPRAGMA
0,1
__ENDSTEPPRAGMA
(*Label :*)(**)
(* FB call: TON *)
Conv_Tmr(_IO_EM_DO_09 AND NOT(CONV_TMR.Q), T#2S) ;

(*************** Code for the end of Rung **************)
__GL __LG0001 ;


(*************** Rung **********************************)
(*Shift conveyor position, loading FIFO. When FIFO full, unload. If non-zero part number comes out of FIFO, load in onto LIFO*)
__STEPPRAGMA
0,4
__ENDSTEPPRAGMA
(*Label :*)(**)
__EDTB1 := CONV_TMR.Q ;
(* FB call: FFL *)
Conv_FFL(__EDTB1, CONV_SOURCE, CONV_QUE, FIFO_CTL, , , ) ;
__EDTB2 := Conv_FFL.Done ;
(* FB call: FFU *)
Conv_FFU(__EDTB1 AND CONV_FFL.FULL, CONV_DEST, 0, CONV_QUE, FIFO_CTL, , , , ) ;
__EDTB3 := Conv_FFU.Done ;
__EDTB5 := __EDTB1 ;
IF __EDTB5 THEN
(* Operator output on : <> with __EDTB4 *)
__EDTB4 := (CONV_DEST <> 0) ;
ELSE
__EDTB4 := FALSE ;
END_IF ;
__MO_DIFF_1 := __EDTB4 ;
(* FB call: LFL *)
Stak_LFL(__EDTB4, CONV_DEST, STAK_QUE, LIFO_CTL, 0, 0, 0) ;
__EDTB6 := Stak_LFL.Done ;
__EDTB7 := (__EDTB3 OR __EDTB6) ;

(*************** Code for the end of Rung **************)
__GL __LG0002 ;


(*************** Rung **********************************)
(*When stack is full, then start unstacking. When empty, stop unstacking.*)
__STEPPRAGMA
0,28
__ENDSTEPPRAGMA
(*Label :*)(**)
__EDTB8 := STAK_LFL.FULL ;
__EDTB9 := UNSTACKING ;
UNSTACKING := (__EDTB8 OR __EDTB9) AND NOT(STAK_LFU.EMPTY) ;

(*************** Code for the end of Rung **************)
__GL __LG0003 ;


(*************** Rung **********************************)
(*While unstacking, unload one item every second.*)
__STEPPRAGMA
0,31
__ENDSTEPPRAGMA
(*Label :*)(**)
__EDTB10 := UNSTACKING ;
(* FB call: TON *)
Unld_Tmr(__EDTB10 AND NOT(UNLD_TMR.Q), T#1S) ;
__EDTB11 := Unld_Tmr.Q ;
(* FB call: LFU *)
Stak_LFU(__EDTB10 AND UNLD_TMR.Q, UNSTACK_DEST, 0, STAK_QUE, LIFO_CTL, 0, 0, 0, 0) ;
__EDTB12 := Stak_LFU.Done ;

(*************** Code for the end of Rung **************)
__GL __LG0004 ;


(*************** Rung **********************************)
(*Conveyor motor control. Do not run when unstacking.*)
__STEPPRAGMA
0,43
__ENDSTEPPRAGMA
(*Label :*)(**)
_IO_EM_DO_09 := CONV_RUN AND NOT(UNSTACKING) ;

(*************** Code for the end of Rung **************)
__GL __LG0005 ;


(*************** Rung **********************************)
(*Initialize FIFO and LIFO by clearing position.*)
__STEPPRAGMA
0,45
__ENDSTEPPRAGMA
(*Label :*)(**)
__EDTB13 := INT_RESET ;
IF __EDTB13 THEN
FIFO_CTL.POSITION := (  0) ;
END_IF ;
__MO_1GAIN_1 := __EDTB13 ;
__EDTB14 := __EDTB13 ;
IF __EDTB14 THEN
LIFO_CTL.LENGTH := (  0) ;
END_IF ;
__MO_1GAIN_2 := __EDTB14 ;

(*************** Code for the end of Rung **************)
__GL __LG0006 ;


(*************** Code for the end of File **************)
__GL __LG0000 ;



(*************** Local Symbols table *******************)
(* __EDTB1 *)
(* __EDTB2 *)
(* __EDTB3 *)
(* __EDTB4 *)
(* __EDTB5 *)
(* __EDTB6 *)
(* __EDTB7 *)
(* __EDTB8 *)
(* __EDTB9 *)
(* __EDTB10 *)
(* __EDTB11 *)
(* __EDTB12 *)
(* __EDTB13 *)
(* __EDTB14 *)

