Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing ladder logic

Tags:

logic

testing

plc

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.

like image 445
Erik van Brakel Avatar asked Sep 16 '08 10:09

Erik van Brakel


People also ask

Is ladder a logic software?

Ladder logic is a programming language that represents a program by a graphical diagram based on the circuit diagrams of relay logic hardware. It is primarily used to develop software for PLCs used in industrial control applications.

How do you read ladders in logic?

Ladder logic is read from the left hand rail to the right hand rail and from the first rung to the last rung. In short – LEFT TO RIGHT AND TOP TO BOTTOM. The rungs contain input symbols that either pass or block the logic flow. The result of the rung is expressed in the last symbol, known as the output.

How do you simulate a ladder in logic?

To perform ladder diagram simulation in Simulink, you must connect input and output blocks to the ladder model that match the actions that the ladder diagram inputs and outputs perform. Connect input and output ports to the PLCControllerSuite block to provide inputs for simulation and to read the outputs.


2 Answers

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

like image 71
jbdavid Avatar answered Sep 28 '22 18:09

jbdavid


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.

like image 33
Ira Baxter Avatar answered Sep 28 '22 18:09

Ira Baxter