SimpleFOC turns OK and stops/stutters

Want to try that one? I couldn’t put the halls in the slots, so I added extra magnets.

1 Like

That’s a chonker of a motor hahahaha. Neat idea to get the hall sensors in place.
I’m looking at the price of motors with hall sensors and they are more expensive than I remembered…
Will empty out the motor closet tomorrow and see if I have anything I can test with…
If not I’ll continue with adding the AS5600 encoders to the hub motors.
Tomorrow because I can’t use the mill at these hours to drill out a centered hole at 2AM hahaha!

I saw you got a ¿DE-5000? looks really nice. I wish that one existed when I got mine, it’s missing ESR :smiley:
369uH seems pretty high, but then if it works it works! What board and motor are you using? GD32F103 hoverboard driver?

Yeah, I thought it would be useful to measure the inductance and resistance of the many hoverboard motor types, maybe Lq and Ld. If we try to measure this by software it will help also.

I tried simplefoc on single boards with GD32F130 and dual boards with stm32f103(with only one motor) so far. Ideally it will work on all the boards.

1 Like

Well, meanwhile I’ve got some things ready next the PCB… there should be 2mm between the bearing and stator for the wires!

1 Like

Who needs a PCB service when you can do it by hand? :crazy_face:

Now time to learn how to get this to work together in SimpleFOC, at least the sensor itself works!


What was the mode you wanted to use again?
If it’s torque mode (voltage or current based), be prepared for a wild ride…
You’d have to wrap the target-torque in a ramp-up/ramp-down (for-) loop to avoid excessive acceleration. As I’ve learned today, there isn’t much PID-tuning available for torque-mode.

I’ve written a bit of code to gradually change max_current and slow down the motor. It could be helpful for big motors in torque mode (current_sense required)

void loop() {

  if (accel2target == 0.0f && sq(motor.shaft_velocity) > 0.5f){
    motor.PID_current_q.limit = motor.PID_current_q.limit /1.005f;  //  gradually reduce current
  else if (motor.PID_current_q.limit < max_current){
    motor.PID_current_q.limit += 0.005f ;  //  back to normal, waiting for new target
  else if (motor.PID_current_q.limit > max_current){
    motor.PID_current_q.limit -= 0.005f ;  //  back to normal, waiting for new target

  // user communication SerialComm instead of Commander
  if(Serial.available() > 0){

1 Like

Velocity/distance control in whatever mode works to be honest hahahah

Thanks for the chunk of code, I’m still struggling just to get the motor to spin hahaha

I found out that the I2C did NOT like being near the phase wires. Had to mill out flats on the shaft to get the wires out another way and the AS5600 reads properly when the motor is powered on!!!

I’m just getting a very wobbly output:

#include <SimpleFOC.h>

BLDCMotor motorL = BLDCMotor(15, 0.75, 19, 0.00119);//, 16); //pp, R, KV, L
BLDCDriver3PWM driverL = BLDCDriver3PWM(32,33,25);
InlineCurrentSense current_senseL = InlineCurrentSense(0.01f, 20.0f, 36, 39, _NC);
MagneticSensorI2C sensorL = MagneticSensorI2C(AS5600_I2C);

float target_voltage = 0;

Commander command = Commander(Serial);

void doTarget(char* cmd) { command.scalar(&target_voltage, cmd); }

void setup() {
  pinMode(17, OUTPUT);

  // pwm frequency to be used [Hz]
  driverL.pwm_frequency = 19531;//4882;

  //Magnetic encoder
  //Wire1.begin(15, 18, (uint32_t)100000);
  Wire1.begin(18, 15, (uint32_t)100000);
  driverL.voltage_power_supply = 12;
  motorL.voltage_sensor_align = 2.5;
  motorL.controller = MotionControlType::torque;
  command.add('T', doTarget, "target voltage");

  Serial.println(F("Motors ready."));
  Serial.println(F("Set the target voltage using serial terminal:"));

void loop() {
  GPIO.out_w1ts = ((uint32_t)1 << 17); //"set"
  GPIO.out_w1tc = ((uint32_t)1 << 17); //"clear"

My brain is no longer working, no idea if the AS5600 needs calibrating or PID tuning.
Tomorrow more… night!

You’re only using 100k BAUD? Did you try 1M Baud or at least 400k?

I also use this constructor:

TwoWire I2Cone = TwoWire(0);
I2Cone.begin(19, 18, 1000000UL); 

Don’t know if it makes a difference performance-wise. But these pin numbers work for me.

Ah! Thanks, forgot to change that back to 1M xD (That improved the loop time from 1.6kHz to 6kHz! Still oscillating, but smoother hahaha)

I was using that from the Deng_FOC examples, but then found the other method in the ESP32 examples and saw absolutely no difference other than one just needs one line for setup on the ESP32 :stuck_out_tongue_winking_eye:

I tested the MKS FOC plus with the hub motor again. It seems, I still get shoot-through when the speed is too high. The FETs got very hot in no time when I increased the current-limit.

With the ESP32 they could have made a propper 6PWM layout, so we can adjust the dead-time via SW.
I guess, I stick with my splitboard controller and make the most of it without current_sensing.

Hmmm… have you checked it is shoot through with a scope? Mine don’t get hot at all and that’s with the constant current spikes xD
Sadly the Wemos Lite doesn’t have enought pins for 6PWM with the current sense and SPI/I2C stuff :frowning:

I’m back!


Anyway, found the DEV branch, stole @o_lampe 's SmoothingSensor and PID values from here and the motor finally runs smooth… doesn’t want to stop but… it’s something.

Honestly I’m running out of motivation and Monday I’m starting a new job (farewell 21 months of fun holidays lol) so between work, training and chores my free time will provably be null. So yeah, if I don’t pop back in here on Saturday or Sunday this is most likely a farewell.
I hope not, because I have a third hoverboard of higher quality parts (the windings on the motor actually look nice and neat XD) and I’d like to see how that performs…

Thanks for all the wonderful help and support :green_heart:


You can choose for me a small question: when using hall sensors, does your operating mechanism run well in closed loop mode? I am using velocity control but the chance is stuttering