11

We all know the various ways of testing OO systems. However, it looks like I'll be going to do a project where I'll be dealing with PLC ladder logic (don't ask :/), and I was wondering if there's a good way of testing the validity of the system.

The only way I see so far is simply constructing a huge table with all known states of the system and which output states that generates. This would do for simple 'if input A is on, turn output B on' cases. I don't think this will work for more complicated constructions though.

eglease
  • 2,445
  • 11
  • 18
  • 28
Erik van Brakel
  • 23,220
  • 2
  • 52
  • 66

5 Answers5

6

The verification of "logical" systems in the IC design arena is known as "Design Verification", which is the process of ensuring that the system you design in hardware (RTL) implements the desired functionality.

Ladder logic can be transformed to one of the modern HDL's like Verilog.. transform each ladder

|---|R15|---+---|/R16|---------(R18)--------|
|           |
|---|R12|---+

to an expression like

always @(*) R18 = !R16 && ( R15 | R12);

or you could use an assign statement

assign R18 = R16 && (R15 | R12); 

a latching relay

assign R18 = (set condition) || R18 && !(break condition);

Then use a free verilog simulator like Icarus to develop a testbench and test your system. Make sure you're testcases give good CODE coverage of your logic! And If your ladder editing software gives you decent naming capabilities, use them, rather than Rnn.

(Note: in Ladder Logic for PLC convention, Rnn is for internal relays, while, Xnn is an input and Ynn is an output, as can be quickly gleaned from one of the online tutorials.

Verilog will be an easier language to develop your tests and testbenches in!

It may be helpful to program in some unit delays.

Sorry, I have never looked for ladder logic to/from verilog translators.. but ladder logic in my day was only just being put into a computer for programming PLC's - most of the relay systems I used were REAL Relays, wired into the cabinets!!

Good luck. jbd

There are a couple of ladder logic editors (with simultors) available for free.. here is one that runs on windows supposedly:

http://cq.cx/ladder.pl

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
jbdavid
  • 602
  • 1
  • 7
  • 9
3

We've experimented with test coverage tools for Rockwell Control Logix controllers. Most procedural language test coverage tools do branch coverage or some such; because Relay Ladder Logic typically doesn't branch, this doesn't work very well.

What we have prototyped is MC/DC (modified/condition/decision coverage) for RLL code for Rockwell controllers.. This tells, for each condition in rung, whether that condition has been tested as TRUE, tested as FALSE, and more importantly, if the condition controlled the output of the decision in the rung (well at least the action controlled by the decision) in both true and false directions under some test.

This work is done using a general purpose program analysis and transformation tool called DMS used to instrument the RLL code with additional logic to collect the necessary data.

You still have to code unit tests. The easiest way to do that is to get another PLC to act as a replacement for the mechanical hardware you intend to control, and simply write another RLL program to exercise the first one.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
0

My boss on a constant basis tells me that the testing is built in the logic itself . PLC’s are in fact deterministic so you should practically be able to follow logic and not need to simulate testing. However we’re not perfect. Having framework would really only allow us to step through what we already know, ladder logic really just takes practice to understand how PLCS work.

That being said I did have some good success with a program I made that essentially flipped on and off IO , it could even simulate the counts of an encoder to test what happens when an object gets to a position. Their were assert statements that could get tripped and inform me where my logic faulted. It did catch a few bugs, and that implementation went very well for a system I’ve never touched. It itself was very beneficial and I do think that it could be useful but I’ve gotten a lot better so I find myself not needing it because of my experience.

0

There is a program called LogixPro which has an IO simulator for ladder logic, you can try that.

rlbond
  • 65,341
  • 56
  • 178
  • 228
0

Sometimes on small PLC programs a test program (or subroutine, or ladder file) is written in the project, which is only run when the project is being emulated. The file has some simple logic that says when an output is energised, turn on the input associated with the feedback. You can then control your PLC through whatever HMI is wired up to it and see that the code behaves as expected. Its very important to disable or delete the test program when the software is downloaded to a real site as it can do very strange things in the real world.

On larger projects each device has a simulation mode that does something slightly similar. http://www.batchcontrol.com/s88/01_tutorial/06-modules.shtml

This is nothing like using test frameworks for OO languages, but I haven't really seen any test driven development for PLCs, or even much automated testing.

daniel
  • 471
  • 1
  • 4
  • 13