Siemens Ladder logic - must be a better way...

DLMUK

Member
Join Date
Jun 2013
Location
Southampton
Posts
311
Hi,

I need a bit of help from you more experienced programmers please. I have a bit of ladder logic, which "works", I don't think it is the smoothest but I have tested it on my PLC and it does what I want it to do which is...

I have a multiple RS485 modbus RTUs, they go into a serial server, then my PLC connects to the serial server via modbus TCP. The Serial server does not have a watchdog on it, therefore, if one RTU drops out, all the PLC sees is that the value of that particular RTU just remains the same.

Therefore my program looks at the input (which is constantly changing), saves the input value, then saves the input value again 1 second later. If the value hasn't changed then it activates a timer, if the timer doesn't get interrupted for 10seconds (10 matching values) then an error flag is generated.

I have this over 4 networks in an FB. What i want to know is, can I make it more concise? Reason being is that I have 46 RTUs and don't want to repeat anymore code than I need to.

Code can be found here...

https://www.dropbox.com/s/tj2em2az8dohx34/fb.png?dl=0

Thanks!
 
Which PLC are you using? I would think this would be the same either way, but the 300's do have some mighty specific rules.

Network 3 probably should still happen after the rest, but I think networks 1/2/4 can all be combined.

Move, compare (I think use <> instead of ==), timer, coil.

I also typically recommend the IEC timers instead of the S5 style ones, but that doesn't really effect the overall flow. The IEC timers are stored in a DB instead of Timer memory. You can multi-instance it into your FB, instead of creating a new tag for each timer.
 
I would create a specific FB for this function and pass the variable in and out. Rather than using a timer, increment an integer variable every time the values are the same and reset the variable to 0 if the values change. If the variable exceeds the limit value then you have a fault condition.

As you have 46 signals to monitor, call your FB 46 times in a multi-instance fashion so you only need 1 instance DB and not 46.

Nick
 
Manglemender has the correct answer.
If your code needs timers, then add these as SFB4 "TON" in the FB declaration. In this way they become embedded into the instance DB.
Definitely do not use S5-Timers with FBs.
 
Thanks for the replies, can you expand a bit on what you mean below? I understand the general concept of what you are saying but would you create a 2nd FB which calls the first one 46 times?

thanks

As you have 46 signals to monitor, call your FB 46 times in a multi-instance fashion so you only need 1 instance DB and not 46.

Nick
 
Thanks for the replies, can you expand a bit on what you mean below? I understand the general concept of what you are saying but would you create a 2nd FB which calls the first one 46 times?

thanks

Yes. I would create one FB, with your couple rungs of logic and the IEC timer. I would also create another FB that calls the first FB 46 times, once for each RTU. This 2nd FB would only be called once, from your main code. You would need to create an instance DB for the large FB, but each of the smaller FBs can have their instance data contained in the main DB, as a multi-instance.
 
Attached is a program only project which demonstrates what you need. FB1 is the checking block and FB2 contains multiple instances of FB1 declared in the Static section.

It was written in S7 Classic but it should import and execute OK.

Nick

Just realised the FB1 is missing a line of code to save the last value on the rising edge of the clock pulse. Insert after the checks.

Nick
 
Last edited:

Similar Topics

Hi. I have 2 files where I would like to see the ladder logic differences (similar to the Rockwell compare function). I am using TISoft Siemens...
Replies
1
Views
1,264
I'm having a heck of a time figuring out how to efficiently move the decimal value 1150 into MW20. Can this be done using the MOVE command? Does...
Replies
17
Views
6,848
Hi I have just started using Siemens S7 PLC for a mechatronics degree. I have used Matushita PLCs before but I am having difficulty with Siemens...
Replies
4
Views
3,670
Hello there, I am currently taking my final year project and working out in my ladder logic programming. I am finding some difficulties on...
Replies
76
Views
32,275
Why we do use more than one networks in Ladder logic of Siemens PLCs ? whats the need of using more than one networks in programming a task...
Replies
8
Views
5,092
Back
Top Bottom