Shop OBEX P1 Docs P2 Docs Learn Events
P2 PLC: Foundation might be working... - Page 2 — Parallax Forums

P2 PLC: Foundation might be working...

2»

Comments

  • evanhevanh Posts: 16,178

    It is rather neat that text mode, and self hosted, is sufficient.

  • @Rayman said:
    Thinking the simulation and running code is pretty bulletproof.
    But, the ladder drawing code is proving to be a challenge...

    I think it is looking great! but, yeah, if the ladder isn't showing the execution well, that'll lead to confusion, too.

  • @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?

  • RaymanRayman Posts: 14,923

    @"R Baggett" I guess so... ldmicro is open source and this code will be too... Don't know about "easily" though...

  • RaymanRayman Posts: 14,923

    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

    1348 x 766 - 30K
  • RaymanRayman Posts: 14,923

    Found another issue with drawing the connecting wires with this one.
    Think have that going correctly now...

    1043 x 800 - 26K
  • RaymanRayman Posts: 14,923

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

  • FredBlaisFredBlais Posts: 380
    edited 2025-01-29 20:35

    @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.




  • RaymanRayman Posts: 14,923

    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.

    1015 x 628 - 29K
  • RaymanRayman Posts: 14,923
    edited 2025-01-29 22:53

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

  • RaymanRayman Posts: 14,923

    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:

    1043 x 832 - 31K
  • evanhevanh Posts: 16,178

    Oh, those are numbered rather than symbols. T11, C22 sort of thing. Symbols/Labels associated with those can be any text.

  • RaymanRayman Posts: 14,923

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

  • @Rayman said:
    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?

  • RaymanRayman Posts: 14,923

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

  • RaymanRayman Posts: 14,923
    edited 2025-02-03 21:39

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

    1043 x 832 - 45K
  • TubularTubular Posts: 4,718
    edited 2025-02-03 22:39

    @Rayman said:

    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.

Sign In or Register to comment.