views:

641

answers:

3

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.

+3  A: 

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

jbdavid
Very nice! I'm going to look into that simulator soon, hopefully.
Erik van Brakel
A: 

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

rlbond
+1  A: 

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 there 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