nailian
Hi

I'm stuck in ST language timer usage. I'm not implementing to any hardware, just using PLC Simulation mode. My problem is that after setting of timer (both tried for TP, TON and TOFF) and applying TRUE to IN input, ET does not count, Q still remains FALSE (Not sure if this helps or true, even if ET is forced to a higher value than PT, Q does not go from FALSE to TRUE). I can use Timers in other languages (at least tried for LD, FBD and SFC). Also tried if any extra ENABLE/EN/ENA input exists, but result is negative, the compiler gives error.

A test intended program and its debug result is given in the screenshot. It can be seen that even IN is TRUE, ET is not counting time.
(Depending on the given test program, timer IN is TRUE for two separate period of times)

Thanks

Screenshot_2.png


EDIT: Also discovered that the same problem occurs in IL language. With these languages in variable table window, also the "Initial Values" column is not working for Timers/Counters.
Reply 0 0
clintux
Where have you declared the instance of your timer "myTimer2"?
Reply 0 0
r2k-in-the-vortex
It's declared right there in program0, but TON is a function block, you need to call it or its just a structure sitting there doing nothing.
myTimer2(); if you have already set its inputs
Or
myTimer2(in=:true, pt:=t#1s, q => B); if you want to set them while calling it. And read output too.
Reply 0 0
clintux
That is exactly where I was headed, but we can't see if there is more to the program after line 19. myTimer2 is just a variable declaration of type TON but a TON() FB with the same name needs to be instantiated in the program.
Reply 0 0
r2k-in-the-vortex
Thats some sort of semantics confusion, Variable declaration is the instance.... you can't (easily) instantiate function blocks in program runtime, but you can call instances you have declared.
Reply 0 0
nailian
Thank you everyone, i followed your answers and solved the problem.

Let me clarify depending on your answers:
-The instance "myTimer2" is declared locally inside the "variable table" (not sure how to call this technically), since in OpenPLC Editor i could not run the defining keywords like "VAR-END_VAR", so that i fill all the labels/variables in that table.
-Using "myTimer2();" text for one time solved all of my problems, thank you for this advice, because i have not seen this kind of usage in ST language in any 'limited' tutorials as you mention that it is a FB and as i can deduce it needs to be invoked (maybe once, maybe in all scans, but this structure works properly). I thought defining Timer FB on the table is already enough to start/run.
-Also, there is no more program after line 19. As mentioned, this is a chopped version for just TON testing purpose. 

Again, the working ST text is attached. This code is intended as a brute force test of TON FB. 'myTimer2' is still needs to be declared in the table. Debugger window screenshot is not added, but myTimer2 works properly. Thank you all for your attention, effort and advice again.


st_solution1.png
Reply 0 0
r2k-in-the-vortex
It helps to know the IEC definition of pou types from this perspective.

A program has only one instance, is called and can only be called by system, can't call program in user code.

FB can have instances and these instances may be invoked from anywhere during runtime.

Functions have no instances and may be called from anywhere, including variable declarations which run during setup phase.

Well... theoretically it is so, in practice each IEC implementation is a snowflake and does things slightly off from  standards ideal.
Reply 0 0
Reply