@Rayman said:
Added in TON delay. Seems to be working as it should.
Excellent. I have a question.
Since the TON box is a box, with an input and an output that can be included in a line of logic, Is it generic enough to become a custom code box where add ons like TOF, PUL, PT,NT and such could easily be coded? Better yet, this ability to code the box extended to the end user?
Think have the drawing logic figured out (but have been wrong before...).
Copied the code into a Windows console program to help debug. That was surprisingly easy.
Passing some tough looking tests now:
If do have it, it's pretty simple:
At the end of a parallel, row needs to go back to starting row, after updating lowest row
At the end of series, row goes to lowest row in series +3
@Rayman said:
Thought implementing TOF was going to be easy... Just kind of opposite of TON.
But, it's a mess. Kind of ruins everything...
It can make a series that was off turn on in the middle...
Have to figure out how to handle that...
The way it is implemented in Allen-Bradley PLC is that you can view a TON or TOF like a coil.
Instead of using the TON in series, the TON "done" bit can be used.
The same goes for the TOF, but the DN bit is on when EN bit is on and turn off after PRE time.
Updated top post with version that might actually be working with TON and TOF.
Forgot to change it back from run mode to simulation mode though...
One can change that here in ladder.c:
void setup()
{
_setbaud(_BAUD); //in case we are using a faster baud, _BAUD defined in platform.h
//Pick one: EditMode, SimulationMode, RunMode
PlcMode = SimulationMode;
PlcMode = RunMode;
//Output screen to serial terminal?
bRunTerminal = true;
//bRunTerminal = false;
Going to try THI (Timer High) next. Hopefully, won't be as much trouble as TOF...
Just realized when adding "ADD" that the destination and source can be variables that include those used by TON, THI, and TOF.
Also, the variable names for TON, THI, and TOF have to start with a "T". ldmicro forces this.
There are also counter variables that have to start with "C".
Think have a handle on this now and now display variables on the right side too:
The UART formatted string output is interesting...
Looks like it only sends one character every loop.
Guess there is a danger of breaking the cycle time if try to send too much.
Also, sending a full serial message every 10 ms is probably not a good idea...
ldmicro appears designed with baud rate of 9600 in mind.
Default here is now 230400 baud.
Going to start off just sending the entire string.
Want to add the longest cycle execution time to the display so can see how close to the edge things are getting...
Got the "hello.ld" example to work.
Have to turn off the serial ladder to see UART type output obviously...
Also, got "traffic.ld" to simulate correctly.
This is a more challenging one...
Unfortunately, it has rungs with multiple coil type things, which breaks the ladder drawing code
Thought read that it was bad form to have more than coil on a rung?
Is that true?
Also, the traffic example is strange. What traffic light goes from red to yellow to green and then back to red?
Think they might have red and green reversed for some odd reason...
Unfortunately, it has rungs with multiple coil type things, which breaks the ladder drawing code
Thought read that it was bad form to have more than coil on a rung?
Is that true?
Its preferred for an output coil to have all its feed-in logic attached, yes, makes it easier to troubleshoot. However with simpler state machines you do often see set and reset coils on the same rung. To use your traffic light example, you might 'set Green' while resetting Red and Yellow, all off the same state transition rung.
Comments
It is rather neat that text mode, and self hosted, is sufficient.
I think it is looking great! but, yeah, if the ladder isn't showing the execution well, that'll lead to confusion, too.
Excellent. I have a question.
Since the TON box is a box, with an input and an output that can be included in a line of logic, Is it generic enough to become a custom code box where add ons like TOF, PUL, PT,NT and such could easily be coded? Better yet, this ability to code the box extended to the end user?
@"R Baggett" I guess so... ldmicro is open source and this code will be too... Don't know about "easily" though...
Think have the drawing logic figured out (but have been wrong before...).
Copied the code into a Windows console program to help debug. That was surprisingly easy.
Passing some tough looking tests now:
If do have it, it's pretty simple:
At the end of a parallel, row needs to go back to starting row, after updating lowest row
At the end of series, row goes to lowest row in series +3
Found another issue with drawing the connecting wires with this one.
Think have that going correctly now...
Thought implementing TOF was going to be easy... Just kind of opposite of TON.
But, it's a mess. Kind of ruins everything...
It can make a series that was off turn on in the middle...
Have to figure out how to handle that...
The way it is implemented in Allen-Bradley PLC is that you can view a TON or TOF like a coil.
Instead of using the TON in series, the TON "done" bit can be used.
The same goes for the TOF, but the DN bit is on when EN bit is on and turn off after PRE time.
Thanks @FredBlais, interesting to see...
TOF was messing with my brain, but think have it now.
Looking at the C code generated by ldmicro helped.
That C code is linear though whereas this is recursive.
The recursion makes it difficult with things like this.
Updated top post with version that might actually be working with TON and TOF.
Forgot to change it back from run mode to simulation mode though...
One can change that here in ladder.c:
Going to try THI (Timer High) next. Hopefully, won't be as much trouble as TOF...
Just realized when adding "ADD" that the destination and source can be variables that include those used by TON, THI, and TOF.
Also, the variable names for TON, THI, and TOF have to start with a "T". ldmicro forces this.
There are also counter variables that have to start with "C".
Think have a handle on this now and now display variables on the right side too:
Oh, those are numbered rather than symbols. T11, C22 sort of thing. Symbols/Labels associated with those can be any text.
The UART formatted string output is interesting...
Looks like it only sends one character every loop.
Guess there is a danger of breaking the cycle time if try to send too much.
Also, sending a full serial message every 10 ms is probably not a good idea...
Have to think about this one...
other core doing the UART, maybe set flag when message in/out is complete?
check the flag each time around?
ldmicro appears designed with baud rate of 9600 in mind.
Default here is now 230400 baud.
Going to start off just sending the entire string.
Want to add the longest cycle execution time to the display so can see how close to the edge things are getting...
Got the "hello.ld" example to work.
Have to turn off the serial ladder to see UART type output obviously...
Also, got "traffic.ld" to simulate correctly.
This is a more challenging one...
Unfortunately, it has rungs with multiple coil type things, which breaks the ladder drawing code![:( :(](https://forums.parallax.com/resources/emoji/frowning.png)
Thought read that it was bad form to have more than coil on a rung?
Is that true?
Also, the traffic example is strange. What traffic light goes from red to yellow to green and then back to red?
Think they might have red and green reversed for some odd reason...
Its preferred for an output coil to have all its feed-in logic attached, yes, makes it easier to troubleshoot. However with simpler state machines you do often see set and reset coils on the same rung. To use your traffic light example, you might 'set Green' while resetting Red and Yellow, all off the same state transition rung.