msousa@276: (* Following taken directly from the IEC 61131.3 draft standard *)
msousa@276: 
msousa@276: (*
msousa@276:  * An IEC 61131-3 IL and ST compiler.
msousa@276:  *
msousa@276:  * Based on the
msousa@276:  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
msousa@276:  *
msousa@276:  *)
msousa@276: 
etisserant@0:  FUNCTION_BLOCK RAMP
etisserant@0:    VAR_INPUT
etisserant@0:      RUN : BOOL ;      (* 0 - track X0, 1 - ramp to/track X1 *)     
etisserant@0:      X0,X1 : REAL ;
etisserant@0:      TR : TIME ;       (* Ramp duration *)
etisserant@0:      CYCLE : TIME ;    (* Sampling period *)
etisserant@0:    END_VAR
etisserant@0:    VAR_OUTPUT
etisserant@0:      BUSY : BOOL ; (* BUSY = 1 during ramping period *)
etisserant@0:      XOUT : REAL := 0.0 ;
etisserant@0:    END_VAR
etisserant@0:    VAR XI : REAL ;       (* Initial value *)
etisserant@0:        T : TIME := T#0s; (* Elapsed time of ramp *)
etisserant@0:    END_VAR
etisserant@0:    BUSY := RUN ;
etisserant@0:    IF RUN THEN
etisserant@0:       IF T >= TR THEN BUSY := 0 ; XOUT := X1 ;
etisserant@0:       ELSE XOUT := XI + (X1-XI) * TIME_TO_REAL(T)
etisserant@0:                                 / TIME_TO_REAL(TR) ;
etisserant@0:            T := T + CYCLE ;
etisserant@0:       END_IF ;
etisserant@0:    ELSE XOUT := X0 ; XI := X0 ; T := t#0s ;
etisserant@0:    END_IF ;
etisserant@0:  END_FUNCTION_BLOCK
etisserant@0: