Hi,
We’re having issues getting lowside current sense to work.
Current sense init failed!
Code generated with SimpleFOCGenerator
Any obious errors?
#include <SimpleFOC.h>
//HardwareSerial Serial1(USART1);
// BLDC motor instance BLDCMotor(polepairs, (R), (KV))
BLDCMotor motor = BLDCMotor(14);
// BLDC driver instance BLDCDriver3PWM(phA, phB, phC, (en))
BLDCDriver3PWM driver = BLDCDriver3PWM(PB0, PA7, PA6, PA8);
// position / angle sensor instance HallSensor(hallA, hallB , hallC , pole pairs)
HallSensor sensor = HallSensor(PB13, PB14, PB12, 14);
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}
// lowside current sense instance LowsideCurrentSense(R, gain, phA, phB, (phC))
LowsideCurrentSense currentsense = LowsideCurrentSense(0.007, 10, PA0, PA1, PA2);
// commander instance
Commander command = Commander(Serial);
void doTarget(char* cmd){command.motion(&motor, cmd);}
void setup() {
// start serial
Serial.begin(115200);
// USE_EXTERN is default (1k - 5k recommended), change to USE_INTERN if needed
sensor.pullup = Pullup::USE_EXTERN;
// initialize sensor
sensor.init();
// enable Hall effect interrupts
sensor.enableInterrupts(doA, doB, doC);
// link sensor to motor
motor.linkSensor(&sensor);
// set power supply voltage
driver.voltage_power_supply = 12;
// set driver voltage limit, this phase voltage
driver.voltage_limit = 4;
// initialize driver
driver.init();
// link driver to motor
motor.linkDriver(&driver);
// link driver to current sense
currentsense.linkDriver(&driver);
// set torque control type to voltage (default)
motor.torque_controller = TorqueControlType::voltage;
// set FOC modulation type to sinusoidal
motor.foc_modulation = FOCModulationType::SinePWM;
// velocity PID controller
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 2;
motor.PID_velocity.D = 0;
// set motor voltage limit, this limits Vq
motor.voltage_limit = 2;
// set motor velocity limit
motor.velocity_limit = 20;
// set motor current limit, this limits Iq
motor.current_limit = 2;
// use monitoring
motor.useMonitoring(Serial);
// initialize motor
motor.init();
// initialize current sensing and link it to the motor
// https://docs.simplefoc.com/inline_current_sense#where-to-place-the-current_sense-configuration-in-your-foc-code
currentsense.init();
if (currentsense.init()) Serial1.println("Current sense init success!");
else{
Serial1.println("Current sense init failed!");
return;
}
motor.linkCurrentSense(¤tsense);
// align sensor and start FOC
motor.initFOC();
// add command to commander
command.add('M', doTarget, "target");
_delay(1000);
}
void loop() {
// main FOC algorithm function
// the faster you run this function the better
motor.loopFOC();
// this function can be run at much lower frequency than loopFOC()
motor.move();
// significantly slowing the execution down
motor.monitor();
// user communication
command.run();
}