Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

A-B Function Routines

Status
Not open for further replies.

techshoot

Electrical
Aug 26, 2001
15
Many people don't realize that it is possible to write a function in the PLC5 and SLC500 processors that you can pass values to and receive an answer back. This is very useful when you have a great deal of code to place in multiple places. Example of adding 100 to a number below:

1) Create a new file for you function routine
2) The first instruction will be an SBR N7: An integer address for holding the number you want to add (N7:10 example) but make it unique or create a new data file with local scope. Then place an output instruction, OTE B/100 for example.
3) Next rung start do an ADD 100 N7:10 N7:11 to add 100 to your number.
4) The final rung is RET N 7:11 N7:11 is the result of the ADD instruction and this will be sent back to the calling JSR below.

5) In your LAD 2 File, add a JSR with your function program file number and add an input parameter of N7:0 at the end of the logic and keep hitting the enter in the graphic until you see Return Parameter and enter N7:1.
6) Put a value in N7:0 and run the program, N7:1 will always show as 100 more than N7:0.
 
Nice tip, techshoot.
Another example, which I have written for the 90-30 GE/Fanuc plc, is a subroutine I named "UP_SCL", which takes a value from 0 - 100 (for instance a motor speed, stopped to wide open) and turns it into an equivalent 0 - 32,000 integer, which the GE plc uses for it's Analog Output registers. I do a few MOV_INT instructions to put my input values into the correct registers, then "CALL" the subroutine, and then immediately MOV_INT the output into the desired register.
The subroutine is a 14-rung program that takes a little thought to write, but is easy to call again and again. I put my "zero checking" in there as well - any values below zero I convert to zero. This has saved me a lot of time.
 
i want to know about the special features of s7
 
I know well about the S7 and the function capabilities it has are far greater than the A-B. Just simply a matter that the A-B users don't always know about it. By far the most powerful PLC that I have used have been Siemens, unfortunately they are not as common as I would like.
 
I have a question regarding a Allen Bradley Micrologix 1200 PLC. We recently installed a new piece of equipment that uses a Micrologix 1200 and a Panelview 550. The comm port on the PLC is directly connected to the Panelview. What can I install to communicate to the PLC without disconnecting the Panelview from the communication loop. It is a huge pain to make program edits and then have to swap cables back and forth to see the results on the Panelview. Any help is greatly appreciated.
 
Please post as a seperate question while I tried to figure a solution for you.

Thanks
 
Just curious, techshoot: why do you feel the Siemens PLCs are far better than most? My own experience showed that most people who prefer Siemens either started with it, or think that statement-list programming is somehow superior to ladder logic. Not wanting to start a pissing match, just curious.
 
Actually, most of the things you can do with an A-B you can do with ladder in the Siemens PLC. In fact, I prefer to program the majority in ladder and leave the statment list to the function blocks. The real power is not in the statement list, but in what you can do in statement list. With the Siemens PLC and statement list, you can dynamically allocate memory, create new blocks (or temporary blocks), do low level processor functions, and many more things that you keep discovering the more you use it.

I will agree that the A-B is easier to use and I believe the brand PLC is a redundant argument for 90% or more of the applications. I have not tried to change anyone's mind about a processor brand, though I have helped OEM clients convince their customer due to the OEM's preference (and every time so far it has been to A-B). No worry to me about any pissing match since it isn't all that important to me what brand I use for most applications.
 
This is for Shotgunner. You could set up a DH485 Network. This is easier than it sounds. Simply add an 1746-NET-AIC(Advanced Interface Converter) at the PLC and another at the PanelView. Conect them with the appropriate communication cabling, and you will be able to access the PLC from either location. More detailed information can be found at
 
Can you write funtion subroutines for AB Micrologix 1500? I am familiar with Siemens S-7 226 subroutines.
 
Unfortunately, only with the PLC5 and now the ControlLogix/CompacLogix/FlexLogix processors. Highly recommend looking into switching to the new processors as the cost comparisons are very favorable with greater capabilities.
 
Gents,
I agree with techshoot that subroutine functions are easier in PLC, and ControlLogix...in fact in CLX I use create a User Defined Data type for ALL my subroutinesand simply pass one variable with all the routine data.

BUT the same technique also works for the SLC and Micro1500...just a little more work. Write the device or logical subroutine and point ALL the data in it to one N file dedicated to it. Typically I will use the first word or two as flags, and the rest as true integer values. If Reals are needed define a separate F file.

Give everything in this file a symbol such as _Run (N10:0/0), or _TimeMax (N10:1). Then using the database export tool get it into Excel.

Using Excel cut and paste the variables you have just made and create new N files (say N11,N12), but now dedicated to the device or logical objects you are working with. Then use Search and Replace to create for example, Pump1, Pump2 would become:
P1_Run(N11:0/0), P1_MaxTime (N11:1), or P2_Run (N12:0/0), P2_MaxTime (N12:1).

In this way you can quickly create lots of very well organised datatable, complete with full symbols and comments if you wish.

And finally, in the ladder simply use the COP instruction to copy the file say beginning with P1_Run onto _Run. (COP N11:0 N10:0 LEN 2)

Call the SBR and then immediately after do another COP of _Run back onto P1_Run. (COP N10:0 N11:0 LEN 2) and Voila!@! the subroutine has passed its data back to the device data table.

If any of you are interested I am happy to email an SLC .RSS example project file that uses this technique.

Then
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor