Problem for stepper motor in close loop mode

hello everyone,
I’m using STM32F103C8T6 blue pill bord, MA730 sensor, and L298N driver. Openloop work and sensor output are correct, but once enter torque mode or angle mode motor stop spining, I follow the Stepper motor control example setting everything up, still can’t get it working.
what should i do? any tips
Thank you !

Hey @dj140, we need a it more info to help you out Can you share your code with us?

it just the standard example code :

#include <Arduino.h>

#include <SimpleFOC.h>

// Stepper motor instance

StepperMotor motor = StepperMotor(50);

// Stepper driver instance

StepperDriver4PWM driver = StepperDriver4PWM(PA1, PA3, PB0, PA2, PB8, PB9);

MagneticSensorSPI encoder = MagneticSensorSPI(MA730_SPI, PA4);

// commander interface

Commander command = Commander(Serial);

void onMotor(char* cmd){ command.motor(&motor, cmd); }

void setup() {

  // initialize encoder sensor hardware


  // link the motor to the sensor


  // choose FOC modulation

  motor.foc_modulation = FOCModulationType::SpaceVectorPWM;

  // power supply voltage [V]

  driver.voltage_power_supply = 12;


  // link the motor to the sensor


  // set control loop type to be used

  motor.controller = MotionControlType::torque;

  // controller configuration based on the control type 

  motor.PID_velocity.P = 0.2;

  motor.PID_velocity.I = 20;

  motor.PID_velocity.D = 0;

  // default voltage_power_supply

  motor.voltage_limit = 12;

  // velocity low pass filtering time constant

  motor.LPF_velocity.Tf = 0.01;

  // angle loop controller

  motor.P_angle.P = 20;

  // angle loop velocity limit

  motor.velocity_limit = 50;

  // use monitoring with serial for motor init

  // monitoring port


  // comment out if not needed


  // initialise motor


  // align encoder and start FOC


  // set the initial target value = 2;

  // define the motor id

  command.add('M', onMotor, "motor");

  // Run user commands to configure and the motor (find the full command list in

  Serial.println(F("Motor commands sketch | Initial motion control > torque/voltage : target 2V."));

void loop() {

  // iterative setting FOC phase voltage


  // iterative function setting the outter loop target

  // velocity, position or voltage

  // if tatget not set in parameter uses variable




  // user communication;


Ok, can you explain more the behavior you’re experiencing? do you feel any type of torque, is the motor getting hot, how much current is the power supply drawing, etc.

It’ll be easier to help you out with more information.

I’m using 12V 1A power supply. When power on the motor rotates a little bit from left to right, after that it draw a lot of current, motor slowly getting warm. I can twist the rotor by hand, but it won’t return to its original position.
Thanks for helping.