OriolFM

Calling a Timer in ST code.

3 posts in this topic

Dear all,

In a state machine I have certain states which need to have a timer to handle timeout errors, that is, if the FSM remains too long in a certain state without getting the conditions to transition to another one, it will produce an error.

My current code is using a TOF with an input variable that will be triggered upon entering the state, I call the function block, and then turn the signal off so it starts counting:

TRIG_STOP_TIMEOUT := TRUE;
TTO_GLOBAL_CYCLE_STOP(IN:= TRIG_STOP_TIMEOUT ,PT:= T#15s ,Q=> ERR_GLOBAL_STOP_TIMEOUT ,ET=> CLK_GLOBAL_CYCLE_STOP ); // TOF
TRIG_STOP_TIMEOUT := FALSE;

For some reason, the counter does not work. I don't know if I should trigger the signal on in one scan and off on the next. I thought about using the system 1s clock as a trigger (SM412) but the description of the TOF function block states whenever the input is ON, the output will be true, and the timer will only start counting once the input is low.

The other thing I thought about was to use the TOF_E instead, with the clock as a trigger, and just set the enable signal when I'm in the state, but I'm not sure it'd work correctly, either.

Any suggestions?

Share this post


Link to post
Share on other sites

Hi Oriol FM.

I think the scan time is to fast so you need some extra program to hanlde the trigger for Timer.In from True to False. First you must add you timer instance variable to "Register Watch" and see if the timer is running. If not add some code to hold maybe some seconds to trigger :

Quote

TOF_1.IN := TRUE AND NOT TON_2.Q;
    TOF_1(PT:= T#15S );
    TON_2(IN:= Force1 ,PT:= T#2S);
    BOOL_STAT := TOF_1.Q;

 

Hope you can get it running.

Share this post


Link to post
Share on other sites

Posted (edited)

On 31/12/2019 at 6:21 PM, deny zaelani said:

Hi Oriol FM.

I think the scan time is to fast so you need some extra program to hanlde the trigger for Timer.In from True to False. First you must add you timer instance variable to "Register Watch" and see if the timer is running. If not add some code to hold maybe some seconds to trigger :

Hope you can get it running.

Thanks to your example, I figured out a simpler way to handle it.

Because I'm using a state machine, I do setup a trigger (in the example, CONV_STARTUP_TRIGGER) which is TRUE when I enter the relevant state (in this case, the startup procedure) and FALSE when I'm outside it.

CONV_STARTUP_TIMEOUT(IN:=CONV_STARTUP_TRIGGER, PT:=TIME_CONV_STARTUP);

The timer (CONV_STARTUP_TIMEOUT) is a TON which, when the trigger becomes active (when I enter the state, the trigger goes from FALSE to TRUE), the output (CONV_STARTUP_TIMEOUT.Q) becomes FALSE for the specified time (TIME_CONV_STARTUP) and then becomes TRUE until the timer is activated again (by raising flank).

Edited by OriolFM

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now