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
encoder.init();
// link the motor to the sensor
motor.linkSensor(&encoder);
// choose FOC modulation
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
// link the motor to the sensor
motor.linkDriver(&driver);
// 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
Serial.begin(115200);
// comment out if not needed
motor.useMonitoring(Serial);
// initialise motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// set the initial target value
motor.target = 2;
// define the motor id
command.add('M', onMotor, "motor");
// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
Serial.println(F("Motor commands sketch | Initial motion control > torque/voltage : target 2V."));
delay(1000);
}
void loop() {
// iterative setting FOC phase voltage
motor.loopFOC();
// iterative function setting the outter loop target
// velocity, position or voltage
// if tatget not set in parameter uses motor.target variable
motor.move();
Serial.print(encoder.getAngle());
Serial.print("\t");
// user communication
command.run();
}
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.