Stone & Turtlex
Turtlex Turtlex
Stone, I’ve been eyeing the idea of writing an open‑source firmware for a laser cutter that runs on a bare‑metal MCU. The devil’s in the microstepping and the G‑code parsing—both need to stay crisp and fast. Have you ever tinkered with microstepping or tried to keep a toolpath tight? I’d love to get your precision‑craft perspective.
Stone Stone
Sure, I’ve spent a lot of time on stepper drivers and keeping a path tight. Microstepping is just a matter of setting the correct driver currents and timing the half‑steps with the same resolution you want in the X/Y axes. On a bare‑metal MCU you’ll want a timer interrupt that fires at a constant rate and toggles the coil drivers in the proper sequence, using a lookup table for the sine values if you’re doing analog microstepping. For G‑code parsing, keep it a simple state machine that reads one byte at a time, strips comments, and stores numeric parameters in a fixed‑point format so you avoid the overhead of floating point. Once you have the target coordinates, use linear interpolation with Bresenham‑style stepping so the step count per axis is exact. If you run into jitter, check that your step interrupts have higher priority than the UART receive. That’s the trick to keeping the toolpath crisp and fast.
Turtlex Turtlex
Nice rundown, but remember that lookup tables can balloon the flash if you go too deep—maybe keep it to 256 points and wrap with a small sin approximation. Also, for the fixed‑point you might want to bias the scaling so you don't hit negative values when you’re subtracting small deltas; a 32‑bit integer with a Q16.16 format usually gives a sweet spot. Have you tried caching the G‑code line buffer on a DMA‑enabled UART? That can keep the CPU free for the step ISR. Just a thought for a next iteration.
Stone Stone
Good points, especially the 256‑point table and the Q16.16 scaling. DMA for UART is a solid move – it keeps the step ISR clean. I’ll keep an eye on the flash footprint and make sure the lookups are in the low‑end of memory. Thanks for the tweak.
Turtlex Turtlex
Glad that helped—just make sure you don’t accidentally cache the UART buffer into RAM you’re already using for the step queue; the two will start fighting each other like rival cats over a laser pointer. Good luck with the memory gymnastics.