0

This is Arduino RC control car, the sketch tested good in a small motor, but burned two 60A drivers when put into 24V,500W motors, need help to find out whats wrong?

#include <VirtualWire.h>


//motor A connected between A01 and A02
//motor B connected between B01 and B02

int STBY = 2; //standby  // mod: was 10 --2 ??

int count;

//Motor A
int PWMA = 9; //Speed control   // need mod: was 3 change into 9
int AIN1 = 8; //Direction  // was 9
int AIN2 = 7; //Direction

//Motor B
int PWMB = 10; //Speed control   // need mod: was 5 change into 10
int BIN1 = 5; //Direction   // was 6
int BIN2 = 4; //Direction   ///was 16 put into p7 cause of Arduino uno no p16.

const boolean FORWARD = HIGH;
const boolean REVERSE = LOW;

float speed_Max = 252; //pwm usually goes from was:0-255 ////0-255 changed into 0-252

float speed_Min = 0;
float analogInput_Max = 1023;
float analogInput_Min = 0;
float analogInput_Middle_X = 515;//ideally it would be analogInput_Max / 2
float analogInput_Middle_Y = 495;//ideally it would be analogInput_Max / 2
float deadBand = 0;
float middleMax = (analogInput_Max / 2) + deadBand;
float middleMin = (analogInput_Max / 2) - deadBand;
boolean pastDirection = FORWARD;

void setup()
{
  // Configure Timer 2 for PWM @ 14 kHz.
  TCCR2A = 0;           // undo the configuration done by...
  TCCR2B = 0;           // ...the Arduino core library
  TCNT2  = 0;           // reset timer

  TCCR2A = _BV(COM2A1)  // non-inverted PWM on ch. A
           | _BV(COM2B1)  // same on ch; B
           | _BV(WGM20);  // mode 10: ph. correct PWM, TOP = ICR1

      TCCR2B = (TCCR2B & 0b11111000) | 0x01; //3.92116 [kHz] //** use this code got 3.9khz but joystick works not too good
    {

    Serial.begin(9600);  // Debugging only
    Serial.println("setup"); //Prints "Setup" to the serial monitor

    vw_set_rx_pin(6);       //Sets pin D12 as the RX Pin
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);      // Bits per sec
    vw_rx_start();       // Start the receiver PLL running

    pinMode(23, OUTPUT); //Relay one ////M1 added 2 was 2 -- 4
    pinMode(25, OUTPUT); //Relay two
    pinMode(27, OUTPUT); //Relay four
    pinMode(29, OUTPUT); //Relay five
    pinMode(31, OUTPUT); //Relay sex
    pinMode(33, OUTPUT); //Relay seven
    pinMode(35, OUTPUT); //Relay eight
    pinMode(37, OUTPUT); //Relay three
    pinMode(39, OUTPUT); //Relay three
    pinMode(41, OUTPUT); //Relay eight
    pinMode(43, OUTPUT); //Relay three
    pinMode(45, OUTPUT); //Relay three

    digitalWrite(23, HIGH); 
    digitalWrite(25, HIGH);
    digitalWrite(27, HIGH);
    digitalWrite(29, HIGH);
    digitalWrite(31, HIGH);
    digitalWrite(33, HIGH);
    digitalWrite(35, HIGH);
    digitalWrite(37, HIGH);
    digitalWrite(39, HIGH);
    digitalWrite(41, HIGH);
    digitalWrite(43, HIGH);
    digitalWrite(45, HIGH);
     }

  pinMode(STBY, OUTPUT); //// pin: the number of the pin whose mode you wish to set; mode: INPUT, OUTPUT, or INPUT_PULLUP.

  pinMode(PWMA, OUTPUT);
  pinMode(AIN1, OUTPUT);
  pinMode(AIN2, OUTPUT);

  pinMode(PWMB, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);
}

void loop() {

button(); //// disable 'button', no work. remove '//' enable, button works good
joystick(); //// disable 'joystick', no work. remove '//' enable, joystick works good, but no motor control yet

 }

void joystick() {

  uint8_t buf[VW_MAX_MESSAGE_LEN]; // This declares a variable array. instead of 7 variables buf1, buf2 etc...
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    int i;
    int column = 0;
    String message;
    int commands[30];
    // Message with a good checksum received, dump it.
    for (i = 0; i < buflen; i++)
    {
      //DEBUG:
      //Serial.print(char(buf[i]));

      if (char(buf[i]) == '|') {
        commands[column] = message.toInt();
        message = "";
        column++;
      } else {
        message += char(buf[i]);
      }
    }

    //one more time to capture the last value since the message does not end with |
    commands[column] = message.toInt();

    // DEBUG
    //    Serial.print("X: ");
    //    Serial.print(commands[0]);
    //    Serial.print(" Y: ");
    //    Serial.println(commands[1]);

     motorControl(commands[0], commands[1]);

  }

}

void move(int motor, int speed, boolean direction) {
  digitalWrite(STBY, HIGH); //disable standby

   if (motor == 1) {
    digitalWrite(AIN1, direction);
    digitalWrite(AIN2, !direction);
    analogWrite(PWMA, speed);
  } else {
    digitalWrite(BIN1, !direction);
    digitalWrite(BIN2, direction);
    analogWrite(PWMB, speed);
  }
}

void motorControl(float x, float y) {
  boolean currentDirection = y >= analogInput_Middle_Y;

    //map(value, fromLow, fromHigh, toLow, toHigh);
  if (currentDirection == REVERSE) {
    y = map(y, analogInput_Middle_Y, analogInput_Min, speed_Min, speed_Max) ;
  } else {
    y = map(y, analogInput_Middle_Y, analogInput_Max, speed_Min, speed_Max);
  }

  int subtractFromLeft = map(x, analogInput_Middle_X, analogInput_Min, speed_Min, y);
  int subtractFromRight = map(x, analogInput_Middle_X, analogInput_Max, speed_Min, y);

  if (subtractFromRight < 0) {
    subtractFromRight = 0;
  }

  if (subtractFromLeft < 0) {
    subtractFromLeft = 0;
  }

  int Throttle_RIGHT = y - subtractFromRight;
  int Throttle_LEFT = y - subtractFromLeft;

  boolean currentDirection_LEFT = currentDirection;
  boolean currentDirection_RIGHT = currentDirection;


  if (Throttle_LEFT < 1 && Throttle_RIGHT > 1) {
    currentDirection_LEFT = !currentDirection;
    Throttle_LEFT = Throttle_RIGHT;
  }

  if (Throttle_RIGHT < 1 && Throttle_LEFT > 1) {
    currentDirection_RIGHT = !currentDirection;
    Throttle_RIGHT = Throttle_LEFT;
  }

  move(1, Throttle_LEFT, currentDirection_LEFT);
  move(2, Throttle_RIGHT, currentDirection_RIGHT);

  }

void button()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    int i;
    digitalWrite(13, true);  // Flash a light to show received good message
    // Message with a good checksum received, dump it.
    Serial.print("Got: ");

    for (i = 0; i < buflen; i++)
    {
      int c = (buf[i]);
      Serial.print(c);
      Serial.print(" ");
      if (c == 65 ) {
        digitalWrite(23, !digitalRead(23));  //// A--RELAY A1
      }

      if (c == 66 ) {
        digitalWrite(25, !digitalRead(25));  //// B--RELAY A2
      }

      if (c == 67 ) {
        digitalWrite(27, !digitalRead(27)); //// C--RELAY B1
      }

      if (c == 68 ) {
        digitalWrite(29, !digitalRead(29)); //// D--RELAY B2
      }
/*      
      if (c == 69 ) {
        digitalWrite(37, !digitalRead(37)); //// E--
      }

      if (c == 70 ) {
        digitalWrite(39, !digitalRead(39)); //// F--
      }
*/
      if (c == 71 ) {
        digitalWrite(31, !digitalRead(31)); //// G--RELAY C1
      }

      if (c == 72 ) {
        digitalWrite(33, !digitalRead(33));  //// H -- RELAY C2
      }

      if (c == 73 ) {
        digitalWrite(43, !digitalRead(43));  //// I --
      }

       if (c == 74 ) {
        digitalWrite(35, !digitalRead(35));  //// J --
      }

       if (c == 75 ) {
        digitalWrite(37, !digitalRead(37));  //// K --
      }

      if (c == 76 ) {
        digitalWrite(39, !digitalRead(39));  //// L --
      }
      if (c == 77 ) {
        digitalWrite(41, !digitalRead(41));  //// M --
      }
      if (c == 78 ) {
        digitalWrite(35, !digitalRead(35));  //// N --
      }

    }
    count++;
    // Serial.print(count);
    Serial.println("");
    digitalWrite(13, false);
  }
}

My new driver is came, I just scare to use it, heard that DC motor will draw upto 300A at the start, what should I do to reduce the start current?

9
  • What kind of drivers? Feb 24, 2019 at 18:01
  • this one: ebay.com/itm/…
    – laoadam
    Feb 24, 2019 at 18:17
  • There are lot of edits, what should I do with them?
    – laoadam
    Feb 24, 2019 at 18:18
  • how do you know that the sketch is the cause of the failure?
    – jsotola
    Feb 24, 2019 at 19:14
  • @jsotola I'm not sure, I checked online the driver was sold and used quite much, that's why I guess maybe wrong sketch resulted in the 'shoot through'?
    – laoadam
    Feb 24, 2019 at 20:31

1 Answer 1

4

As you wrote in comment you use this H bridge:

https://www.ebay.com/itm/60A-DC-Motor-Driver-Module-High-Power-motor-Speed-Control-Dual-Channel-H-bridge/122479397950

The description how to use it is clear: h-bridge features

But the listing doesn't say what will happen when you set state of A1,A2=1.1 to that H-bridge.

When you set value of A1,A2=1.1 to a unprotected (cheap) H-Bridge you get a direct short to ground through 2 transistors burning them instantly

H-Bridge and electricity path for 1,1

Your code actually does not protect against that:

   if (motor == 1) {
    digitalWrite(AIN1, direction);
    digitalWrite(AIN2, !direction);
    analogWrite(PWMA, speed);
  } else {
    digitalWrite(BIN1, !direction);
    digitalWrite(BIN2, direction);
    analogWrite(PWMB, speed);
  }
}

If previous value of direction is 0 (A1,A2=0,1) and you want to set direction to 1 (A1,A2=1,0) when arduino runs the line digitalWrite(AIN1, direction); for few cycles you actually end up with A1,A2=1,1 and MOSFETs go bye bye.

Try setting AIN1, AIN2 (or BIN1, BIN2) to 0 before adjusting the direction

   if (motor == 1) {
    digitalWrite(AIN1, LOW);
    digitalWrite(AIN2, LOW);

    digitalWrite(AIN1, direction);
    digitalWrite(AIN2, !direction);
    analogWrite(PWMA, speed);
  } else {
    digitalWrite(BIN1, LOW);
    digitalWrite(BIN2, LOW);

    digitalWrite(BIN1, !direction);
    digitalWrite(BIN2, direction);
    analogWrite(PWMB, speed);
  }
}

This way you are guaranteed that you always have at least one 0 there.

EDIT:

You wrote that the module contains IR2103s it should protect you from the problem I described above. (But my suggested fix is not dangerous so you can use it just in case)

There is another possibility. Maybe the rapidly changing of the direction induces high voltage spikes in the motor, and that burns the circuit. Do you see any power diodes there? Look at the image I pasted above it has 4 diodes that should safely discharge those spikes. Make sure your code does not change direction every few milliseconds.

11
  • Thank you Filip Franik, you are right. I remember that burned after be tested a while. Can you help me modify the sketch to avoid this?
    – laoadam
    Feb 25, 2019 at 0:32
  • Or is that possible to avoid this by use the circuit below: mycontraption.com/wp-content/uploads/2013/06/…
    – laoadam
    Feb 25, 2019 at 0:39
  • Couldn't you repair the H-bridge by replacing the dead MOSFETs?
    – Duncan C
    Feb 25, 2019 at 3:19
  • I guess it is possible, I checked the PCB plate was burned, the MOSFETs may be still usable, sure I can also replace new MOSFETs. I even purchased 2 pics new drivers on the way. Still I need the problem solved. Thanks.
    – laoadam
    Feb 25, 2019 at 13:37
  • @laoadam If you can read the part numbers on the ICs from that driver i can check the datasheet if that's actually the case. Usually the H-bridge drivers are protected. Feb 25, 2019 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.