Shop OBEX P1 Docs P2 Docs Learn Events
P2 Grbl emulator G-code motion controller and stepper pulse generator — Parallax Forums

P2 Grbl emulator G-code motion controller and stepper pulse generator

mwrobertsmwroberts Posts: 75
edited 2021-05-10 16:24 in Propeller 2

This program runs on a propeller2 chip and mimics the operation of an arduino Grbl motion controller.
This wasn't ported from GRbl C code, it is a fresh write in Spin and PASM.

It uses a PASM cog for the low level interpolation and pulse generation, a main cog to send motion commands to the PASM interpolator, another cog to read in and parse the serial input stream, maintain a move buffer and output serial status updates of position information, digital inputs, and other stuff , and the JM_fullduplexserial object uses a 4th cog.

It interpolates 4 Axis, X,Y,Z,A, even though Grbl is only 3 axis.
It outputs up to 50Khz step pulse generation rate.
It uses linear Acc/dec trapezoidal moves using an acceleration time constant like a Fanuc CNC.
Position is updated every 1/100,000 second by calculating the area under the trapazoidal velocity profile curve.
Moves overlap by a time constant unless doing an exact stop G9 or a dwell G4.
You can use it with the "Universal Gcode Sender" shareware program, or type messages to it
using the Parallax Serial Terminal.
There is a lot of stuff I need to finish up before it is fully functional, but a good portion of it seems to be working now.
These demo clips in YouTube show it being run from parallax serial terminal in one, and using Universal Gcode Sender in the other one.
I have a propeller2 board hooked up to an arduino Grbl stepper motor shield. Stepx->Pin0
DirX->pin1 StepY->pin2 DirY->pin3 Gnd on propeller board to the ground on the shield, and 3.3v from propeller to the 5v pin on the shield...

https://youtube.com/watch?v=KOSJahTrb4w

https://youtube.com/watch?v=CiVGo-anzRg

Comments

  • Very nice 👍

  • cgraceycgracey Posts: 14,206

    That looks really neat, Mike.

    Do you have any idea how your P2 implementation compares, at the code-size level, with the alternatives?

  • @cgracey
    I'm not sure. In another Grbl thread on here, someone said Grbl used floating point. I did this using only integer math.
    The cordic functions work really nice! They made quick work of the position calculations,and the circular interpolation.
    But yea, other than the parsing stuff, there isn't a lot of code...

  • cgraceycgracey Posts: 14,206
    edited 2021-05-10 18:53

    @mwroberts said:
    @cgracey
    I'm not sure. In another Grbl thread on here, someone said Grbl used floating point. I did this using only integer math.
    The cordic functions work really nice! They made quick work of the position calculations,and the circular interpolation.
    But yea, other than the parsing stuff, there isn't a lot of code...

    32-bit math should be plenty. It will resolve the Earth's circumference to under 1cm.

    We are working on a generic four-half-bridge driver board for controlling most any motor(s).

    What will you be using your code for? Any specific project in mind?

  • @cgracey
    There was a thread about a stepper motor class, and talk about buying a 3d printer to experiment on, so that all kind of kicked me off in this direction. I don't have any specific application for this Grbl code, but I think it is a good addition to the propeller community's code base... My background is in CNC type stuff, so this if an area where I can contribute. My programming skills, not so much (meaning I'm sure my code looks ugly in places, because I'm only a weekend programmer).

  • cgraceycgracey Posts: 14,206

    @mwroberts said:
    @cgracey
    There was a thread about a stepper motor class, and talk about buying a 3d printer to experiment on, so that all kind of kicked me off in this direction. I don't have any specific application for this Grbl code, but I think it is a good addition to the propeller community's code base... My background is in CNC type stuff, so this if an area where I can contribute. My programming skills, not so much (meaning I'm sure my code looks ugly in places, because I'm only a weekend programmer).

    If you got it working, I think your programming must be all right. If there's something you're not confident about, it's only because your mental model of the P2 is incomplete. I'm glad you made this. Now, using it will reveal anything that needs improving.

  • RaymanRayman Posts: 14,744

    Searching for some gcode software and found this just now.
    Need something for my Zen CNC, shown on post #20 here: https://forums.parallax.com/discussion/174485

    This looks pretty good and I see it works with Universal g-code Sender, which is just what I need.
    And, UGS can import Carbide Create files, which is just perfect for me as have familiarity with that.

    Has anybody used this or something similar on a real CNC?

  • I don't feel really good promoting my commercial products here. If you intend to do this for fun, research or hobby and you like to create something new please ignore this and continue to work with GRBL. But in the case you just want to get your machine running as fast as possible you might consider this: Propeller based stepper controller with Ethernet. It's the low-cost version of the controller I use for my big machine.

  • @ManAtWork said:
    I don't feel really good promoting my commercial products here. If you intend to do this for fun, research or hobby and you like to create something new please ignore this and continue to work with GRBL. But in the case you just want to get your machine running as fast as possible you might consider this: Propeller based stepper controller with Ethernet. It's the low-cost version of the controller I use for my big machine.

    That's really neat.

    Do you ship those with the rough-cut DB25 shell ? I wonder if adding a vinyl sticker on the shell side with the cutout would hide all that, and provide a nice spot for logo/etc.. ?

  • RaymanRayman Posts: 14,744

    This is a P2 based gizmo for $20 euros? Am I seeing that right? That is a good deal.

    My current targets are painting cookies and eggs, so I guess I’d call this hobby.

    Still, I’ll be in Germany in June and might have to get one then…. Avoiding high shipping costs, right?

  • RaymanRayman Posts: 14,744

    @ManAtWork Micropod2 must be P1 based, right? Doesn’t look like P2 could fit in space or price…

  • @VonSzarvas said:
    Do you ship those with the rough-cut DB25 shell ? I wonder if adding a vinyl sticker on the shell side with the cutout would hide all that, and provide a nice spot for logo/etc.. ?

    It's a laser-cut DB25 "dongle" shell (for DB25 connectors on both sides, originally). A single side DB25-cable shell hasn't enough space for the PCB and making a custom mold was too expensive. The RJ45 jack and the 5V power supply terminal doesn't really fit but could be worse...

    @Rayman said:
    This is a P2 based gizmo for $20 euros? Am I seeing that right? That is a good deal.

    No, it's a P1. I've developped this between 2014 and 2017 before the P2 was available. It was a hard challange to squeeze everything into 32kB. It was only possible because it only holds a buffer of 2s trajectory lookahead. The P2 software feeds the buffer and acts as GUI and fileserver. But the P1 does a really good job generating low jitter step pulses. Steppers run much smoother than with any bresenham-like single-core solution I'd claim.

  • RaymanRayman Posts: 14,744
    edited 2024-03-12 13:03

    @ManAtWork Ok, makes sense. I do like the idea of having galvanic isolation between PC/P2 and stepper controllers... And, P2 is obviously overkill for what that does.

    My current setup is a bit dicey with P2 pins connected directly to 5V based stepper controllers. It seems to work, but not exactly the best situation... The inputs are rated for a minimum high of 0.7*5V, which P2 can't quite get, but seems to work anyway....

  • No, the P2 is not overkill. It can save you a lot of time. The smart pins make many things easier and the bigger memory and faster performance allows some algorithms to be implemented in Spin where you need assembler on the P1.

    Yes, galvanic isolation would be good but is not mandatory. I often simply place a 74HCT245 driver between the expensive part and the power stage. If something blows up the driver also fails but protects the P2.

    Also check isolation coulpers like the ISO7720 or -21 (or the cheaper CA-IS3720). They can be used as isolated level shifters as they work with different voltages from 2.5 to 5V. I also have isolated prog plugs so I can safely work even if the P2 is connected to mains voltage.

  • @Rayman

    here is another link to a GRBL version a month after that one... https://forums.parallax.com/discussion/173498/p2-grbl-printing-text-on-a-creality-ender3-with-a-red-sharpie#latest
    The link above shows the older version actually moving the x-y table on my creality printer...
    In the past couple of years I've added a lot of functionality, it's 5 axis with better pulse generation, probing and work offset functionality... I've been wanting to post an update, but I keep wanting to add stuff and I've been distracted by my drone project.
    You can send commands to it with the parallax serial terminal program also, and I was working on a version that had a debug graphical user interface, but the P2 debug routines doesn't include pc file access so I could stream a g-code file to the p2.....
    I can post a more recent version if you would like.

  • RaymanRayman Posts: 14,744

    @mwroberts Awesome thanks!

    Of course I’d not turn down the latest..

  • RaymanRayman Posts: 14,744

    @ManAtWork think i2c I/o expander at 3.4 MHz would work for things like this? Or, still too slow?

  • @Rayman said:
    @ManAtWork think i2c I/o expander at 3.4 MHz would work for things like this? Or, still too slow?

    You want top add an I2C I/O-Expander to GRBL? That should work, why not. But I think the P2 should have plenty of IO pins. I use simple 74HC166 shift registers for input and 74HC595 for output on my P1 boards. Of course, the P1 runs out of pins very soon.

    A cycle time of ~1ms is fast enough for all simple IO, e.g. switches, digital sensors and relays or solenoids where you don't need PWM or high frequencies (encoders).

  • RaymanRayman Posts: 14,744

    Thanks. I have the pins, but the interface is really 5v on my cnc thing. Getting away with 3.3 volt but thinking about easy fixes for future…

  • @mwroberts very interested in the latest.

    @ManAtWork That Propeller based stepper controller with Ethernet would be perfect for controlling a few old hardware boxes I have laying around that originally used LinuxCNC with a printer port. I fear the software with the German manual tho. are there any alternatives?

    Thanks All!

Sign In or Register to comment.