Another customer driver for a hoverboard motor

Hi everyone,
I want to develop another motor driver using SimpleFOC library. I’m disabled and retired, so far this will be a poor man’s project :grinning: - most of the components are the cheapest components from Aliexpress.
I’m not very familiar with the library yet, and I wouldn’t want to make a mistake in the board design - the motor uses hall sensors, will three low side current sensors be enough or am I missing something?
For the first trial a am going to use blue pill and stm32g030 in the final board.
I’m going to use 2 motors and therefore I need a torque mode.
Could you help me with a simple library initialization to work with this configuration?

Simplefoc doesn’t support current sensing with stm32g0

Really STM32F103 is fine as well - it is not decided yet, I want to play at first.

Yes F1 will be OK for playing around. That’s what hoverboard controllers use.

But later you might want a chip with a floating point unit for more fancy stuff.

I am not going to fly, I need simple enough driver with UART torque control.

When choosing your MCU, please pick one with 128kB flash (or more). There are BluePills available with 128kB, but especially for doing 2 motors, you might want to consider a BlackPill or a F4 / G4 Nucleo 64 board instead.

Running even just one motor can be tight in 64kB, and with two I think you’ll run out of memory otherwise.

Regarding your circuit, the schematics are quite dense, but it looks ok at a quick glance.

I’m not sure about the op-amp current sensing circuit though, I tried to simulate it in circuitjs and it doesn’t look like it’s working as expected. But it may also just be that I got it wrong.

This amplifier is copy/pasted from hoverboard schematic :grinning:
Few years ago I have used hoverboard-firmware-hack-FOC for my mobility scooter


If you are designing a new board, might as well get “as much processor as possible”. The F103, while excellent years ago, is quite underpowered these days.

I would recommend the STM32G431. Much more powerful than the F411, and available easily on Aliexpress either as a cheap black pill (<$4) or as a single chip. 128kb flash, 32kb SRAM, M4 with additional DSP/FP (including CORDIC coprocessor which offloads sin/cos/tan operations)

It’s roughly 3 times faster than the F103 in basic operations, but having a FP unit is probably 6-10x faster than a F103 if you need floating point math.

It’s the processor used in the ST ESC evaluation board

Thank you for the recommendation.
I have been designing software for microcontrollers about 40 years and I am retired now. I’m more interested in using weak processors to get maximum effect. I have a lot of different microcontrollers on my shelf, but using powerful ones is far away from a hobby. If you could recommend how to do this task on STM8, that would be interesting. Most Chinese scooter controllers use an old good 8051 core and 16Kbytes of memory (like SH79F1611).
Naturally, the algorithms are the simplest.
My idea is to make a working model on some STM32 and then modify the library to work with a weak microcontroller.
And I don’t want to spend a lot of money - this project is just for fun, no real needs.

But thanks anyway.

Then I take it back :slight_smile: 64kB is enough to get it running with Arduino + SimpleFOC, if you disable USB for example.

And from there I see no reason an experienced developer couldn’t make it work in 32kB, perhaps even less. The trick will be to get rid of all the bloated abstraction layers like Arduino or Mbed, remove all the unneeded code in the library and rewrite the parts you need using lean code for only the HAL or bare metal.

8 bit cores have the advantage of everything being smaller - the compiled code and most of the data winds up being much smaller. On a 32 bit MCU I think hitting 16kB will be a real challenge, but do let us know how it goes, I would be very interested to hear how you progress on it :slight_smile:

This is a plan, but at the first I have to get working system with any STM32, I don’t know how motor works. After I will be able to remove everything relаted to Arduino and HAL - probably stm32g030 is good enough. Will be good to know if my board is enough for simpleFOC.