Sign in to follow this  
Followers 0
BobB

Function Block Definition

18 posts in this topic

SHOCK - HORROR - I have a job where I can see the use of function blocks is viable. Just writing software now. I was under the impression you could write some ladder and then drag and drop into a function block - correct me if I am wrong. I wrote some ladder and then defined an FB under the PLC I am using in the workspace called NCAlarm. It is empty. I have tried to copy and paste and drag and drop the code from the ladder editor and cannot. I thgought this is what I could do - help please if anyone is awake. Silly old bugger bit coming in here I guess.

Share this post


Link to post
Share on other sites
Hi Bob Highlight the rungs you wish to add, right-click, and select 'FB Ladder generation' from the context menu. It then presents all the addresses, and you can define them as INs, OUTs, INTERNALs etc. Works beautifully! Pp Edited by ParaffinPower

Share this post


Link to post
Share on other sites
BobB saw the light AND the light was GOOD!

Share this post


Link to post
Share on other sites
Amen Bob

Share this post


Link to post
Share on other sites
AHHHH!! First reply was too long coming. Had the programs written for 3 generator sets by then. Master PLC program was finished 1/2 hour later. All in ladder. Quite frankly, I was going to use FB for my alarm routines. Had a go this morning - too darn slow!! Quicker in ladder!! Takes 1/2 the time!! It would be good for complex routines but not for simple stuff.

Share this post


Link to post
Share on other sites
And for any complex math calc's, we could even get you using Structured Text Bob.... I am sure that would be more shock horror..... FB's are good, but they do take a bit to develop, they also add to the program size, sometimes more so than what doing the exact same thing in the normal ladder would consume. They can also add to scan time I have found. I am sure that I may be corrected on this however. I find that FB's are best for scaling functions, and also for device control, pumps/valves/ PID etc, expecially with some of the HMI templates we have setup. If you decide you may want to have a crack again Bob, flick us a PM or post here, I am sure most will be more than willing to help. Edited by scottmurphy

Share this post


Link to post
Share on other sites
Cannot see myself ever doing complex maths Scott. The most complicated maths I ever have to perform is some floating point stuff that I drag out of generators from CanBus J1934 - number may be wrong but nearly all the diesel engine manufactureres are using it now. I extract the data via Modbus RTU then fiddle. What ever happened to integers? Darn numbers come out and then there is a divisor, offset etc. Pain in the tail. By the way, I have gone back and fiddled with FBs again and rewrotr the alarm routines. They take up an awful lot of room on the page - why can't they be displayed sideways like all other functions? Not convinced yet - will see how the project goes and then decide whether FBs are good or ladder is good. Scan time is not an issue - a full generator program with Modbus comms to 3 or 4 devices is usually only about 3-4 ms in a CJ1M-CPU12.

Share this post


Link to post
Share on other sites
Cannot insert or change online? Goodbye!!!! Further observations - too slow to write program - too fiddly - take up too much room on the monitor - pain in the 'A'!!! Last job for these little babies - I am commited now and will finish the job but unless there is some complicated logic I will never use FBs again. I do an enormous amount of online program changing. Many times I have routines written to find out the input is the other way around. I developed 2 alarm blocks - NOALARM and NCALARM. Found a contact was the other way around and CX-P would not allow me to delete the NCALARM and replace with the NOALARM (NC = normally closed - NO = normally open) online. You guys tell me this is easier when I have to go offline to change an FB invocation, stop the PLC in the middle of a generator heat run (4 hours into an 8 hour test) to download a program change and have to start the test again after wasting 4 hours for 10 people when I could just do an online change by putting a slash through a contact? No 'B' way!!! I am going back to straight ladder. Stick FBs!!! Edited by BobB

Share this post


Link to post
Share on other sites
Hi Bob, I can change FB body online no problem . Change from NO to NC, insert new rungs and internal symbols etc etc. Just Double click the FB call to edit the Instance and then Ctrl-E to begin online edit. Are you sure you're using the latest software? I might never convert you to FB lover, but at least I can make sure your well informed Regards, Bertie.

Share this post


Link to post
Share on other sites
Thanks Berti I was not trying to edit an instance online but to delete an NCALRM FB and then insert an NOALARM FB. They are the only 2 I am using and rather than edit my NCALARM i wanted to insert the NOALARM as it is the correct one for the job. Editing one instance when all the other instances would be standard would only cause confusion to anyone trouble shooting up the line. The other annoying thing I noticed is that normally if one uses the sams output number twice (yes I program with I/O numbers and symbols - combination) in ladder CX-P warns you that you have used the same output twice - programming with FBs there is no warning when the same oputput is used twice. It may be that I am using raw I/O numbers without any symbols, will document later, but it should warn you. I have not tried to compile in this situation but hopefully the compiler picks it up. CX-P also has the famous red line when a rung is noy compilable. With FBs the red line goes away when the inputs are satisfied - you can, I presume, forget to put in outputs and the thing will compile and run? Crazy!!! I also update CX-One to the latest version at least weekly and it is fully up to date. It is not all negative by the way - I love the fact that you can place a fairly lengthy description on each instance - saves on documentation if you name each instance descriptively. Edited by BobB

Share this post


Link to post
Share on other sites
Hi Bob Why not have one Alarm block with one NC and one NO input leg. When it is an NC alarm put Always Off on the NO leg and if it is a NO alarm but Always On to the NC alarm leg. Banker

Share this post


Link to post
Share on other sites
That is a good idea thanks but my major gripe now is that you cannot insert an instance online. My secondary gripe is the acres of screen the dang things take up. I have a Dell Vostro 1710 with a WUXGA screen running at 1920 x 1200 - it is a brilliant screen and gives me heaps more ladder on the screen at a time. T9300 processor with 4 gig of RAM and it fairly flies. 1 1/2 very simple FBs take up the whole screen. turn the sideways like functions and allow insertion of instances online and I may reconsider.

Share this post


Link to post
Share on other sites
I agree with this, the AB implementation of the Add-On instructions is far superior. I tend to try and limit the amount of visible in/out parameters purely for this reason, have started using pointers, with only key variables external to the FB. FB's take time to perfect, at least they can be edited online (in the latest CPUs ), whereas the AB ones is not available till the next version I believe.

Share this post


Link to post
Share on other sites
All depends if the FB is a 're-usable' type or not Bob. Are the functions in your FB process in a single scan or over multiple scans ( timers etc ). If in a single scan, then you can use the same instance as previous, saves a bit on FB memory as well.

Share this post


Link to post
Share on other sites
What do you mean by re-usable Scott? I have stored my FBs in the program section for each PLC where you store FBs. There are no timers - just very simple ladder with 2 KEEP functions, one for an alarm latch with a reset and the other for an alarm mute with a reset. I have attached the devestatingly complicated alarm routines that have been dragged into FBs. Maybe the problem is I was writing these extremely complicated routines while drinking the second bottle of a really good Ozzie shiraz. Drinking a bottle right now from Barrosa Valley - YUM! I tried to delete an NOALARM FB and replace it with an NCALARM FB. By the way. I organise my alarms into shutdown, critical and non critical. I then use BCNT to count alarms on, mute on, then compare one with the other and if alarms on are greater than mutes on I turn on the sounder and flash the appropriate light - no they are not red but amber - the international standard for alarm that all the electrical consultants want to be red. (Red flashing lights? A bit old for that I am afraid.) NO_NC_Alarms.cxp

Share this post


Link to post
Share on other sites
Hi Bob, By re-usable, I mean that you only need to declare 1 instance of the block, then re-use that instance as many times as you like in your code. Analogue scaling is an example of re-using the same instance of a FB. So in your attached example, I would create an instance that matches the FB definition name, NCALARM & NO ALARM, then when you want to add/modify the type of FB for a particular contact or Alarm bit, then you just edit the rung, delete the NC FB, insert an NO FB, with an instance that is already declared, NOALARM. Since you are using discretes, and not analogues, this will not work the same, as analogues can have their state updated at each instance of the FB. I have just done some testing, and modified your block slightly to use In/Out variables instead of out only, this then achieves what I was trying to allude to, and you only need 1 instance of the FB. Does this make a bit more sense? NO_NC_Alarms.cxp

Share this post


Link to post
Share on other sites
AMBER for alarms Bob... I Agree..... RED is danger / Stop / or operating... not alarms (as far as I am concerned any ways...) Bob, i would have coded the logic in Excel and simplay pasted as statement then viewed as ladder logic..

Share this post


Link to post
Share on other sites
Re-usable means use the same piece of code in memory over and over again. Can save huge amounts of programming memory.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0