Idea: Put all of the logic for a PLC program in a function block.

theColonel26

Lifetime Supporting Member
Join Date
Feb 2014
Location
West Michigan
Posts
781
So I have this situation where I need to debug a major change to a program for a machine. I have very limited time on the actual machine and it is at a customers location. I can run it on another PLC or run a simulation but that does not simulate the mechanical logic of the machine itself. So I was thinking why not create practice of putting the entire logic of the PLC programs in a Function block. That way in the future you could write logic around it to simulate the physical state of the machine. In production you would have IO addresses for input and outputs of the function block but during debug you would have variables as Inputs and Outputs that are controls by the logic if you machine simulator code.

Thoughts? has anyone every done something like this?
 
Encapsulating logic into a function block general limits your ability to edit it, and to expand or change the input or output elements.

And it would also probably limit the execution of each sub-routine to just the execution of the main routine. Any controller operating system features that give you asynchronous or time-based or event-based execution management would be unavailable.

I have certainly built machines where I buffered the inputs and outputs, or ran them in parallel with virtual/test data.

I really don't think that a Function Block is the right way to approach virtualization or simulation of an industrial process.
 
Not a chance here - if you must use FBs use them for repeatable code IE scaling or reusable motor starting circuits. Think about the poor electrician who has to trouble shoot the machine who can understand ladder logic but little else. Takes too long anyway - I can write ladder much quicker than FBs and it is easier to commission and trouble shoot.
 
I have an old SLC505 hanging in my office, that I normally use to simulate IO, so if I need to test the works out of a PLC program, I will dump the program in a PLC that match the setup and connect the IO's I wold like to simulate to my SLC, maybe this is a little overboard, but I get a good simulation where I also can press the scantime in real time without adding extra test code :)
 
i just make a global flag "sim" that enables logic which simulates the system to write to the inputs by using the "force_bit" block, and my analog input block takes a value from the simulation logic when SIM is active.

in allen bradley land I couldn't figure out how to programmatically force the inputs so I did as Ken says and buffered the inputs so that when SIM was active the program would write the models state to the buffered input tags, and when SIM was false the program would write the inputs to the buffered input tags. all of the logic looked at the buffered input tags instead of the physical IOs.

There is no advantage to putting the whole program in a function block that I can see.
 
What platform are you using?
For this project Omron.

Encapsulating logic into a function block general limits your ability to edit it, and to expand or change the input or output elements.

And it would also probably limit the execution of each sub-routine to just the execution of the main routine. Any controller operating system features that give you asynchronous or time-based or event-based execution management would be unavailable.

I have certainly built machines where I buffered the inputs and outputs, or ran them in parallel with virtual/test data.

I really don't think that a Function Block is the right way to approach virtualization or simulation of an industrial process.

i just make a global flag "sim" that enables logic which simulates the system to write to the inputs by using the "force_bit" block, and my analog input block takes a value from the simulation logic when SIM is active.

in allen bradley land I couldn't figure out how to programmatically force the inputs so I did as Ken says and buffered the inputs so that when SIM was active the program would write the models state to the buffered input tags, and when SIM was false the program would write the inputs to the buffered input tags. all of the logic looked at the buffered input tags instead of the physical IOs.

There is no advantage to putting the whole program in a function block that I can see.
Ken and V0n, you are right, I think that would be a much the better approach rather than a function block.

Have you guys ever made a standard practice of IO buffering as you call it? So that this so that you can easily drop simulation logic in later?
 
Last edited:
I do exactly the same of having several "simulation" bits that enable special code to simulate inputs based on what the outputs does.
I even put the simulation right inside my reusable function blocks so that I get the simulation for free when I add an instance of the function block. An this also disables the real outputs so you dont damage something if you run the program on a real machine.

A tip: Reset all the simulation bits upon 1st scan. This so you dont forget to turn the simulation bits off when you leave the machine.
 
I agree with bob 100% , ladder is the way to go , think of poor maintenance person who has to work on the machine, Function blocks, structured text and add-on instructions have there place , finding that there being over used. What I have run into lately is that some programmers do not understand relay logic so they find ladder hard to understand , Ladder is far easier to commission machinery also.
 
The most stupid thing I have ever seen was a specification that required ALL program to be in an FB. This meant that the programmer had to write an FB for 2 contacts in parallel driving an output! Absolute stupidity! And he had to write it in ST for heavens sake!
 

Similar Topics

Hello, Concept: Input should remain for a given time so as for the PLC to look into. What to do if my input can change its value, which is...
Replies
7
Views
2,458
A repeated theme that I see on this board is always talking about documentation. Last year for the final for my class, the students paired up and...
Replies
19
Views
6,166
I am trying to create an agnostic product queue builder using PLC ladder logic. I have a pallet conveyor and would like to be able to use a NO or...
Replies
18
Views
2,177
Hi all, I have been working on a tool for my company that handles a specific task our company runs into often related to PLC's. This is a tool I...
Replies
15
Views
2,854
I asked this question briefly in my previous post long post, I'm asking again here as the main point so it doesn't get buried. I am pretty new at...
Replies
3
Views
1,487
Back
Top Bottom