Problem using DRV8302 board with ESP32

Hi. So for 2 days I have been trying to get this setup running, but the motor won’t budge. I can hear the initiation sequence, but it is only summing quietly…
I checked out all the pins and it should work.
The drv8302 driver also supports a 3,3V interface so that also shouldn’t be a problem.
Using the Arduino uno I could get this setup running, but with the esp32 for some reason not…
I also made sure I only use pins from the esp32, which work…


Here is my code so far:

#include <SimpleFOC.h>

#define   INH_A 16
#define   INH_B 17
#define   INH_C 12
#define   EN_GATE 27
#define   M_PWM 26 
#define   M_OC 21
#define   OC_ADJ 25

BLDCMotor motor = BLDCMotor(20, 0.055);
BLDCDriver3PWM driver = BLDCDriver3PWM(INH_A, INH_B, INH_C, EN_GATE);

MagneticSensorSPI sensor = MagneticSensorSPI(5, 14, 0x3FFE);

void setup() {
  pinMode(M_OC,OUTPUT);
  digitalWrite(M_OC,LOW);
  pinMode(M_PWM,OUTPUT);
  digitalWrite(M_PWM,HIGH);
  pinMode(OC_ADJ,OUTPUT);
  digitalWrite(OC_ADJ,LOW);

  sensor.init();
  motor.linkSensor(&sensor);
  
  driver.voltage_power_supply = 20;
  driver.init();
  motor.linkDriver(&driver);

  motor.controller = MotionControlType::velocity;

  motor.PID_velocity.P = 0.2f;
  motor.PID_velocity.I = 20;
  motor.PID_velocity.D = 0;
  motor.voltage_limit = 20;
  motor.LPF_velocity.Tf =  0.01f;

  Serial.begin(115200);
  motor.useMonitoring(Serial);
  motor.current_limit = 15; // Amps - default 0.2Amps
  motor.init();
  motor.initFOC();

  Serial.println("Motor ready.");
  _delay(1000);
}

float target_velocity = 20; // 2Rad/s ~ 20rpm

void loop() {
  motor.loopFOC();

  motor.move(target_velocity);
}

Also an observation, which I made is that if I disconnect the common ground pin the summing gets louder, but still doesn’t turn :frowning:

This is a graph on how everything is wired:

Thanks for the Help!

Regards,
Laurenz

Questions. Did you check the PWM with an oscilloscope going into the MOSFETs High and Low gates? Did you check the PWM with an oscilloscope out of the MOSFETs High and Low into the motor? On your schematics I see you are doing 3PWM. Could it be you send only high but not low PWM? What is the MPWM value? Also, do you get PWM out of ESP32 to begin with into the driver? What is the oscilloscope saying? Lastly, is the open velocity working?

On Drv8302 OC_ADJ needs to be high. In your code, you have made it LOW. I checked you haven’t defined the sensor align voltage, set it to 1V. Always first test the torque control mode then move towards velocity and angle.

1 Like

OK Thanks @MoidKhan and @Valentine. I got my setup working (kindof). It is also a bummer that the Oscilloscope I orderd isn’t yet here…

I updated the schematic:

and the code:

#include <SimpleFOC.h>

#define   INH_A 16
#define   INH_B 17
#define   INH_C 12
#define   INL_A 15
#define   INL_B 13
#define   INL_C 22

#define   EN_GATE 27
#define   M_PWM 26 
#define   M_OC 21
#define   OC_ADJ 25

// BLDC driver instance
BLDCMotor motor = BLDCMotor(20, 0.055);
BLDCDriver6PWM driver = BLDCDriver6PWM(INH_A, INL_A, INH_B, INL_B, INH_C, INL_C, EN_GATE);
MagneticSensorSPI sensor = MagneticSensorSPI(5, 14, 0x3FFE);

void setup() {
  pinMode(M_OC,OUTPUT);
  digitalWrite(M_OC,HIGH);
  pinMode(M_PWM,OUTPUT);
  digitalWrite(M_PWM,LOW);
  pinMode(OC_ADJ,OUTPUT);
  digitalWrite(OC_ADJ,HIGH);

  sensor.init();                                                                
  motor.linkSensor(&sensor);
  
  driver.voltage_power_supply = 20;
  driver.init();
  motor.linkDriver(&driver);

  motor.controller = MotionControlType::velocity;
  motor.PID_velocity.P = 0.2f;
  motor.PID_velocity.I = 20;
  motor.PID_velocity.D = 0;
  
  motor.voltage_limit = 20;
  motor.LPF_velocity.Tf =  0;

  Serial.begin(115200);
  motor.useMonitoring(Serial);
  motor.current_limit = 15; // Amps - default 0.2Amps
  motor.init();
  motor.initFOC();

  Serial.println("Motor ready.");
  _delay(1000);
}

float target_velocity = 20 ; // 2Rad/s ~ 20rpm

void loop() {
  motor.loopFOC();

  motor.move(target_velocity);
}

The startup (initiation sequence) works like a charm. The only problem I am still facing is that the motor turns at a velocity and then at an angle suddendly starts chalking.
Here is a demo video:

I also updated my setup:


I added a buck converter to 20V from 45V so I don’t get any problems with the PWM resolution…

Thanks for the help!

Regards,
Laurenz

Are you able to move the motor in torque control? If your answer is yes then you need to tune your PID parameter for velocity and angle.

Also, In your code put the target_velocity in the setup loop, currently, it’s declared outside the setup loop.

Thanks
Moid