PLC

dani1

New Member
Hi all

Is it possible to do a Programmable Logc controller with picaxe ?

The problem is that PLC worc with ladder diagram programming , it means that this
ladder my contaim several branches and each one my contain some delays .

Do I ned some OS to incude with the main program ?
Which one ?

Thanks
Elico
 

westaust55

Moderator
Welcome to the PICAXE forum.

It is not possible to program a PICAXE microcontrollers using ladder logic as if it were a PLC.
While it may be possible to achieve something similar, it would require your writing subroutines or other sections of code to act like the the PLC rings, emulate the various types of output "coils"/timers, etc.
I suspect the would take a lot of program space.

The PLC has a special interpreter that allows it to understand the ladder logic. Some PLCs do have alternate "interpreters" that allow other programming structures.

The PICAXE microcontrollers use a BASIC language interpreter.
This can be programmed using either a text based programming format or a flow charting format.
 

mikeyBoo

Senior Member
Picaxe emulating a PLC (but NOT a real PLC)

It’s possible to emulate a PLC using a Picaxe or other uProc running BASIC. It is usually easier to read a printout in ladder logic format rather than raw BASIC code (e.g. machine control logic).
In most cases it’s easier to just use a real (cheap) PLC if you’re controlling simple discrete IO.

The only reason I’ve found to emulate a PLC is when you need functions provided by a uProc that are not usually found on inexpensive PLCs (I2C, display controls, etc.). This is how I did the code for my Picaxe kayak control project (it’s BASICally a little PLC with I2C & OLED outputs). The Picaxe is particularly well-suited for small PLC-style control applications where speed & danger are not issues. HOWEVER, the Picaxe would NOT be suited for high-speed industrial applications because of the speed issue & no watchdog timer.

The attached .pdfs show an old MCS-BASIC program emulating a PLC for a simple building alarm system (this same little app could be done much easier in Picaxe BASIC because of all the included bit-control commands). The Picaxe is not a PLC but it can certainly mimic one.
 

Attachments

hippy

Technical Support
Staff member
A rainy day and a few hours to kill proved it's not too hard to create a ladder logic to PICAXE Basic converter. The trick was in realising that, if one has an 'ASCII art' text file which represents the ladder program, it's mostly just a matter of stepping through that from top right and heading leftwards to determine the code to generate.

A rather quick and dirty attempt has most things a ladder program would use supported -

Digital input pins: [Xn], [In], [CBn], [C.n]
Digital output pins: (Yn), (On), (CRn), [B.n]
Digital output states as input: [Yn], [On], [CRn]
Digital variables: (Vn), [Vn]
Digital flip-flop variables: (Fn), [Vn], [Fn], [Qn]
Countdown Timers: (Tn=seconds), [Tn]
Branching: -.- -^- -+- -&-
Signal inversion: (/xx), [/xx], -/-
Signal reporting via SERTXD: -#-

That allows the standard on and off button control of a LED to be created with -

Code:
|---[X0]---.---[/X1]---------(Y7)---|
|          |                        |
|---[Y7]---'                        |
Set input 'X0' (pin C.0) high to turn the output 'Y7' (pin B.7) LED on, set that low and set input 'X1' (pin C.1) high to turn it off again. The '[Y7]' input is the state of the (Y7) output.

The code for that is similar to the following -

Code:
dirB.7 = 1
Do
  bit0 = pinC.0 | outpinB.7
  bit1 = pinC.1 ^ 1 & bit0
  outpinB.7 = bit1
Loop
The full code which can be simulated in PE6 is -

Code:
#Picaxe 20M2
#Terminal Off
#No_Data

;         .-----_-----.
;         :           :
; pinX1 --| C.1   B.6 |-
; pinX0 --| C.0   B.7 |-- outpinY7
;         `-----------'

Symbol pinX0      = pinC.0
Symbol pinX1      = pinC.1

Symbol outpinY7   = outpinB.7   : Symbol dirY7  = dirB.7

PowerOnReset:

  dirY7 = 1       ; outpinY7

MainLoop:

  ; |---[X0]---.---[/X1]------(Y7)---|
  ; |          |                     |
  ; |---[Y7]---'                     |

  bit0 = pinX0 | outpinY7
  bit1 = pinX1 ^ 1 & bit0
  outpinY7 = bit1

  Goto MainLoop
I am not that familiar with ladder programming but it seems to be able to handle most things one would want from ladder programming with a PICAXE. Because it's thrown together it's not capable of taking any random ladder program at present, one cannot for example do -

Code:
|---[X0]---.---[X1]---.------(Y7)---|
|          |          |             |
|          `---[X2]---'             |
But that can be worked round with -

Code:
|---[X0]-------&-------------(Y7)---|
|              |                    |
|---[X1]---.---'                    |
|---[X2]---'                        |
Or more simply, by just arranging the order -

Code:
|---[X1]---.---[X0]----------(Y7)---|
|          |                        |
|---[X2]---'                        |
As noted timers are implemented -

Code:
|---[X0]------------------(T1=10)---|
|                                   |
|---[T1]---------------------(Y7)---|
Which will keep the Y7 LED on for 10 seconds after X0 is released. But I am not convinced my timers are well implemented.

I can free-run flash an output 10 seconds on, 20 seconds off with -

Code:
|--[/T1]--[/T2]---(T1=10)--(T2=30)--|
|                                   |
|--[T1]-----------------------(Y7)--|
But the following, which looked to me like it would work, has a subtle issue with T2 never triggering. T1 hits zero at the end of the ladder so it gets reset on the next iteration through the ladder before T2 has a chance to trigger -

Code:
|---[/T1]---[/T2]---------(T1=10)---|
|---[/T1]---[/T2]---------(T2=20)---|
|                                   |
|---[T1]---------------------(Y7)---|
Maybe I've just accidentally burnt my first virtual factory down :)

I guess I'm going to have to read up on PLC's, ladder programming, and timers in particular.

It doesn't help that every PLC manufacturer seems to have done things slightly different, often use different naming conventions.

One thing which would be useful to know from someone who is more familiar with ladder programming; is what the following should do -

Code:
|---[X0]-----------(T1=10)---(Y7)---|
Is output Y7 set from the X0 input which also sets the timer or is Y7 set while the T1 timer is set, non-zero ?

If anyone wants to create a not too complicated ladder program and post that I can see what that generates. And if anyone can think of anything I am missing let me know.

Being PICAXE it could make sense to allow analogue inputs [A0>=10], servo (S1=150), and PWM (P1=75%) control, but those are not supported yet. It's also hard coded for the 20M2 at present.

Ladder programming does get the occasional mention on the forum and, if it does seem useful, I can look to see how best to turn what I have into something more easily usable by others.
 

techElder

Well-known member
From working around machines being repaired, I was always under the impression that "ladder" programming was just more convenient to do on the machine's hardware without a full programming environment. Perhaps that's just an "old" idea?
 

Buzby

Senior Member
I have years of experience programming in ladder, but it's moved on so much that modern ladder would be difficult to process with a language like PICAXE BASIC.

A programme to support simple ladder diagrams, e.g. with no forward branches and in-line functions, would be reasonably easy to decode, but the biggest problem, even with a simple structure, is how to enter ladder diagrams into a PICAXE.

The simplest method would to parse a text file into opcodes, then decode them very much like PICAXE interprets BASIC.
However, if you want a 'real' PLC programming interface, with incremental editing and visual debugging, then it would be a real labour of love. ( You can buy a CUBLOC for $35, programmable in ladder and BASIC at the same time. http://comfiletech.com/cb220/ )

For anybody who really want to give it a go, I've got a few ideas to throw in the pot.

Cheers,

Buzby
 
Last edited:

Buzby

Senior Member
... and to answer hippy's question
... One thing which would be useful to know from someone who is more familiar with ladder programming; is what the following should do -

Code:
|---[X0]-----------(T1=10)---(Y7)---|
It all depends what manufacturer, and decade, you are attempt to replicate.

The earliest ladder logic could only have the timer on the right hand end of the rung, in the position known as a 'coil'. Then other rungs would use 'contacts' from the timer 'coil' as they needed.

Nowadays a timer 'block' can sit mid-rung, and it outputs a few digitals ( 'timing' and 'timed' usually ) and an analogue of the current elapsed time. It can also be of different types, e.g. simple On-delay, simple Off-delay, accumulating On-delay, monostable, etc.

The first step in writing a PLC emulator is to decide what ladder variant you are going to replicate.

Cheers,

Buzby
 

mikeyBoo

Senior Member
For those folks who aren’t familiar with ladder logic

Ladder logic is the lingua franca of industrial electrical controls. It’s very similar to electrical elementaries or “ladder diagrams”. This is why a redneck yahoo from the states feels right at home on an American or German PLC. The ladder element may say “Ein/Aus” or “On/Off” but the symbols are the same (regardless of the programmer’s native tongue).

Most competent electricians/techs/engineers would be able to troubleshoot & repair a machine documented in ladder logic while many would not be able to repair a machine with a C/Python/BASIC (etc.) printout.

Picaxe projects are usually simple enough to not need a ladder diagram, but for those projects that need to be repaired in the field, a ladder diagram printout can be very helpful. The easiest way (for me) is to draw out a ladder diagram on paper or computer, then write BASIC code for each rung. Add rungs as needed.

An on-screen PLC-style ladder editor would be nice. Maybe in a future version of Picaxe editor?

Picaxe “pseudo-PLC” main proc: (endless loop):
/—>Read real-world Inputs to image registers
| (bytes from PC if needed (on-screen controls))
| update timers
| evaluate rungs
| update real-world outputs
| (In/Out image bytes to PC (if you need graphics))
| |
\<———————/
 

techElder

Well-known member
It seems from reading above that Buzby & mikeyBoo (both obviously well versed in ladder logic) have differing ideas about the universality of ladder logic implementations.
 

Buzby

Senior Member
...the universality of ladder logic implementations.
Modern PLCs have 4 or 5 languages that they can run simultaneously ( BASIC is rarely one of them ) .
It is up to the programmer to decide which language is best for each part of the project.

No language is 'better' or 'worse' than another, it's horses for courses.

[rant]
It narks me when a client insists that the whole project must be written in ladder.
It's like telling a builder you want the whole house built using bathroom tiles.
[/rant]
As to emulating a PLC language with a PICAXE, they would all be difficult, some more than others.

But if you want some help, I'm here !.

Cheers,

Buzby
 

hippy

Technical Support
Staff member
The first step in writing a PLC emulator is to decide what ladder variant you are going to replicate.
I don't know enough about PLC's to be able to answer that and I suspect I might just be throwing my own interpretation of what ladder programming is into the mix.

Ladder programming has always seemed to be a somewhat convoluted way to express logic diagrams to me though I can appreciate those using them probably find them far more useful than I can appreciate.

I guess what I have is logic programming masquerading as PLC ladder programming, so at best the most primitive type of PLC with my own inventions and limitations thrown on top.

How useful that is I don't know. Maybe not at all to a real PLC programmer, but it was really only a rainy Sunday effort to keep myself amused. In that respect I think it's going to end up as 'whatever it is it is', useful or not.

Beyond reading in a text file which holds a representation of a ladder program, generating a PICAXE Basic file from that, I don't really have any intent to push it further or make it more genuinely PLC like.

I still need to bash it into shape but I think that's about it from me.
 

Buzby

Senior Member
Ladder programming has always seemed to be a somewhat convoluted way to express logic diagrams to me though I can appreciate those using them probably find them far more useful than I can appreciate.
Ladder is really good at what it was designed for, i.e. letting electrical engineers familiar with relays programme PLCs easily.
But it's not just ladder diagram alone that ensured the PLC's success, the programming packages also allow rapid modification, much quicker than re-wiring, and visual indication of the running logic for de-bugging. Today this known as an IDE and is standard on most micro and PC languages, but PLCs had it from the start.
Beyond reading in a text file which holds a representation of a ladder program, generating a PICAXE Basic file from that, ...
Parsing a text file, well, that's a start, and that is where the challenge is, not the coding. 99% of ladder programmes can be built from 'AND, AND-NOT, OR, OR-NOT, Q, T' and a 1-bit wide push/pop stack. These few functions can be easily coded with macros, and called as each opcode is executed.

The real challenge is parsing the text file into opcodes, and dynamically updating a representation of the running code on the screen.

Without the IDE the ladder engine is like smart phone with a dead screen, very powerful but not much use.

I think that's about it from me.
And from me, unless anyone wants some help building one.

Cheers,

Buzby.
 

Flenser

Senior Member
I think that the comments about ladder logic being a programming language that was developed for PLCs have the timeline the wrong way around.

I used a PLC briefly around 1985 when we replaced the wiring in a factory.
- We used to have a switchboard that was full of contactors (a type of relay commonly used in industrial electronics) and the control logic was implemented as hardwired connections between switches (the start and stop buttons, limit switches, etc) and these contactors.
- The control logic portion of the circuits in our new switchboard was replaced by a PLC. The only contactors that were left were in the switchboard were the ones that switched power to the 240V single phase or 315V three phase motors and these were controlled by the outputs from the PLC.

My recollection is that ladder logic predated PLCs. i.e. I think that when the first PLCs came out they used ladder logic because ladder logic was already in common use to document the control logic of industrial electrical systems.
 
Last edited:

Flenser

Senior Member
Ladder programming has always seemed to be a somewhat convoluted way to express logic diagrams
Hippy,

It might help if you think of ladder logic as a diagramming method designed to express the control logic of industrial electric systems. If you are familiar with the electrical circuit symbols it uses then it is very easy to interpret what each rung does as a control circuit.
i.e. Try not to think of ladder logic as something intended to document, or to program, general logic diagrams.
 

Flenser

Senior Member
For anyone who would like to write Ladder Logic I found Ldmicro http://cq.cx/ladder.pl.

This is free software that allows you to enter a ladder logic diagram using a graphical editor and then compile it to an assembler program so that it can be run on a short list of AVR and PIC microcontrollers. While this forum is probably not interested in the compiler it does have a graphical ladder logic editor and also includes a simulator for testing ladder programs.

There are two versions of Ldmicro.
The original version at http://cq.cx/ladder.pl
- This is the version created by the original author. The last release was his v2.3 version in Jan 2016.
Another version at githup https://github.com/LDmicro/LDmicro. The latest version can be download from here https://github.com/LDmicro/LDmicro/releases
- This appears to be a fork of the original version which is being maintaned by other people.
- There appear to be regular releases. V4.23 was released on Sep 25 2017.
- There are maintenance updates for both the graphical ladder logic editor and the compiler.
- This version has been extended. It has a much larger list of ladder instructions and compiles for more chips than the original version.
- There is an Ldmicro forum http://cq.cx/ladder-forum.pl. It currently has steady activity. e.g. There were 19 new threads posted in August 2017. I did a quick count and found about 47 new threads in the Active PICAXE Forum for August 2017.

If you do write ladder logic programs then you will need to convert them to PICAXE BASIC manually.

I also found the following article from the Spanish magazine Saber Electrónica on a single-board PLC based on the PICAXE-18 chip http://www.clubse.com.ar/DIEGO/NOTAS/notas19/nota01-1.htm
On page 2 of this article they describe a method of manually converting a ladder logic program to PICAXE BASIC. Those of us who do not speak Spanish will need to interpret this Google translated version of page 2 to understand their conversion method https://translate.googleusercontent.com/translate_c?depth=1&hl=en&prev=search&rurl=translate.google.com.au&sl=es&sp=nmt4&u=http://www.clubse.com.ar/DIEGO/NOTAS/notas19/nota01-2.htm&usg=ALkJrhht99F_FfYqWUsjBfPV8IBDp_xQSg
 

geezer88

Senior Member
I think the term "ladder logic" came from need to simplify understanding and repairing of relay control systems. It was a good way to document a system to allow an unfamiliar technician to troubleshoot a complicated pile of wires, relays, timers, and switches. I have attached a jpeg of a simple refrigerator control system. The left side is a standard wiring diagram that shows every wire, device, and connection in the refrigerator, but the "spaghetti" nature of it makes it very hard to see the operational sequence. The right side is a standard ladder diagram of the same machine. It is much easier to follow the flow of the control.

example-ladder.jpg

My first job as an engineer was to design controls for custom food processing equipment. My boss showed me the ropes for ladder diagrams and I was hooked. After release to production, technicians took over the systems, and the ladder diagrams helped this transition immensely.

I agree with the others on this thread that the PLC ladder code was developed to ease the transition from relay systems to computer controls.

Since those days, I've designed control systems using basic, pascal, c, and others. Someone else on this forum says, "horses for courses". I agree.

tom
 

mikeyBoo

Senior Member
Why Ladder Logic is a Big Deal

For-whatever-it’s worth: Ladder Logic greatly simplifies electrical troubleshooting (A real-world example):

Years ago, my boat had an electrical problem while at a remote area on a mountain lake. The problem turned out to be very simple (a loose wire), but it was an extremely frustrating experience trying to decipher the boat vendors’ wiring diagram to locate the problem. I determined that I was not going to go through that again, so I dedicated a full day to turning the spaghetti wiring diagram into a ladder. Now, when I have a problem, it can be located in a matter of minutes.

The moral of this story is that if you have a system with a lot of field wiring, you’d best have a ladder diagram. Compare my “simple” boat wiring problem to what exists on an industrial production line & it’s obvious why ladder diagrams are a big deal. PLC ladders are very similar.

The thing that’s a mystery to me is why all boat (and auto) wiring is not supplied as ladders. Maybe it’s because repairs are charged by the hour.

See attached .pdf to see my boat wiring simplification. (Now I can fix my boat without having to think so hard).
 

Attachments

westaust55

Moderator
To my knowledge/recollection, industrial sites (certainly those I was involved with)such as mining, oil & gas, metal refineries, etc., always drew their electrical schematics in a format typically with the power circuit as a 3-line portion across the top from left to right showing the circuit breaker/fuses, contactor and overload/protective device.
Below that was the control schematic with the active/positive down the left side, the neutral/negative on the right.
From the left each line ("rung") had the contacts for field devices and relay coils or timers in a sequence leading to a coil of a relay, contactor, timer, etc., at the right side then to the neutral/negative.

For each relay, contactor, timer coil there was such a line ('rung') so the control schematic looked akin to a ladder with two side rails and rungs of circuitry between.
Electrical tradespersons were very familiar with this style of schematic diagram.

When PLC's came onto the scene to control industrial plant (beieve the first were in the 1960's but first I worked with were late 1970's)
the decision was to use a programming interface called ladder logic that emulated the presentation of the earlier electrical control schematic diagrams so that they were easy for the electrical tradespersons to understand and fault find.

I do recall that while ladder logic was at the time the primary programming format as seen on the PLC programming terminals, that some companies such as Klockner Moeller has multiple CPU options depending upon what "logic" format you wished to program in. There was Ladder Logic, Assembler and a third type of programming format available certainly by the early 1980's.

Strangely while car manufactures were some of the first to use PLC's for automobile assemble line control, as already mentioned their own schematics/wiring diagrams are a different story in terms of ease of reading/understanding.
 

techElder

Well-known member
...always drew their electrical schematics in a format typically with the power circuit as a 3-line portion across the top from left to right showing the circuit breaker/fuses, contactor and overload/protective device....
Don't know where all of it is now since I retired, but I regularly used equipment documentation in "ladder" form from equipment built in the late 30's and early 40's. Magnetic particle testing equipment from that era seemed to be lasting forever!

We never used the word "logic" alongside of "ladder", and despite mikeyBoo's experience with his boat, some of it got quite confusing with relays and contacts in far flung corners of the box.
 

mikeyBoo

Senior Member
Never used the word "logic" alongside of &#8220;ladder" ??

Well Tex, that&#8217;s &#8216;cause you didn&#8217;t get your education at the Jethro Bodine Technical Institute & Double Naught Spy Academy as I did.

Google &#8220;ladder logic&#8221; (e.g. https://en.wikipedia.org/wiki/Ladder_logic )

Every day&#8217;s a new adventure.
 

techElder

Well-known member
The point was that ladder diagrams were a type of schematic long before PLCs were popular. Just a bit of history.

Now back to the Beverly Hillbillies rerun on TV. :)
 

Mark.R

Member
Good evening all,

I know this thread is from a few years ago now but did the idea of a "Ladder Logic" editor ever gain any traction for the Picaxe, as being from that background more so than BACSIC I think it would be bloody brilliant to pardon my french! I believe a project based around a Picaxe and being programmed with a ladder editor would be marvellous, think of the function blocks you could have built in, FB's for I2C, SPI & 1-Wire bus you could have, I think the idea has legs but far beyond me to write such a potentially powerful program.
 

mikeyBoo

Senior Member
It would certainly be possible to write a PC app for writing & downloading ladder logic to Picaxe chips.
There would have to be a reason or need for doing that. Right now I can’t think of one. Maybe for an application with a lot of complex conditional logic (but then I wouldn’t use a Picaxe).

There are a lot of esoteric (mission-specific) things you can do with a Picaxe that would be very difficult using PLC ladder logic.

For example (simple as it is), the little Picaxe app attached below would be difficult (at least for me) to do on a PLC.
The little app is a motion-activated security system with the following features:
Monitors 8 wireless motion sensors & generates an event when any one of them is triggered.
Sends a “record on” pulse to a DVR (for video recording)
Announces a voice message to tell us which sensor was triggered.
Sends an event string to a PC for display on a graphic (or send a text or email).
Outputs to an OLED (if needed).
Panic mode, lights, alarm outputs
Timers for alarm intervals, DVR On pulse, etc using Picaxe’s TIME variable.

Notice there is even a “ladder_eval” subroutine for doing conditional logic (much like a PLC) & I did make a ladder drawing to assist anyone else doing a repair. (Note that some “rungs” are simply subroutines.)

PLC logic is great for quickly setting up discrete connections, but the programming is pretty rigid. Picaxe has a lot of built-in tools that make it much more pliable for esoteric projects.

So, as the Brits say “Horses for Courses”.
 

Attachments

Buzby

Senior Member
There are a lot of esoteric (mission-specific) things you can do with a Picaxe that would be very difficult using PLC ladder logic.

Monitors 8 wireless motion sensors & generates an event when any one of them is triggered.
Sends a “record on” pulse to a DVR (for video recording)
Announces a voice message to tell us which sensor was triggered.
Sends an event string to a PC for display on a graphic (or send a text or email).
Outputs to an OLED (if needed).
Panic mode, lights, alarm outputs
Timers for alarm intervals, DVR On pulse, etc
Even a cheap modern PLC can do all the above easily, and is much simpler to install and debug than any micro running PICAXE or Python code.

For a start, PLCs are physically ready to connect to the real world straight out of the box. Microcontrollers need interfaces.

But the biggest advantage of PLCs is the ability to monitor the code execution in real time, and make changes on-the-fly without stopping.

The downside is that even the cheapest 'real' PLC costs about $100.

The biggest challenge of using a PICAXE, or any other micro, as a PLC is not the actual coding of the PLC engine, it's the tools that go with it.

When this thread started back in 2017, I had an attempt at programming a PLC in PICAXE.

Programming the engine turned out to be easier than I thought, but the tools were going to be a big problem, so I gave up.

( See the code below for my start of a PICAXE PLC. )

Note that all the PLC variables and PLC code are stored in scratchpad memory. This was done to allow tools written on a laptop to connect via I2C, and read and write seamlessly to the PICAXE PLC. ( I would now probably actually use a second PICAXE to do the I2C, with serial to the laptop.
)

Cheers,

Buzby
 

Attachments

Flenser

Senior Member
Mark.R

It is certainly possible to program the PICAXE using a Ladder Logic editor.

After this thread was started in 2017 I thought I'd have a look to see if I could use the PICAXE precompiler to convert the C code produced by the LDmicro open source project into PICAXE BASIC. That turned out to be a dud idea but I as became more familiar with the LDmicro code I realized that the way the program was architected made it relatively straightforward to add the PICAXE chips to the program.

Generating PICAXE BASIC code for all all the ladder instructions was a bigger task and I've been working on and off on a PICAXE port of LDmicro since then.

At the moment it is at a pre-alpha stage. I've desk checked the code generated for each ladder instruction and the code generated for my test cases passes a syntax check using the command line compilers but I have not done any testing on hardware. Last year I purchased VSM and planned to use it test the generated code without needing to wire up a breadboard for every test case but I got distracted with other projects and have not yet started that VSM testing.

If there is any interest I'm happy to post my PICAXE port in it's current state with the following caveats:
  • The RevEd site has a link to a commercial Ladder Logic compiler so I would need to get RevEd's go-ahead before I posted my program.
  • There is no documentation yet. The LDmicro program does include a manual for the graphical editor and there is a LDmicro wiki with a lot of example code but the doco for the PICAXE specific features of my port would be poor.
  • I plan to provide "best effort" support for the generated PICAXE BASIC code only. i.e. I will fix any bugs in the generated PICAXE BASIC code but I make no promises as to when I might get around to doing the fix.
  • I would not be providing support for any bugs in, or improvements to, the LDmicro graphic editor. These would need to be posted to the LDmicro github project to be handed by the LDmicro maintainer. I give no guarantee that I would implement any LCmicro bug fixes in my port.

Here is a simple example that implements a latching switch for the 08M2 chip:
  • Xstart is a normally open ] [ momentary contact pushbutton switch connected to the input pin C3.
  • Xstop is a normally closed ]/] momentary contact pushbutton switch connected to the input pin C1.
  • Yout() is the output pin C2 connected to something you want to turn on. i.e. a LED, a relay, etc
  • Yout] [ is an internal relay with the state of the Yout() output pin
  • When you push Xstart to make the contact the output pin is latched on.
  • When you push Xstop to break the contact the output pin is turned off.

A screen dump of this program in the LDmicro editor:
25441

The generated PICAXE BASIC program test#latchingswitch#08m2.bas is attached

LDmicro forum https://cq.cx/ladder-forum.pl
LDmicro Wiki https://github.com/LDmicro/LDmicro/wiki
 

Attachments

hippy

Technical Support
Staff member
The RevEd site has a link to a commercial Ladder Logic compiler so I would need to get RevEd's go-ahead before I posted my program.
Has or would need to allow ?

If you mean that we have a link to the "Automgen" commercial software offering I don't believe that would prohibit or stand in the way of publishing something which is an alternative from yourself.

Is this the compiler - https://github.com/LDmicro/LDmicro - If so it seems to be GPL 3.0 licensed so I can't see any problems in publishing what you have done., any changes you have made.

Of course, if you are adding PICAXE support to that, if you can get them to incorporate that as a part of the mainline or a branch, you could simply point people to that.
 

Buzby

Senior Member
It is certainly possible to program the PICAXE using a Ladder Logic editor ....
That's clever work you've done there, but I can't see how the IDE can monitor the running code in a PICAXE.

( I don't know LDmicro at all. Can it real-time monitor any of it's target devices ? )

However, I noticed in the screenshot that LDmicro looks like it can use Modbus addresses.

If you added some PICAXE code to run as a Modbus slave, then the IO and coils could be read back for real-time display, assuming LDmicro can support this function.

Still clever work though, well done !.

Cheers,

Buzby
 

Flenser

Senior Member
If you mean that we have a link to the "Automgen" commercial software offering
Yes, this was my meaning. I don't know if there is some agreement between RevEd and Automgen so I wanted to check if it was OK before I posted my open source port of LDmicro.

Yes, this is the program I've modified.

if you can get them to incorporate that as a part of the mainline or a branch, you could simply point people to that
If I was to get my PICAXE code included in LDmicro then I'm essentially committed to coding the PICAXE versions for all it's future enhancements.
By forking off a copy to create a PICAXE BASIC only version I only need to maintain that version.

LDmicro has had an interesting history. The latest wrinkle is that the maintainer lives in Odessa and hasn't posted to the forum since Russian invaded Ukraine.

Can it real-time monitor any of it's target devices
No, LDmicro cannot do any monitoring of it's target devices.
It is a graphical editor, like Blocky that compiles to an output file. My version will compile to PICAXE BASIC.
LDmicro also has a simulator that is a similar feature to the PE simulator.

If you added some PICAXE code to run as a Modbus slave, then the IO and coils could be read back for real-time display, assuming LDmicro can support this function.
I don't know anything about Modbus. Modbus appears to have been implemented for Arduino based Controllino product which is based on the Ardunio and supports the modbus protocol over RS485 using an add-on RS485 module. The "Extended Byte Code" output was implemented to support the Controllino.
 
Last edited:

Mark.R

Member
Hi Flenser,

I've had a read down the posts since I last posted asking basically if the ladder programming idea for Picaxe had gone anywhere and they make interesting reading, most of all the work it looks like you've already done to pursue the idea further.

I've yet to download the latest LDmico program to have a play with it but I have watched quite a few videos made by OnosTech on how to use it which have been very informative, would be good to see videos from him using LDmicro with Picaxe.
Looking as the screen shots you've added to your post I'm making the assumption (yes I know that's dangerous) that when you go through to the drop-down to select the type of and what processor you're using you now have Picaxe in that list and the different types, 08m2..........40X2?

It would be good to see this go further and maybe it's something that RevEd could pick up themselves if you don't want to be doing the ongoing support and development.

Is your version of LDmico available?
 

Flenser

Senior Member
Mark.R,

My version is a port of the original LDmicro to the PICAXE chips. i.e. it is a copy I've made and modified that is completely seperate from the original.
The only chips it supports will be the PICAXE chips and it supports all the current M2 & X2 chips only.

I won't be adding my PICAXE code to the original LDmicro, so you won't see any videos from him using LDmicro with Picaxe. This shouldn't matter as the ladder logic programs are not specific to any microcontroller.

The fact that Ladder Logic instructions are not specific to any microcontroller also means that almost all of the ladder logic instructions will be available for the PICAXE chips. The only instructions that should be unavailable are the ones that PICAXE BASIC does not support.
For example, PICAXE BASIC does not allow you to use the microcontrollers watchdog timer in your program so this instruction can't be added to your PICAXE Ladder Logic program because it is "greyed out" on the instruction menu.

I have a some work to do to prepare my vesion of LDmicro before I upload in to the project section. I don't get much spare time during the week so it will be at least a couple of weeks before it is ready,. I'll post an announcement in the Active Picase forum when I've uploaded it.
 

Mark.R

Member
Flenser,

All read and understood, I think its wonderful that there are people out their who us/give up spare time for quite, I believe, in-depth things like this.
 

Dadace

New member
good morning to all of you, I'm working on a circuit to simulate ul PLC, the micro is a 40X2 according to you there is the possibility of emulating a watcdog or if this is not possible, use an 08M2 to ferify the cycle time and in case you is it a problem to command the reset pin on the 40x2?
thanks and congratulations for the very professional forum
 

hippy

Technical Support
Staff member
Using an 08M2 as an external watchdog, even on top of any software watchdog, is a good low-cost option. You could monitor an output pin from the 40X2 and, if it doesn't toggle within a certain time frame, initiate a hardware RESET to the 40X2.

There is always an issue of 'who guards the guards?', how you ensure an external watchdog is reliable, that the 08M2 is still working as expected.

What level of watchdog protection one needs will depend on the consequences of things not working as expected. For safety and life critical systems multiple pure-hardware solutions would likely be implemented to minimise the chance of failure but there are other cases where reducing the chance of failure is sufficient.
 

Dadace

New member
thanks hyppi for the tips, i will use 08M02 as watcdog in order to implement a security on the software part. The safety part for people, I will use a safety relay with emergency stop on the electromechanical circuit.
 

Dadace

New member
Thanks Flenser, I downloaded the integrated data sheet. This also seems to me a good solution. I see to find it and to do some tests on the product. I will update you on the subject
 

Mark.R

Member
I've looked at LDmicro and still look forward to giving the PICAXE modded version a go. In doing LDmicro rummaging about I came across a channel on YouTube from a chap called OnesTech who has done some tutorials on LDmicro on other hardware which are very good, but has also done a series of videos on the Outseal PLC which is based on the same processors as the Arduino Nano. Now I'm not pushing other hardware but the actual Outseal Studio software layout and appearance is very good and in line with how I see PE6, it would be good if there was ever an official PELadder software it was like this, but I guess this is still down to whether RevEd sees a need or demand.
 
Top