Beckhoff Twincat using functions

Join Date
Nov 2011
Location
Ireland
Posts
182
Hello

i have created a function in PLC control in the twincat system. the function has been created using ST while the main program is written in LD.

i am not sure how i use the function in the main program??

i thought that it would be a case of adding it as a function block however i now believe that "functions" and "function blocks" are different

the following image shows the function and the main program. i am trying to use the "function" in the main program. if anyone could tell me how to do this it would be great.

twincat function.jpg
 
First of all, I never use LD to program anything, always ST, therefore my "help" is only possible after searching the help system (Infosys) and pasting what's written there.

After the small "disclaimer" :)

What I've found:

'Insert' 'Function Block' Shortcut: <Ctrl>+<B>

Use this command in order to insert an operator, a function block, a function or a program as a POU. For this, the connection between the contacts and the coils (cursor position 4), or a coil (cursor position 3), must be marked. The new POU at first has the designation AND. If you wish, you can change this designation to another one. For this you can also use the Input Assistant. Both standard and selfdefined POUs are available.

The first input to the POU is placed on the input connection, the first output on the output connection; thus these variables must definitely be of type BOOL. All other in- and outputs of the POU are filled with the text „???“. These prior entries can be changed into other constants, variables or addresses. For this you can also use the Input Assistant.

It looks like you just have to press Ctrl+B and then insert the function name and parameters there, this information have been copied from the help system in this path: TWINCAT >> TWINCAT PLC >> TWINCAT PLC CONTROL >> EDITORS >> Ladder Diagram Editor

Good luck!
 
insert BOX with EN
now click on the AND and press F2 or right click
the function will only be executed when the ENable input is true.
watch the type of the output if BOOL you can set a coil this has to be declared. on the next rung you can ask the status of this coil.

obvious this is not the neatest method but as you are still learning good point, as yes it is possible.
when you learn CFC, you will notice a big improvement in readability of your program, but for now fine.

A better way to do this:
for PLC_PRG use Structured text.
in this you can call a Ladder as a program, or a function block.
i saw you are using MAIN,
when you are editing your program it is possible you can not start it although PLC_PRG or MAIN is present. then goto tasks and make a task freewheeling and the POU is called PLC_PRG or MAIN. (just to keep you out of trouble this is) in the tasktab you can run several programs running together, and even do some interuptpou.
 

Similar Topics

Hi I'm doing a simple writing to .CSV file. I want to write the headers, but I have hard time indentifying when the file is empty. One idea was...
Replies
1
Views
2,000
Hi, I want to write a string into a file. This has to happen within a funcion (FUN, no FB) since I want to use it to log stuff to a file...
Replies
3
Views
6,591
Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
1,013
Hello, I was wondering if anyone know how to upload a PLC program to the Beckhoff TwinCAT 3 from a file? i.e. without having the development pc...
Replies
0
Views
758
Hi anyone got any tips and tricks?? I'm at a stage wherei need to tidy up my hmi project and give all objects sensible names, I did start this...
Replies
0
Views
962
Back
Top Bottom