Hello all,
I have a BLDC motor without a decoder sensor and I’m testing the code example “Velocity open-loop control” to try to make it work with ESP32 in combination with DRV8302. It works for some seconds and then stops working.
Do you have any idea what is happening?
Thanks in advance for your help.
This is the code I’m using:
// Open loop motor control example
#include <SimpleFOC.h>
// DRV8302 pins connections
// don’t forget to connect the common ground pin
#define INH_A 21
#define INH_B 22
#define INH_C 23
#define INL_A 13
#define INL_B 12
#define INL_C 14
#define EN_GATE 19
#define M_PWM 36
#define M_OC 39
#define OC_ADJ
// BLDC motor & driver instance
// BLDCMotor( pp number , phase resistance, KV rating)
BLDCMotor motor = BLDCMotor(11 , 5, 1000);
BLDCDriver6PWM driver = BLDCDriver6PWM(INH_A, INL_A, INH_B,INL_B, INH_C, INL_C, EN_GATE);
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&motor.target, cmd); }
void doLimitCurrent(char* cmd) { command.scalar(&motor.current_limit, cmd); }
void setup() {
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor current (provided resistance)
motor.current_limit = 3;
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
motor.init();
motor.initFOC();
// add target command T
command.add(‘T’, doTarget, “target velocity”);
command.add(‘C’, doLimitCurrent, “current limit”);
Serial.begin(115200);
Serial.println(“Motor ready!”);
Serial.println(“Set target velocity [rad/s]”);
_delay(1000);
}
void loop() {
motor.loopFOC();
// open loop velocity movement
// using motor.current_limit and motor.velocity_limit
motor.move();
// user communication
command.run();
}