Use simple foc in cnc machine

Good night, excellent initiative for this project. I would like to know if it is possible to use simplefoc + bldc to replace the step motor in a cnc router

Hello and welcome.

You may want to talk to @Juan-Antonio_Soren_E about this.


Yes, true, I do have a test environment sat up, and have been working on a modular NEMA23 design for a while. If you look at my recent post, you can see what is happening.

So basically I’m combining a 21bit angle sensor (MT6835) with the STSPIN32G4 MCU and the INA241. I’ll probably have prototypes ready in a few week if it all plays out nicely. Although I am aiming to drive steppers as bldc’s, in a way, it’s also possible to use THE FIELD STACK to drive 3phase motors, but since those bad boys are a hugely different style motor, I think it would be beneficial to use that 4th bridge for a brake resister. My focus is steppers since they do have a great potential, also for closed loop FOC. Also, since the design I have been working on is modular, a larger BLDC power stage is in the event horizon. NEMA23 steppers are in my view a good match for “small” DIY CNCs w. aprópiate gearing. The cool thing about SimpleFoc lib. Is that only your imagination sets the limits. If you intend on building a huge industrial CNC, one day this will be possible and viable

Do you have experience with CNCing ?

Good Morning.
Yes, I have a lot of experience with cnc machines.
what i would like to know, is if i can use openfoc using step and direction input, connect a brushless with optical encoder and use a controller such as GRBL or something similar to command the position of the axis.

Step/dir listener is part of the REPO as far as im informed, while it may not be the optimal way to achieve what you desire.

You kinda have to let go of the StepperDriver approach, usually used in 3D printers etc.

My goal is to get Klipper up and running. Do you know Klipper ?

I’ve been thinking of doing just this with my small milling machine.

I don’t see any issues but there is some work you (and eventually I) will need to do.

  1. How does the current CNC controller interface to the current motor controller? It is step/dir? If so, this uses two GPIO pins to command the SimpleFOC controller. I think SimpleFOC already has a step/dir interface.

  2. Is step/dir the best method? Many CNC controllers can also drive analog servo motors, and the control loop is closed inside the CNC controller. Is this better? I don’t know. Step/dir requires very fast steps up to 100KHz or even faster but Analog can be much slower.

The other thing is that SimpeFOC can drive the existing stepper motor using FOC and in effect turn it into a stepless analog servo. This gives you closed loop control for the price of adding a quadrature encoder driver board. I hope to get much better performance from the same motor and also for the motor to run cooler.

What kind of CNC controller are you using? I’m running LCNC

Just catching up on Klipper functionality.

The usual way of achieving synchronized multi-motor machines is by having a central MCU like on a “controller” board w. Stepper drivers. That’s what Marlin, Smoothie Etc. does well.

Klipper is synced by time. So everything works like a complex clockwork with a PC or Pi as central processor.

So, one motor-controller or “sub-driver” knows beforehand when it should arrive at a certain point in space-time, yes it is rather outstanding.

Each subdriver also report back to the central unit, I’m not sure about the frequency at which it report, it’s most likely dependent on USB frame rate.

The thing to remember about a CNC tool is that it is interpeting g-code. the g-code defines the points the cutter must pass throught and the speed to move. The CNC machine does not jump from point to point. It moves continuously along a path that passes through the points. The controller typically looks ahead a point or two. I think it fits a funtion to the points. With the funtion fitted it can calulat the location of any intermediate point

The other thing to remeber is that the g-code file is written in (x,y,z) Cartesian coordinates. So the controller needs to convert the valocity vactor 3D (x,y,z) space to rotational rate on each axis. Only then can it check if the commanded speed and acceleration of some motor is within its limit and if so reduce the overall speed.

Typical “frame rates” where all this gets re-compted are on the order of 1000 per second.

Machine tools are a lot like robots except that many robots don’t run g-code, they determine their own actions in real-time

The mater controller needs access to the raw encoder data so that it can track error