Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

How to reset timer type PULSE

Edxx
2016-10-26
2016-11-07
  • Edxx - 2016-10-26

    Hi
    I'm new in the forum so Regards to All

    I have question how to reset output of the pulse timer TP.
    By the rising triger condition "A", I activate timer TP for fixed time, I wish to reset this time in case when comming another condition "B"

    I writing program for Beckhoff PLC in CFC.
    Is possible to manage this logic with SR, trigers etc by I looking for simplest reset of the timer.

    Best regards
    Ed

     
  • Anonymous - 2016-11-07

    Originally created by: scott_cunningham

    What should happen when Condition B is held high? Should the output stay ON, if it was on? What if the output was already OFF (TP expired) and you set Condition B high? Should the output stay OFF?

    You may be best to program your special need using ST as it's own FB, instead of trying to use a combination of TONs, TOFs, SRs, etc. Here is an example that assumes holding CondB high will keep timer at 0 until dropped low. Maybe CondB should be edge triggered?

    The code below seems to work, but please test it yourself. Maybe this can be handled with a CFC solution without a state machine, but I didn't try.

    FUNCTION_BLOCK TP_RST
    VAR_INPUT
       IN : BOOL;
       PT : TIME;
       RST : BOOL;
    END_VAR
    VAR_OUTPUT
       Q : BOOL;
       ET : TIME;
    END_VAR
    VAR CONSTANT
       INIT : INT := 0;
       RUN_PULSE : INT := 1;
       PULSE_DONE : INT := 2;
       RESET_TIME : INT := 3;
    END_VAR
    VAR
       Timer : Standard.TON;
       State : INT;
    END_VAR
    CASE State OF
       INIT://Make sure output and timer are off
          Timer(IN:=FALSE, PT:=PT, ET=>ET);
          Q := FALSE;
          //See if user wants to start pulse
          IF IN THEN
             State := RUN_PULSE;
          END_IF
          
       RUN_PULSE://Normal pulse (output is true)
          Timer(IN:=TRUE, PT:=PT, ET=>ET);
          Q := TRUE;
          //See if timer reset requested
          IF RST THEN
             State := RESET_TIME;
          END_IF
          //See if timer expired (this overrides RST signal if timer is already done)
          IF Timer.Q THEN
             State := PULSE_DONE;
          END_IF
       
       PULSE_DONE://Pulse is done - ignore RST input
          //Keep timer TRUE to maintain ET like normal TP
          Timer(IN:=TRUE, PT:=PT, ET=>ET);
          Q := FALSE;
          //See if user shuts off timer
          IF NOT IN THEN
             State := INIT;
          END_IF
          
       RESET_TIME://User wants to extend pulse output (keep output high)
          //Reset timer (ET = 0 again)
          Timer(IN:=FALSE, PT:=PT, ET=>ET);
          Q := TRUE;
          //Watch for drop of RST - and go back to normal pulse output
          IF NOT RST THEN
             State := RUN_PULSE;
          END_IF
          
       ELSE //problem in code - reset state machine so FB doesn't freeze
          State := INIT;
          
    END_CASE
    
     

Log in to post a comment.