Hi all,
I’m using a custom board with an ATmega328, DRV8313, and AS5600 to drive a BLDC motor and facing two issues:
- Noise during rotation: The motor produces a high-pitched sound, especially at mid to high speeds.
- Vibration at velocity 0: The motor vibrates significantly when trying to hold position.
I’m using a ROB-20441 motor from sparkfun with 7.5 ohms winding resistance and an 8V power supply.
Here’s my code:
#include <SimpleFOC.h>
MagneticSensorI2C sensor = MagneticSensorI2C(0x36, 12, 0x0E, 4);
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(3, 5, 6, 7);
float target_velocity = 10.0;
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }
void doLimit(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }
void doVelocity(char* cmd) { command.scalar(&motor.velocity_limit, cmd); }
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
Serial.begin(115200);
SimpleFOCDebug::enable(&Serial);
sensor.init();
motor.linkSensor(&sensor);
driver.voltage_power_supply = 12;
// driver.voltage_limit = 7.4;
// driver.pwm_frequency = 20000;
driver.init();
motor.linkDriver(&driver);
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// motor.motion_downsample = 10;
motor.controller = MotionControlType::velocity;
motor.PID_velocity.P = 0.3f; //0.4f
motor.PID_velocity.I = 10.0f; //1.0
// motor.PID_velocity.D = 0.01f;
motor.LPF_velocity.Tf = 0.001; //0.525f
motor.voltage_limit = 2;
motor.velocity_limit = 20;
// motor.motion_downsample = 10;
motor.PID_velocity.output_ramp = 10000;
motor.useMonitoring(Serial);
motor.init();
motor.zero_electric_angle = 6.14;
motor.sensor_direction = Direction::CW;
motor.initFOC();
command.add('T', doTarget, "target velocity");
Serial.println(F("Motor ready."));
Serial.println(F("Set the target velocity using serial terminal:"));
Serial.print("Sensor angle: ");
Serial.println(sensor.getAngle());
_delay(1000);
}
void loop() {
motor.loopFOC();
motor.move(target_velocity);
motor.monitor();
command.run();
}
Thanks for your time and help!