lamine97 - 2025-03-25

I am trying to implement a Ladder Logic (LD) function block in CoDeSys that increments a value A by B every T time interval. My Structured Text (ST) version works perfectly in simulation, but when I implement it in LD, it does not work.

The ST code:

PROGRAM ADDITION

VAR_INPUT

A : LREAL ;

B : LREAL ;

T : TIME ;

END_VAR

VAR

Timer : TON ;

END_VAR

Timer (IN:=TRUE, PT := T);

IF Timer.Q THEN

A := A + B ;

Timer(IN := FALSE ) ;

END_IF;