# The motor driver is very hot

**URL:** https://community.simplefoc.com/t/the-motor-driver-is-very-hot/84
**Category:** hardware support
**Created:** [August 25, 2020, 6:21am UTC](https://community.simplefoc.com/t/the-motor-driver-is-very-hot/84 "2020-08-25T06:21:21Z")
**Posts on this page:** 3
**Page:** 3

<div class="post-metadata">

### Author: ![Leonardo](https://community.simplefoc.com/user_avatar/community.simplefoc.com/leonardo/32/152_2.png) [@Leonardo](https://community.simplefoc.com/u/Leonardo)
#### Post date: [September 23, 2020, 8:07am UTC](https://community.simplefoc.com/t/the-motor-driver-is-very-hot/84/43 "2020-09-23T08:07:11Z")

</div>

Hi,@Antun_Skuric.  
Nice to see you again ,And thank guys for your reply  
I’m sorry I didn’t post these days. 😰  
And I’m busy with my work recently. I’ll record a detailed video in a few days to describe the problem. 😀

---

<div class="post-metadata">

### Author: ![Leonardo](https://community.simplefoc.com/user_avatar/community.simplefoc.com/leonardo/32/152_2.png) [@Leonardo](https://community.simplefoc.com/u/Leonardo)
#### Post date: [September 27, 2020, 10:12am UTC](https://community.simplefoc.com/t/the-motor-driver-is-very-hot/84/44 "2020-09-27T10:12:12Z")

</div>

Hi，guys.  
I recorded the serial monitor and the motor together today,If there are any problems, I will continue to improve, thanks everyone.

 ![WX20200927-180822@2x](https://community.simplefoc.com/uploads/default/original/1X/b228e26857818c5938e94d8332e25b41f510a0ba.jpeg)

[![](https://img.youtube.com/vi/jJVXR7PxflE/hqdefault.jpg "IMG 3195") ](https://www.youtube.com/watch?v=jJVXR7PxflE)

This is my code.

```auto

#include "SimpleFOC.h"

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

// The cs is Pin7,board is simplebgc mos v1.3
MagneticSensorSPI sensor = MagneticSensorSPI(7, 14, 0x3FFF);

// magnetic sensor instance
// MagneticSensorSPI sensor = MagneticSensorSPI(10, 14, 0x3FFF);

// magnetic sensor instance
//MagneticSensorI2C sensor = MagneticSensorI2C(0x36, 12, 0x0E, 4);

// Motor instance
// BLDCMotor motor = BLDCMotor(9, 5, 6, 7, 8);

// Motor instace(Simplebgc v1.3) （MOT1 9,10,11；MOT2 3,5,6）
BLDCMotor motor = BLDCMotor(3, 5, 6, 14, 8);

void setup() {

  // initialise magnetic sensor hardware
  sensor.init();
  // link the motor to the sensor
  motor.linkSensor(&sensor);

  // 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);

  //
  //12V
  motor.voltage_power_supply = 12;

  // set motion control loop to be used
  motor.controller = ControlType::velocity;

  
  motor.PI_velocity.P = 0.001;
  motor.PI_velocity.I = 0.2;
//
  motor.PI_velocity.voltage_limit = 3;
 
  motor.PI_velocity.voltage_ramp = 1000;

 

  motor.LPF_velocity.Tf = 0.01;

  // use monitoring with serial
  Serial.begin(115200);
  // comment out if not needed
  motor.useMonitoring(Serial);

  //
  motor.voltage_sensor_align = 0.1;
  // initialize motor
  motor.init();
  // align sensor and start FOC
  motor.initFOC();

  Serial.println("Motor ready.");
  Serial.println("Set the target velocity using serial terminal:");
  _delay(1000);
}

// velocity set point variable
float target_velocity = 0;

// utility function enabling serial communication with the user to set the target values
// this function can be implemented in serialEvent function as well
void serialReceiveUserCommand() {

  // a string to hold incoming data
  static String received_chars;

  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the string buffer:
    received_chars += inChar;
    // end of user input
    if (inChar == '\n') {

      // change the motor target
      target_velocity = received_chars.toFloat();
      Serial.print("Target velocity: ");
      Serial.println(target_velocity);

      // reset the command buffer
      received_chars = "";
    }
  }
}

void loop() {
  //unsigned int timecnt;
  // main FOC algorithm function
  // the faster you run this function the better
  // Arduino UNO loop ~1kHz
  // Bluepill loop ~10kHz
  //timecnt = millis()-timecnt;//Read once before testing the function,The unit is us
  motor.loopFOC();

  // Motion control function
  // velocity, position or voltage (defined in motor.controller)
  // this function can be run at much lower frequency than loopFOC() function
  // You can also use motor.move() and set the motor.target in the code
  motor.move(target_velocity);

  // function intended to be used with serial plotter to monitor motor variables
  // significantly slowing the execution down!!!!
  // motor.monitor();

  // user communication
  serialReceiveUserCommand();
  // timecnt = millis()-timecnt;//Subtract the last result after the function test is completed
  // Serial.print("timecnt=");//print the "timecnt"
  // Serial.println(timecnt );
}

```

---

<div class="post-metadata">

### Author: ![Owen\_Williams](https://community.simplefoc.com/user_avatar/community.simplefoc.com/owen_williams/32/105_2.png) [@Owen\_Williams](https://community.simplefoc.com/u/Owen_Williams)
#### Post date: [September 27, 2020, 8:36pm UTC](https://community.simplefoc.com/t/the-motor-driver-is-very-hot/84/45 "2020-09-27T20:36:35Z")

</div>

Your P is quite low. Are you tuning at low speed? I find it hard to tune P at low speed, instead i tune at half max speed (say 20 radians/s) and tune P first (holding i to zero). If P can give you 70% of target speed (i.e 14 rad/s) without oscillation, then later add I.

What was the clock speed of your mcu?

[Previous page](https://community.simplefoc.com/t/the-motor-driver-is-very-hot/84.md?page=2)
