Stepper motor + AS5600 not smooth and gets pretty hot

Hello, I’m trying to use a stepper motor in combination with the AS5600 but its doesn’t seem to be working correctly, I can’t figure out why.

#include <SimpleFOC.h>

// Stepper motor instance
StepperMotor motor = StepperMotor(50);
// Stepper driver instance
StepperDriver4PWM driver = StepperDriver4PWM(10, 9, 6, 5, 11, 3);

// encoder instance
MagneticSensorI2C encoder = MagneticSensorI2C(AS5600_I2C);

// commander interface
Commander command = Commander(Serial);
void onMotor(char* cmd){ command.motor(&motor, cmd); }

void setup() {
  // encoder initialiseren en linken

  // 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::angle;

  // 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;

Thanks in advance.

Carelsbergh Stijn

This seems to be a pid tunning issue. You can find your controller parameters using the studio or the by sending the commands through the commander.

And also start with voltage torque control. If it works well, go to velocity control and find good pid velocity values and once it works well. Go to the angle control. And find the good pid values (only P necessary). :slight_smile: