G-Code CNC Router Controller

Sometimes, a single issue of Circuit Cellar isn’t enough.

Brian Millier, a retired instrumentation engineer in the Department of Chemistry at Dalhousie University in Halifax, Canada, needed more than one issue to explain his construction of a microcontroller-based, G-code controller for a CNC router. So we gave him room for a two-part series appearing in our April and May issues.

In Part 1, Millier explains the basics of G-code and how it is converted into three-axis motion, via the router’s three stepper motors. In Part 2, he describes his design of the router’s axis controller (powered by three small microcontrollers) and the host controller (powered by a more powerful microcontroller).

He calls the project one of the most challenging he has ever tackled.

So why bother? Especially when the combination of a PC and ArtSoft’s Mach3 software is a common and affordable approach to running a CNC router? Well, like most DIYers, Millier couldn’t resist an opportunity to learn.

“I want to be upfront and say that this is probably not the most practical project I have ever done,” Millier says in Part 1. “You can usually pick up a used PC for free, and the Mach3 software is professional-grade and handles much more complex G-code programs than my DIY controller will. However, it did provide me with a challenging programming task, and I learned a lot about designing a program with many concurrent tasks, all of which are quite time critical. Even if you are not interested in building such a controller, you may find interesting some of the techniques and tricks I used to provide the multi-axis stepper-motor motion.”

Millier’s two articles focus on the two main tasks of his project.

“The first was to understand the G-code language used to program CNC machines well enough to be able to write the firmware that would parse the G-code commands into something that a microcontroller could use to control the stepper motors used for each of the three axes,” he says. “The second task was to design the hardware/firmware that would actually control the three stepper motors, all of which had to move synchronously at accurate, ramped speeds.”

Millier wraps up his project by saying: “This was probably the most challenging project I’ve tackled, outside of work projects, in many years. In particular, the Basic program code for both of the controllers ran beyond 3,500 lines.”

If you are also someone who is willing to take on a tough task for the thrill of figuring it out yourself, check out Millier’s explanation of his project in the April and May issues of Circuit Cellar.