Function Block Problem

shantanuc

Member
Join Date
Nov 2020
Location
Aachen
Posts
1
I am using Codesys as my PLC Programmer. I use structured text as the language.
I tried using a timer inside a function block and then mentioning it in variables of main program but its not getting started. the (IN) of the timer is not getting a TRUE value.
If i write the same code in PLC_PRG then it works.

Do i need to do anything additional to make my timer run? Please Help
 
Normally you would never reference a timer that is inside of a function block from outside the function block itself. More normal would be to have an input to the function block turn on the timer.

Function blocks are meant to encapsulate a subset of code that you would re-use many times. In this way, you write the code once and then define multiple instances of the code and use it.

Here is a video I made that attempts to help you learn about function blocks and their use:
https://youtu.be/aYwH2O_QOQo
 
I am using Codesys as my PLC Programmer. I use structured text as the language.
I tried using a timer inside a function block and then mentioning it in variables of main program but its not getting started. the (IN) of the timer is not getting a TRUE value.
If i write the same code in PLC_PRG then it works.

Do i need to do anything additional to make my timer run? Please Help




Can you provide more explanation and perhaps screen capture to show us what you mean.


Are using a global tag or are you addressing a tag declared inside the function block? Are you getting any errors or is compiling error free but the time doesn't start?


What I show in the attached screenshot is bad practice but it shows that it is possible, provided the tag is declared as VAR_STAT; a tag declared as VAR will is not accessible from outside the block and if you try you will get compile error.

timer.PNG
 

Similar Topics

Hi guys, I have a problem with one shot fp when using it in FB. Fp variable is declared as a stat variable. For some reason it isn't one shot. It...
Replies
2
Views
4,587
Please see attached file. I need this program in Function Block form but I am totally lost on this. Any help would be appreciated. Thanks!
Replies
8
Views
260
Hi! I am using a TM200CE40T PLC from Schneider to write data over Modbus. I have used Memory words (%MW) before using the Write variable...
Replies
1
Views
513
Hi folks. New to the forum, but been working with PLCs for several years now. Would like some advice on whether you would keep this logic, or...
Replies
9
Views
1,043
Hi Yes, I'm stuck again. Trying to define a Function Block. What I've put in there so far has been a straight copy/paste from the code (and that...
Replies
22
Views
2,648
Back
Top Bottom