I have connected a Maxon EC45 50W Motor + Encoder with a TI DRV8313EVM to control the velocity of the motor. The motor is rotating one full rotation during the initFOC() phase but then stopping permanently and not accepting commands. I have separately run the encoder_test as well as the driver_test and they work as expected. Below is my code
#include <SimpleFOC.h>
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(8);
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8, 7, 10);
// encoder instance
Encoder encoder = Encoder(2, 3, 2048, A0);
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
float target_velocity = 0;
// instantiate the commander
Commander command = Commander(Serial);
void onTarget(char* cmd){ command.scalar(&target_velocity, cmd); }
void setup() {
pinMode(11, OUTPUT); digitalWrite(11, HIGH);
pinMode(12, OUTPUT); digitalWrite(12, HIGH);
// initialize encoder hardware
encoder.init();
// hardware interrupt enable
encoder.enableInterrupts(doA, doB);
// power supply voltage
// default 12V
driver.voltage_power_supply = 24;
driver.init();
// link the motor to the driver
motor.linkDriver(&driver);
// set control loop type to be used
motor.controller = MotionControlType::velocity;
// velocity PI controller parameters
// default P=0.5 I = 10
motor.PID_velocity.P = 0.1;
motor.PID_velocity.I = 1;
//default voltage_power_supply
motor.voltage_limit = 24;
motor.voltage_sensor_align = 4;
// velocity low pass filtering
// default 5ms - try different values to see what is the best.
// the lower the less filtered
motor.LPF_velocity.Tf = 0.01;
// link the motor to the sensor
motor.linkSensor(&encoder);
// initialize motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// add target command T
command.add('T', onTarget, "target velocity");
// monitoring port
Serial.begin(115200);
Serial.println("Motor ready.");
Serial.println("Set the target velocity using serial terminal:");
_delay(1000);
}
void loop() {
// iterative foc function
motor.loopFOC();
// iterative function setting and calculating the velocity loop
// this function can be run at much lower frequency than loopFOC function
motor.move(target_velocity);
// user communication
command.run();
}