CPU reset occurs in initFOC()

Hi, I’m new here.
I’m using SimpleFOC library with SimpleFOC shield 2.0.3, Arduino UNO (compatible) ,GM4108H and AS5048A. The supply voltage is 12V.

Here is the code.

#include <SimpleFOC.h>
#include "SimpleFOCDrivers.h"
#include "encoders/as5048a/MagneticSensorAS5048A.h"

// magnetic sensor instance - SPI
MagneticSensorAS5048A sensor(10);

// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(11);
BLDCDriver3PWM driver = BLDCDriver3PWM(5, 9, 6, 8);

void setup() {
  Serial.begin(115200);

  Serial.println("Sensor init");
  sensor.init();
  motor.linkSensor(&sensor);


  Serial.println("Driver init");
  driver.voltage_power_supply = 12;
  driver.voltage_limit = 12;
  driver.init();
  motor.linkDriver(&driver);

  motor.controller = MotionControlType::angle;
  motor.voltage_limit = 12;
  motor.velocity_limit = 50;
  
  Serial.println("Motor init");
  motor.init();

  Serial.println("FOC init");
  motor.initFOC();
  
  Serial.println("End of initialization");
}

// angle set point variable
float target_angle = 0;

void loop() {
  target_angle = sin(_micros() / 200000.0) * 1;

  // Motion control function
  motor.move(target_angle);

  // main FOC algorithm function
  motor.loopFOC();
}

I expect the motor to turn after displaying the following
Sensor init
Driver init
Motor init
FOC init
End of initialization

But actually, after “FOC init”, “Sensor init” is displayed again, and it loops indefinitely. It seems that a reset is occurring in motor.initFOC().

Curiously, this phenomenon does not occur when I change the supply voltage from 12V to 5V. The motor turns as expected.
What am I doing wrong?

Hi, did you try adjust the motor.voltage_limit lower during the 12v supply? do you get same result?

Which kind of PSU are you using?

I’m just guessing, but initFOC() is the first function that moves the motor. So I think the motor is drawing too much current, overloading the PSU, voltage drops, and then you get a reset…

If the PSU can handle the current and its just a transient problem you can solve it with some capacitance… if the PSU is too weak, you need a stronger one…

Thank you rndbit.
I tried “motor.voltage_limit = 5;” with actual 12V supply.
But I got the same result.
(Also, “motor.voltage_limit = 24;” caused the same result.)

Thank you runger.
I’m using Wanptek WPS300. I think it is sufficient to drive the motor.
I used an oscilloscope to monitor the supply voltage. At least the voltage never dropped below 10V.

The PSU should be ok, the question is whether it can handle the sudden change in current - have you tried adding an electrolytic capacitor, maybe 200uF or so, across the power input of the SimpleFOC shield? If you have one with “legs” you can just stick it in with the power cables (watch the polarity).

Voltage limits should always be set lower or equal to the PSU voltage. To set them higher makes no sense, and may confuse the algorithm (I have to check the code if we check for it).

But with this motor at 12V, the current should not rise above 1.2A or so… it has 11Ω resistance.

Can you carefully check your cable connections? How about the solder bridges? And the USB connector of the Arduino, it is not touching any of the simpleFOC shield on the bottom?

1 Like

The best solution to the problem. Attach bulk capacitance, one or more 1000uF/25V would do it if you target 12V. Solder them right next to the board input voltage leads. Make sure you get the polarity correctly. You may also want to attach 1MegaO resistor in parallel to guarantee full discharge when the board is not in use.

https://www.amazon.com/McIgIcM-1000uf-capacitor-Aluminum-electrolytic/dp/B06WGPNM19

1 Like

Thank you all so much. It is resolved.

I don’t know the detailed root cause, but I replaced the Arduino UNO with a legitimate one from a compatible one and everything works fine now.
Thanks to your advice, I was able to arrive at the correct answer.

1 Like