DRV8302 + Arduino Uno issue

Hello, I’m trying to run velocity_openloop, just to test my DRV8302 board.
I use the following snippet:

#include <SimpleFOC.h>

// DRV8302 pins connections
// don't forget to connect the common ground pin
#define INH_A 9
#define INH_B 10
#define INH_C 11

#define EN_GATE 7
#define M_PWM A1 
#define M_OC A2
#define OC_ADJ A3

// Motor instance
BLDCMotor motor = BLDCMotor(11);
BLDCDriver3PWM driver = BLDCDriver3PWM(INH_A, INH_B, INH_C, EN_GATE);


void setup() {
  Serial.begin(115200);
  Serial.println("Initializing...");

  // DRV8302 specific code
  // M_OC  - enable overcurrent protection
  pinMode(M_OC,OUTPUT);
  digitalWrite(M_OC,LOW);
  // M_PWM  - enable 3pwm mode
  pinMode(M_PWM,OUTPUT);
  digitalWrite(M_PWM,HIGH);
  // OD_ADJ - set the maximum overcurrent limit possible
  // Better option would be to use voltage divisor to set exact value
  pinMode(OC_ADJ,OUTPUT);
  digitalWrite(OC_ADJ,HIGH);


  // driver config
  // power supply voltage [V]
  driver.voltage_power_supply = 12;
  driver.init();
  // link the motor and the driver
  motor.linkDriver(&driver);


  // choose FOC modulation
  motor.foc_modulation = FOCModulationType::SpaceVectorPWM;

  // set control loop type to be used
  motor.controller = ControlType::velocity_openloop;

  motor.voltage_limit = 12;



  // comment out if not needed
//  motor.useMonitoring(Serial);

  // initialise motor
  motor.init();
  // align encoder and start FOC
  motor.initFOC();

  // set the inital target value
  motor.target = 2;

  Serial.println("Full control example: ");
  
  _delay(1000);
}


void loop() {
  // iterative setting FOC phase voltage
  motor.loopFOC();

  // iterative function setting the outter loop target
  // velocity, position or voltage
  // if tatget not set in parameter uses motor.target variable
  motor.move();
}

which I got by removing the code related to the encoder.
My Arduino Uno gets restarted while trying to execute “motor.initFOC();”
I tried with 2 different boards, even not connected to the DRV.

Could you please take a look?

Thanks in advance!

Remove the ‘initFOC ()’ call.
In the library version v2.0.x the initFOC and loopFOC should not be called in open-loop mode. :slight_smile:
This will change in v2.1

Thank you! I nearly burned my motor :slight_smile: But in the end, it worked!
Also, could you give me a hint on pole pairs, if I have a motor saying 12N14P, which parameter should I use?
And also a general question, did you manage to get a smooth movement of an outrunner RC-motor?

Hey @zjor,

Given what the manufacturer says, N means the number of coils and P means the number of poles (magnets). To know the number of pole pairs divide P (poles) by two, in you case 14/2 = 7 pole pairs.

Having a 7 pole pair out-runner spin smoothly at slow speeds is very tricky because of cogging torque.

2 Likes