Studio 500 Structured Text TONR

papacroft

Member
Join Date
Apr 2020
Location
Huddersfield
Posts
12
Hello I'm trying to do some structured text for a timer that will illuminate a lamp for 2 seconds, then extinguish for 2 seconds.
At the moment I'm emulating but don't seem to be able to get it reliable. Has anyone a snippet of code I could try please?

Thanks..
 
Last edited:
Unfortunately AB don't generate clock memories like Siemens do....this means if you want reliable clock signals you shouldn't rely on timers in a continuous task (because the task can vary in scan time dependent on CPU load and higher priority events).

If you create a periodic task with a set frequency (high priority)- you can generate from here.


Regards

Daniel
 
If the 2s spec is fuzzy enough that 2s +/- 41% (sqrt(2)-1) is acceptable, you could pick a bit in the free running clock that will toggle with a full cycle period somewhere between 2.8s and 5.6s, and tie your lamp to that.


It's one line of code.




For MicroLogix, the low bit (S:4/0) increments at 100us intervals, so 10,000 increments per second, so bit S:4/14 is 16384, and tying the lamp to it would have it toggle at 1.6s intervals.




If your PLC has Hour, Minutes and Seconds in a Real-Time Clock (RTC), you might be able to tie the lamp to the 1 bit of the Seconds register, which will toggle at around 2s intervals.


I am no ST expert and I am not sure how you address the RTC bits, but the implementation would be something like this:



Code:
Lamp_Output := RTC:0.SEC/1;
I just implemented that in ladder on a MicroLogix 1100 and timed the result with an Android stopwatch app: 20.3s for 10 toggles; the 0.3s is probably more my finger than the RTC.





It's all a matter of what accuracy is acceptable.
 
Last edited:
Code:
TONR(Light_Time);
Light_Time.TimerEnable 	:= Not Dark_Time.DN;
Light_Time.PRE 		:= 2000;

TONR(Dark_Time);
Dark_Time.TimerEnable 	:= Light_Time.DN;
Dark_Time.PRE 		:= 2000;

Lamp_Output		:= Light_Time.TT;

Here you go!

The TONR Must be declared as a FBD_Timer and not a Timer as you would use in ladder.
 
Last edited:
Many thanks...I had something very similar, was using FBD. My thoughts were that it was an issue with the emulator.

That said

Can I call the TONR timers and .pre out at the top of the routine and then simply enable inside the if else statement, just to make the code neater? (Ignore 10secs / that's just so I could see in emulator - I am thinking that this is the bigger problem for my setup).


TONR(stTMR_WDLampON);
stTMR_WDLampON.PRE := 10000; // Watchdog Lamp ON Time
TONR(stTMR_WDLampOFF);
stTMR_WDLampOFF.PRE := 10000; // Watchdog Lamp OFF Time



IF AB04_I.7 THEN


stTMR_WDLampON.TimerEnable := NOT stTMR_WDLampOFF.DN;


stTMR_WDLampOFF.TimerEnable := stTMR_WDLampON.DN;


stbMapAB04_O2 := stTMR_WDLampON.TT;


END_IF;


Code:
TONR(Light_Time);
Light_Time.TimerEnable 	:= Not Dark_Time.DN;
Light_Time.PRE 		:= 2000;

TONR(Dark_Time);
Dark_Time.TimerEnable 	:= Light_Time.DN;
Dark_Time.PRE 		:= 2000;

Lamp_Output		:= Light_Time.TT;

Here you go!

The TONR Must be declared as a FBD_Timer and not a Timer as you would use in ladder.
 
Also, a minor issue that may not matter in practice:


The content at that link:



https://trutegra.com/using-tonr-in-structured-text/




emphasizes that our TONR(...) calls should be after we set .PRE, .TimerEnable, etc., and before we check the .DN or .ACC tags.


That said, we are not doing manual .Reset's or anything, so I suspect it may either not matter, or offset the lamp behavior by at most one scan.
 
IF AB04_I.7 THEN


stTMR_WDLampON.TimerEnable := NOT stTMR_WDLampOFF.DN;


stTMR_WDLampOFF.TimerEnable := stTMR_WDLampON.DN;


stbMapAB04_O2 := stTMR_WDLampON.TT;


END_IF;

Just Use:




stTMR_WDLampON.TimerEnable := NOT stTMR_WDLampOFF.DN AND AB04_I.7;

stTMR_WDLampOFF.TimerEnable := stTMR_WDLampON.DN;

stbMapAB04_O2 := stTMR_WDLampON.TT;

You dont need the IF etc
 
Last edited:
All four methods suggested here give results good to within a millisecond of expectations, as modeled on a MicroLogix 1100 cf. here, using ladder logic.
 

Similar Topics

Has anyone had an issue with modbus inputs going High ever few minutes with a AB client AOI? I'm receiving discrete inputs from an automation...
Replies
1
Views
665
I have a micrologix 1100 that I am trying to read three data points from it on my safety plc using studio 5000. Any tips or guidance is appreciated.
Replies
4
Views
815
I have upgraded an old RS500 project to Studio 5000, it has thrown multiple errors which I am currently working through. I have looked through...
Replies
8
Views
1,702
How can I achieve the same functionality in Studio 5000? Image 001.png for the old RSLogix500 program Image 002.png for conversion to Studio...
Replies
6
Views
2,480
Hello everyone, I'm starting a re-do of a controls system HMI using a panelview plus 7, and would like to improve the interface. I want to...
Replies
3
Views
2,005
Back
Top Bottom