# Current sensing in simpleFOC

My understanding is that the FOC algorithm is defined in terms of current because electromagnetic field strength is proportional to coil current. That said, suitable current sensors for low power applications are not common, so simpleFOC makes current sensing optional by assuming that pulse width is proportional to coil current. This assumption is good enough for currents < 5A.

If that’s true, then why do standard stepper drivers for motors with even smaller currents (e.g. A4988) use current sensing and manage decay modes in such detail? As the number of microsteps increase, each output looks more and more like a sinusoid, which seems similar to simpleFOC’s sinusoidal modulation.

Hey @jlo, good question.

Yes foc is really defined by the phase currents or better said the magnetic fields generated by the currents in the coils. This method has been developed for asynchronous motors where the stator phase current have to me measured in order to estimate the rotor currents and in order to set both rotor and stator magnetic fields. Using the q component of the current to generate the torque and d component to generate the magnetic flux to magnetize the rotor.
For the BLDC motors this method has been simplified form because bldcs have the magnets in their stator and we do not need to induce the magnetic field in the rotor any more - no need for d component currents. So we keep it in 0.

Current dynamics if the bldc motor are very fast, usually under 1ms what is the loop cycle time for many low power MCUs. So that basically means that for these microcontrollers the current has no dynamics and we do not need to control it really. We consider it a proportional value to the voltage.
This does not have to do much with the current magnitudes but the phase resistance and inductance of the motor which define how fast are current dynamics.

Another issue that arises due to this approach is that the high velocity applications require very high rate of current chabge (rotation) and sometimes if the assumption of proportionality is not respected the motor is underperforming. But on low velocities the difference is minimal.

Stepper motors are a type of bldc motors. They usually do have a current sensing integrated in the drivers but not to control the motor but to limit the current draw. This is more of a safety feature than the performance improvement. To my knowledge they do not use it for commutation. They do the commutation compelletely open-loops. But they measure the current and limit it to the value set by the potentiometer.

The microstepping and sinusoidal commutation is almost the same thing. The difference is a point of view only. For steppers it make sense to talk about the steps and for bldcs it’s not really intuitive. Also they do not use the high frequency pwm but the low frequency stepping. Also the difference is the number of data microstepps. For bldc motor it will usually have at least 2-3k microstepps per electrical revolution where stepper has at most (that I’ve used) around 128-256.
But it is also important to put this in context because e a stepper motor had usually 10x more pole pairs that the bldc so 2000 microstepps for bldc and 200 for stepper is more or less the same number of steps per revolution.

I spent a while investigating the A3967 stepper driver and my conclusion was that it used current sensing to determine the on pulse duration. The off duration was fixed, and so the frequency would vary from 32kHz to somewhat lower as the pulse duration increased. I could see small changes in the pulse duration even when holding at a fixed position, and I assumed that this was the driver compensating for current fluctuations due to motor winding inductance, resonance, load changes, etc. I think this suggests that current sensing is being used in commutation, would you agree? I would additionally argue that at the pulse level, the system is closed loop, but would agree that at the STEP-rotation level, it’s open loop.

My understanding of decay mode management is that it is an attempt to improve tracking when the desired current is increasing or decreasing. Both current sensing and decay modes suggest to me that there are issues that arise from chopper-driving changing currents through complicated inductive loads like motors. But unless steppers are significantly different from BLDCs as loads, I’m curious why simpleFOC is so successful without current sensing or decay mode management. I probably don’t understand what current dynamics you are referring to. I definitely don’t understand induction motors (yet ).

I’ve experimented with both analog current drive and sinusoidal PWM drive of stepper motors. In the former, I noticed that the driver almost doubled the peak voltage in its attempt to enforce the desired current at higher rotation speeds, not sure why. That said, the motor was not happy at high speeds. The latter scheme I’m guessing is similar to running simpleFOC open-loop without current sensing and was more successful. In both cases, audible noise is significantly lower than with normal stepper drivers at low to moderate speeds, and all I hear is a faint hum at the sine frequency, similar to what I hear on your gimbal controller board video. All of this is making me wonder if the current sensing and decay modes of stepper drivers are addressing issues that don’t matter in my applications.

I’m looking forward to my parts arriving in the mail so I can check out simpleFOC on my bench!

I think this can be a control strategy for the PWM signal, which is being modulated to generate the desired current by setting the voltage via PWM “blurring”. Depending on the MCU and it’s PWM generation capabilities, changing the frequency can be an easy way to maintain a “clean” PWM signal while changing the duty cycle. That’s just a guess though.

The BLDCs (and I assume steppers) are not really sensitive to the PWM frequency. If it gets too low, the PWM becomes audible, which is usually undesirable. The PWM speed is about balancing the electrical limits (FET switching times and associated losses) against the smoothness of the PWM generated voltage/current. In terms of controlling the PWM, the faster it goes the better your time-resolution can be on the commutation (the 2000 micro-steps Antun mentions), but the lower your voltage resolution. So depending on your MCU there will also be a “sweet spot” where you balance resolution vs. frequency.

When doing (low side) current sensing you have the additional constraint of needing to sense the current while the FETs are open, which you have to account for in the timings.

Perhaps your understanding is better than mine, in which case I’d like to learn why you see it this way, but I would have said that the “pulse level” is simulating the voltage/current which is being set by the “step rotation level”, which is the actual commutation.

Depending on the strategy for current control, the control can be implemented at different levels. Some BLDC drivers implement it within the PWM cycles, while other solutions switch after a PWM cycle, and yet others control it independently of PWM. What you describe sounds like the kind of current control implemented to prevent motor overheating, etc… independently of the commutation. That’s why you see it working also when the motor isn’t moving.

Just dropping here to add to this; there’s another very important reason why the PWM frequency is important (at least for BLDCs); for current control we need to stay on the non-steady state of the inductors (the phases), in other words, stay bellow the saturation of the inductors. If the PWM frequency is too low you’ll hit saturation faster, higher frequencies help to stay on this non-steady state.

Well I’m just speculating (and this whole topic is very new to me), but here’s why I think current sensing is used in commutation in the A3967:

1. Controller gets a step command
2. Depending on the direction and microstepping selection, it looks up the next desired current level in a table
3. It sets a voltage representing that current in the DAC so it can be compared with the voltage over the low-side current sense resistor
4. The pulse duration scheme I described previously then acts to change the current to the new level
5. The motor moves one microstep in the selected direction

You can see the DAC and comparator on page 2 of the datasheet I linked to, and note that all the stepping tables on pages 10 – 13 are expressed in terms of motor phase current, specifically as a percentage of ItripMAX. There’s a discussion of this in the section “Internal PWM Current Control” on page 5. So while it’s true that current sensing is used to limit the maximum current, I think it’s also being used in stepping.

Now I’m even more eager for my parts to arrive, but Mouser is having warehouse delays, and my BLDC motor is coming from China :

Ok, I see what you mean now, and also why you call it closed loop on the pulse level.

I see where you are coming from, and it is certainly interesting. I don’t really know anything about stepper motors, but for BLDCs I would say that to be considered part of the commutation the current sensing would have to have influence on the current level chosen in your step #2 above. Closed-loop controlling the PWM-generation of this chosen current is something I have to think about…