The correct h-bridge or motor driver

Hi,

I am learning to program with arduino.
Now I am trying to make a 24v 300w dc brushed motor turn to an input setpoint.

I have tried to use a couple of cheap aliexpres moto monster motor drivers, these however where as good as dead on arrival. I also used a couple of double bts 43A motor drivers, same problem.

But I also ordered a Dual-Motor-Driver-Module-Board-H-bridge-DC-MOSFET-IRF3205-3-36V-10A

I used his motor driver with heatsinks attached en as a single h-bridge by connecting the dir en pwm pins to 2 pins instead of 4. I also added thicker traces with tin on the wider copper leads.
my power supply is 12v 40a with diode's so no higher voltage is given back on the +.

This was all working fine yesterday with slowly but steadily increasing the pwm value and direction change.

#define ENCODER_OPTIMIZE_INTERRUPTS
#define pwmpin 10
#define dirpin 12

#include <Encoder.h>
// Change these two numbers to the pins connected to your encoder.
//   Best Performance: both pins have interrupt capability
//   Good Performance: only the first pin has interrupt capability
//   Low Performance:  neither pin has interrupt capability
Encoder myEnc(2, 3);
//   avoid using pins with LEDs attached

void setup() 
{
  Serial.begin(250000);
  Serial.println("Basic Encoder Test:");
  // set timer for 31.000hz pwm only pin 9 and 10.
  int myEraser = 7;
  TCCR2B &= ~myEraser;
  int myPrescaler = 1;
  TCCR2B |= myPrescaler;
}

long oldPosition  = -999;
int pwm;
int target;
int error;
int minpos = 0;
int maxpos = 30000;
int maxerror = 250;
int minpwm = 60; //increasing these values for testing
int maxpwm = 240;

void loop() 
{
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) 
    {
      oldPosition = newPosition;
    }

  target = map(analogRead(A0),0, 1023, minpos ,maxpos);
  error = abs(newPosition - target);
  pwm = map(error,minpos, maxpos, minpwm ,maxpwm);

  
  Serial.print(" Error:");
  Serial.print(error);
  Serial.print(" PWM:");
  Serial.print(pwm);
  Serial.print(" Target:");
  Serial.println(newPosition);

  if(newPosition >= target)
  {
  
    if (error <= maxerror)
    {    
      digitalWrite(dirpin, LOW);
      analogWrite(pwmpin, 0);
    }  
    else
    {
      digitalWrite(dirpin, LOW);
      analogWrite(pwmpin, pwm);
    }
  }
  
  else if (newPosition <= target)
  {
    if (error <= maxerror)
    {    
      digitalWrite(dirpin, HIGH);
      analogWrite(pwmpin, 0);
    }
    
    else
    {
      digitalWrite(dirpin, HIGH);
      analogWrite(pwmpin, pwm);
    }
  }

}

But today i tried using PID, and i'l be honest. I'm not understanding it completely.
So my h-bridge burnt out, at least one of the irf3205 smoked and now its shorted out.

// PID motor position control.
// Thanks to Brett Beauregard for his nice PID library http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/

#include <PID_v1.h>
#include <Encoder.h>                      // Quadrature encoder B pin
#define M1              12                      // PWM outputs to L298N H-Bridge motor driver module
#define M2              10
Encoder myEnc(2, 3);

double kp = 0.3 , ki = 0.02 , kd = 0.01;             // modify for optimal performance
double input = 0, output = 0, setpoint = 0;
long temp;
PID myPID(&input, &output, &setpoint, kp, ki, kd, DIRECT);  // if motor will only run at full speed try 'REVERSE' instead of 'DIRECT'
long oldPosition  = -999;

void setup() {               // update encoder position
  int myEraser = 7;
  TCCR2B &= ~myEraser;
  int myPrescaler = 1;
  TCCR2B |= myPrescaler;
  myPID.SetMode(AUTOMATIC);
  myPID.SetSampleTime(1);
  myPID.SetOutputLimits(-254, 254);
  Serial.begin (115200);                              // for debugging
}

void loop() {
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) 
    {
      oldPosition = newPosition;
    }
  
  setpoint = map(analogRead(A0),0,1023,0,18414);                       // modify to fit motor and encoder characteristics, potmeter connected to A0
  input = newPosition ;                                // data from encoder
  // Serial.println(encoderPos);                      // monitor motor position
  myPID.Compute();                                    // calculate new output
  pwmOut(output);                                     // drive L298N H-Bridge module
}

void pwmOut(int out) {                                // to H-Bridge board
  if (out > 0) {
    digitalWrite(M1,HIGH );                             // drive motor CW
    analogWrite(M2, out);
    Serial.println(out);
  }
  else {
    digitalWrite(M1, LOW);
    analogWrite(M2, abs(out));     
    Serial.println(out);// drive motor CCW
  }
}

But I don't understand completely why, the current wasn't all that high, it was just oscillating a bit and then it shorted out.

It was drawing a lot more current before, at least 30A because I had a 30A fuse in between the psu + leads and it popped. After i put a new one in the h-bridge begane smoking after a while. This was after I set the kp ki and kd way down.

The only reason I can think of is setting the pwm to 248~ max, because the info on the aliexpress page says a duty cycle of 0 to 98% pwm. Or maybe that the motor gave back i higher voltage than 55v wich is the threshold voltage of the mosfets.

So my question is should I try again with one of those irf3205 h-bridges or maybe there is a drop in replacement for the irf3205 mosfet. Or should I ad better cooling? Al tho the mosfets weren't realy hot to the touch before the burnout. Hopefully I gave enough information.

thanks,

300 watts at 24v requires 12.5 amps so I am not surprised that a 10 amp driver gave up the fight. Get a driver that can handle 25 amps.

...R

Yes, but I connected the h-bridge for 1 motor so the current goes trough both motor channels for 1 motor. Hopefully making it work for double the amps. Plus I added cooling blocks to the fets. The irf3205 is actually rated at 55v 110a so I don't understand why it would blow. Except for the 55v rating. Because the motor will give of its own voltage when spinning. But I also considered that maybe the fets are to blame, because it is chinese market. And al lot of mosfets are of lower quality or even fake.

Is the driver intended to be used with the two h-bridges in parallel?

What is the stall current of the motor?

When you get to the level of individual mosfets I am out of my depth.

...R

The stall current is about 10 times the rated current for that size of motor - you need to implement
current sensing and limiting or else get an H-bridge that can handle 150A spikes.

If you think about a 300W motor at 24V, that's about 12A. If the motor is well designed it will
only be burning up 10% or less of that power in the windings, which means the windings are only
dissipating 30W, say. That means the winding resistance is about 0.2 ohms.

24V / 0.2 ohms = 120A, so this is the level of stall current.

An 8 milliohm MOSFET with 120A flowing is dissipating 115W. Of course the supply will struggle
though sometimes the energy stored in the electrolytics in the supply is enough to blow a chip up.

The way to deal with this problem of large stall currents in high power motors is to not let the
current build up that far. You can add current sensing with fast comparators / flip-flop to shut
off all the MOSFET drive when the current exceeds a threshold.

Professional motor drivers often are current controlled in the first place - current feedback is used
in the inner control loop so the current is always under control. Outer control loops then just have
to set the current set-point (which is clamped to safe limits).

I think I understand, is there maybe an example online you have in mind. I wil off course search it for myself also. But maybe you had a specifiek example in mind.
Thanks anyway off course.

Have you looked at the open source motor controller project?

Hi,
PUT A FUSE IN THE POSITIVE LEAD OF YOUR POWER SUPPLY.

It may save you "burning up stuff".

Tom... :slight_smile:

MOSFETs fail faster than fuses, typically. The fuse protects the wiring.

MarkT:
MOSFETs fail faster than fuses, typically. The fuse protects the wiring.

Exactly... And if anything stupid is done like changing the wiring with the power on.

Choice of fuse can make a difference to.
Fuse will protect against overloads.
For example, you have a 10A motor, 30A MOSFET, 15A fuse, if motor starts drawing current above 10A, the fuse will pop at 15A, before the rated 30A MOSFET.
At 24V 300W, a current limiting motor controller is essential.
If using battery for high current, the battery is capable of many times its rated current if short circuited.
NiMh and Lipo are capable of doing considerable damage.
We aren't talking 9V PP3 batteries.
Tom... :slight_smile: