Spike on Velocity in simplefoc studio

Hi everyone
I’m using a stm32f4 discovery board with as5048a position sensor via SPI connection to a BLDC motor.
I use IGBT with corresponding driver to run motor.
When I use simplefoc studio and monitor velocity, I see some significant spike on Vel.

My code :

#include <SimpleFOC.h>

HardwareSerial Serial1(PB11, PB10);

/// F407VGT6 TIM1
#define PHA_H PE9 // TIM1
#define PHA_L PA7 // TIM1
#define PHB_H PE11 // TIM1
#define PHB_L PB0 // TIM1
#define PHC_H PE13 // TIM1
#define PHC_L PB1 // TIM1

// /SPI 1 (AS5048A)
#define MOSI_ENC PB4
#define MISO_ENC PB5
#define CLK_ENC PB3
#define CS_ENC PE3

MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, CS_ENC);
SPIClass SPI_1(MISO_ENC, MOSI_ENC, CLK_ENC); //(mosi, miso, sclk)

// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(5);
BLDCDriver6PWM driver = BLDCDriver6PWM(PHA_H, PHA_L, PHB_H, PHB_L, PHC_H, PHC_L);

InlineCurrentSense current_sense = InlineCurrentSense(40.0, PA0, PA1, PA2);

float target_velocity = 0;

Commander command = Commander(Serial1);
void doMotor(char* cmd) { command.motor(&motor, cmd); }

void setup() {
sensor.init(&SPI_1);

motor.linkSensor(&sensor);

driver.voltage_power_supply = 24;
driver.pwm_frequency = 32000;
driver.dead_zone = 0.05;
driver.init();

current_sense.linkDriver(&driver);
motor.linkDriver(&driver);
motor.voltage_sensor_align = 5;

motor.controller = MotionControlType::velocity;
motor.torque_controller = TorqueControlType::foc_current;
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;

motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
motor.PID_velocity.D = 0.0;

motor.PID_current_q.P = 0.15;
motor.PID_current_q.I= 0.4;
motor.PID_current_q.limit = 80.0;
motor.PID_current_d.P= 0.15;
motor.PID_current_d.I = 0.4;
motor.PID_current_d.limit = 80.0;
motor.LPF_current_q.Tf = 0.01f;
motor.LPF_current_d.Tf = 0.01f;

motor.phase_resistance = 0.25;
motor.current_limit = 80;
driver.voltage_limit = 20;
motor.voltage_limit = 20;
motor.PID_velocity.output_ramp = 1000;
motor.LPF_velocity.Tf = 0.01f;
motor.LPF_angle.Tf = 0.01f;

Serial1.begin(115200);
motor.useMonitoring(Serial1);
motor.monitor_downsample = 0;
motor.init();

current_sense.init();
motor.linkCurrentSense(&current_sense);
motor.initFOC();
command.add(‘M’, doMotor, “Motor”);

Serial1.println(F(“Motor ready.”));
Serial1.println(F(“Set the target velocity using serial terminal:”));
_delay(1000);

}

void loop() {
motor.loopFOC();
motor.move();
motor.monitor();
command.run();

}

The motor has a vibrant sound and idk how to remove it.
It has to work without sound like this.

Hi @Ali_Mohajeri

The SimpleFOC Studio only displays data received from the motor. It’s possible that errors are being introduced during the transmission of data via serial communications, which could be causing the spark event you mentioned.

BR

Hi
Thanks for your reply.
I found my problem.
My power cable was near my control and sensor cable that leads to make noise on them and then the sparks occurred.

1 Like