text: <user>
  Create a function block for a TON (Timer On Delay) in TwinCAT Structured Text that mimics the behavior of ControlLogix TON instruction, where a preset of 1000 equals 1 second.<|endoftext|>
  <assistant>
  FUNCTION_BLOCK FB_TON_ControlLogix
  VAR_INPUT
      IN      : BOOL;  // Timer input
      PT      : DINT;  // Preset time in milliseconds
  END_VAR
  VAR_OUTPUT
      Q       : BOOL;  // Timer output
      ET      : DINT;  // Elapsed time
  END_VAR
  VAR
      startTime   : DINT;
      currentTime : DINT;
      timerActive : BOOL;
  END_VAR
  
  // Main program
  IF IN AND NOT timerActive THEN
      startTime := F_GetSystemTime();
      timerActive := TRUE;
  ELSIF NOT IN THEN
      timerActive := FALSE;
      ET := 0;
      Q := FALSE;
  END_IF
  
  IF timerActive THEN
      currentTime := F_GetSystemTime();
      ET := currentTime - startTime;
      
      IF ET >= PT THEN
          Q := TRUE;
      END_IF
  END_IF
  
  (* 
  Explanation:
  This function block implements a TON (Timer On Delay) that mimics the behavior of ControlLogix TON instruction. 
  The timer starts when the IN input becomes TRUE and continues to accumulate time until it reaches the preset time (PT). 
  The Q output becomes TRUE when the elapsed time (ET) reaches or exceeds the preset time.
  The preset time (PT) is in milliseconds, where 1000 ms equals 1 second, matching the ControlLogix behavior.
  
  Related TwinCAT 3 features and programming techniques:
  1. Real-time Task Configuration: Configure the task that calls this function block to ensure precise timing.
  2. Structured Text Debugging: Utilize TwinCAT 3's debugging features to monitor timer behavior in real-time.
  3. Online Change: Implement this feature to allow modifications to the timer logic without stopping the PLC.
  *)
  
  END_FUNCTION_BLOCK<|endoftext|>
  