Low-side current sense on stm32

Hi guys,

First of all, congratulations for the work accomplished, simplefoc is realy helpfull to understand bldc motor.

I have a DRV8302 driver and i would like use the low-side current sense for torque control. I try on a blackpill STMF411 but the result is strange and I saw that the low-side was not yet available on the stm32 but that it is on the stm32 B_G431B_ESC1 (impossible to buy, out of stock everywhere). To precise, my setup works in voltage torque mode but I want to drive an 8110 motor and voltage torque is not suitable for high currents.

So my question is :

Has anyone tried to implement low-side current for torque control on a stm32 ?

I have drv8302 board to and im wery interested by solution of current problem.

not sure if it helps but below is a low side implementation of vesc6 with drv8301 and stm32. It is not simplefoc though.

Cheap-FOCer… wow… what went through one’s thought process to name it like that.

Welcome, @Mortalus !

This is very much work in progress at the moment, and will probably be part of the next release of the library. As you noted there is a STM32G4 implementation a bit specific to the B_G431B_ESC1 board, which could probably be adapted to your purposes.

Do you think this scheme using gd32e103c8t6 + drv8323 has reference value?

I’ll give you the circuit diagram and source code (keil version) first. If you think it’s useful, I can provide it to you

Dear @blackblue007 ,

Thank you for this! The schematic picture is fine, you don’t need to send more. The implementation of low side current sensing will not be strongly affected by the way the analog signals reach the MCU, although obviously the gain or V to A ratio of the solution is an important parameter.
It will be interesting to see if the gd32e103c8t6 supports the analog in functionality in exactly the same way as the STM32F103 does.

Thank you for this!

thanks for the answers

I have a strange issue, in TorqueControlType::voltage the motor goes faster in one direction than in the other and it s not the same current consumption. The slower rotation corresponds to the higher current.

When I look the PWM signal of INH_A, INH_B and INH_C, they are not perfectly centered. Can this explain the different speed and current?

if not what are the other possibility?

It s an homemade winding, maybe i made a mistake.
A photo of my actuator, its a 1/10 cyloidal gear box


Wow, this looks like really, really nice work!

The STM32 code tries to sync the timers used, so the PWMs should be centred… but I would not expect this to lead to different performance in one direction than the other.

This type of behaviour can be due to a mechanical unbalance/problem, the motor simply has more friction one way than the other… or, maybe more likely, it can be due to an alignment problem during the sensor alignment.

May I ask, is the motor loaded during alignment? If the alignment does not find the electrical zero precisely, but is only a little bit off, it can lead to this problem. It is more likely to happen if the motor is loaded during alignment, as the open-loop control during alignment may not have the torque to move the motor as well as it should.
What voltage_limit are you using during alignment? If possible, you could try increasing it to see if it helps.

Nice cyclo. Is it off the shelf or custom made?

The difference in speed could be the windings, however, unlikely because the error would be symmetrical. Also asymmetric windings would cause errors in parts of the circle, not in one direction only.

Perhaps the cyclo has different resistance in one direction ? The cyclo is notoriously inefficient so it could be you are losing efficiency in one direction vs the other?

There is an excellent paper on cyclo efficiency. Looking at your design, you probably are experiencing asymmetrical cyclo efficiency. A cyclo like yours has between 40% and 70% efficiency so even some machining and mechanical asymmetry would drastically impact one direction unfavorably.

This is hypothetical. Without examining the real gears we are mostly guessing here.

1 Like

Thank you guys, I have more mechanical skills than programming (and English) :smiley:
I noted the speed difference with and without gearbox. I will try to increase the alignment tension.

The cylo is also a custom made, it is the most compact that I can make while keeping the ball bearings for a better performance. I have not finished the development, especially the bldc electronics and programming. I measured the stall torque of the motor without reducer at 2.2N.m and with cyclo at 19.3 N.m without breakage, but these are preliminary tests. I think the efficiency is not so bad :slight_smile:

1 Like

You need to be careful because at stall the efficiency is just the theoretical cycloidal reduction ratio efficiency, which is 88.6% in your case, and falls directly where average theoretical cyclo efficiency is, check the paper I sent you.

The reason is, there is no dynamic friction. It’s all holding torque.

Problem is, real life you won’t be operating at stall, you will be operating at some rotational friction and that’s where your cyclo gets killed and loses all the power into heat through friction.

Watch out and double check your assumptions.


PS You need a torque dynamometer which is a really expensive piece of equipment to measure the dynamic efficiency. The efficiency is also dependent on the speed and load and lubricant and finishing of your lobes, pins and holes.

You’re totally right, that’s why I developed a measuring benches for dynamic measurement. My test with the reducer was just to reassure me. I’m already looking to improve the bldc controller. I’m sure I can do better. I will test several windings and choose the most suitable for my application.

some pictures


That’s very impressive, thank you for sharing. Many people on that board would find this very educational. Do you mill your own parts or use service?

That looks like a serious piece of machinery.

Gear down for what ? did the same static test on some of his planetary gearboxes ( 3D printed ) and his results were between 20% and 40% (!)

If you swap 2 wires, the motor will rotate in the other direction, with all the other variables unchanged. This will tell you if you have a mechanical problem or the controller is to blame.

Thx, I mill my own parts with my CNC, 3d printer (foldarap like and Ultimaker like) and laser cutter (90w). All these machines are homemade. An CNC is a router like full homemade (100kg) and an another based on Producmill F30 (high school machine) from which I recovered only the frame (around 450kg). I spent 10 years building my hobbyist workshop and now I can play with it :smiley:

1 Like

That a good idea, i will try and I would be fixed on the origin of the problem.

For the AS5048A position sensor, what accuracy am I supposed to have? with 14bit i should get 0.00038 rad ? but concretely?

Thanks for sharing! This looks like amazing work!

The AS5048A is a good sensor, and you should get good accuracy. If the system is still, the position should be more or less stable. If the system is moving/vibrating, it might be less so. Are you getting stable readings?

For a BLDC, this sensor is definately sufficiently precise to get good FOC. I think as for any magnetic sensor, the faster the motor turns, the less precision you ultimately have due to filtering and latency.

Do you use any type of current sensing with this setup?

I believe the board he uses has low side current sensing. How it’s been used not sure.