Converting C/C++ to Ladder Logic

palk

Member
Join Date
Oct 2009
Location
USA
Posts
1
I know this may sound odd, but we have a need to convert a C/C++ application to ladder logic to run on a Modicon PLC. Does anyone know of a conversion tool that can assist us in this conversion process?
 
We have Eberle PLC's that have the same function. The Eberle has the option of text based logic or ladder logic. The computer attached to the Eberle streams ascii directly over to overwrite the current text program. Its not a Modicon solution but maybe it can help give you an idea? If your only wanting one conversion to ever take place your going to have to write down the C++ process logic into a flow chart and write your PLC program from scratch.
 
I can't imagine there is such a tool. It just doesn't come up enough to generate the need and it would be such a monumental task that almost no one would choose to do this just for fun.

If you have a lot of C/C++ experience and no ladder logic experience then you have to get a few thing straight in your head.

The main issue comes in with the way the program is scanned, especially operator inputs. A PLC program must always loop through the entire program in a set amount of time or it will fault (usually called a watchdog fault). Therefore, you cannot "wait" in a loop for something to happen or someone to press a button or the machine will fault. You can have short loops in the program but they END in time for the program to finish before the watchdog timer.

What helped me was the idea that the control of the program falls through the ladder diagram. You should not do anything that will stop the falling.

As spaceacealpha pointed out, your best bet is to put together a flow chart.

If you have specific questions along the way, post them here.

If you are not set on the PLC you may want to go for something based on IEC-61131 (Maybe the Modicon does, I have no idea) which uses a language called Structured Text (ST) that at least is entered as statements like C (you even get the semi-colon at the ends of the lines ;) ).

Anyway, good luck, sounds like fun!
 
I know this may sound odd, but we have a need to convert a C/C++ application to ladder logic to run on a Modicon PLC. Does anyone know of a conversion tool that can assist us in this conversion process?

This really isn't so far fetched, actually. It's no different than writing a compiler. The main issues are:

* - What is your destination controller. If you want to compile to ModSoft, forget it. If you want to compile to Unity then absolutely.

* - You'll have to take PLC issues into account. Things like
Interrupts and the lack of a coil type instruction in a higher-level language.

Years ago I wrote a simple compiler for Allen-Bradley's 1771-DR module. The thing was unsupportable without it (I worked for A-B tech support at the time and had to support that beast). I also did the parse trees for a high level type language which was designed to compile to any PLC that supported ASCII import. The main problem is:

* Do you know how to write a compiler...

Good Luck,

(8{)} :) .)
(Yosi)
 
One concern I would have is scan time. Is this an embedded controller? PLCs can be quite slow compared to "some" embedded devices. Is this thing doing something that requires high speed processing.

I would also make sure that all of the peripheral items can be handled by a plc. networking, persisting data, etc.

If it's just a fairly simple sequencer then no problem. Scrap it and start from scratch with the plc.

The other way around would be a lot more fun. 🍺
 
This sounds like a fun challenge.

Is it a large program? Can you post it? Where is the program originally run? PC or embedded controller?

I mean that if you even consider to convert to ladder it must only be logical functions and pretty straight forward.
 
We once needed to replace some ferranti hardware with a plc now these used some type of basic, in the end we forgot the code, worked out what each module did with the help of an old spec sheet & the listings then just wrote the code required.
forget trying to convert any other language into plc code it's quicker to understand what the plant is required to do & start again.
 
There is a C toolkit available for Modicon. It is an add-on toolkit to be bought along with Unity programming software. may be that will help you.

I have experience in C and Modicon. PM me your excat requirements and code. May be I will be able to convert and send back you the PLC program.
 

Similar Topics

Hi there! I am new to PLC's, and I have undertaken the task of converting a primarily pneumatically-operated machine to electrically &...
Replies
5
Views
2,706
Hi all, Please understand that I am not good at English. I have plan to project with one of our customer have the Ls XGB-XBC-DR60SU PLC. This PLC...
Replies
1
Views
1,484
Hello there! I have a code that is in ladder logic and would like to see it in structured text. The software in which the code was written in was...
Replies
9
Views
21,906
Hello, Calling on all SattCon nerds – or any other helpful souls! I have to transcribe a program originally written in DOX 10 for SattCon...
Replies
13
Views
5,066
Hello, I have to update some PLC firmware (FX1n), the devices out on the market are reflashable via rs232. I cant find where the GX developer...
Replies
0
Views
3,364
Back
Top Bottom