Continue to Site

# How do I change DC motor's direction without burning it ?

Status
Not open for further replies.

#### Deccoyi

##### Newbie level 3
I will drive a DC motor with L293D (H bridge) And there is a load on DC motor. When I change its polarity it will start spinning other way. But It might burn because of counter EMF.

I know that small motors can handle that counter EMF. But how do I prevent this? How do I change its polarity without burning it ? Is there a way to reduce this counter EMF ?

(My english is not so great I hope I could explain it. )

It is best to stop it then reverse it. You stop it by shorting it.

It is best to stop it then reverse it. You stop it by shorting it.

Thank you for your answer but it is my homework to change it suddenly

Your analysis is flawed. There's no "counter EMF" involved in the problem. A motor generates EMF according to it's actual speed, maintained by the motor and load inertia. To change the motor speed, e.g. reverse it's rotation, you have to decelerate and/or accelerate the inertial mass by applying a torque which is in turn related to a motor current.

The maximum motor current is determined intended rate of speed change. A motor has little problems to carry a high current for short times, this is normal operation. But the H-bridge has maximum ratings that should be observed. The only way to keep is to limit the rate of speed change by applying a speed ramp.

I suspect that the teacher wants the student to prevent the motor from burning out when the H-bridge suddenly changes its polarity and it is driving a heavy flywheel.
The flywheel keeps the motor turning in the original direction and generating a current with the original polarity then the power source polarity is suddenly changed causing the current in the motor to be double its stalled current.
Maybe shorting the motor will also cause it to burn out when it is driving a heavy flywheel so I agree that its speed should be ramped down then ramped back up in the opposite direction.

Deccoyi

### Deccoyi

Points: 2
yes this is exactly what i am talking about. it causing the current in the motor to be double its stalled current.

but when H bridge changes everything changes. how do i make it first slow down and speed up other direction?

The surge current when the motor's magnetics have risen to peak current is limited by the V+/Rs for a winding resistance , Rs . Current starts at 0 when V is applied, reaches a peak and when rotational speed picks up speed, the back EMF generated reduces the current drawn.

This surge current is typically 8x max Rms rating and the time duration depends on inertial load.

Reversing at full speed in one direction to the other obviously exceeds normal operation so current must be limited by calculated power transient rating of the motor or thermal monitoring and control using PWM, metal oxide ICL's and acceleration profile which is the current limited torque or force where f=ma. and mass is the inertial mass and acceleration is your problem.

Therefore your solution is a choice between open or closed loop current limiting the resulting Energy equations for thermal rise and your optimization of acceleration vs heat rise vs rise in aging. ICL"s are cheap but have limited lifespan and sluggish response times in seconds from overload. A precise current ramp>peak and decline at target speed is the optimum solution that results in acceptable heat rise. Since duty cycle and heat mass change, there must be some force cooling or a means to limit duty cycle of forced direction changes or adapt with temperature rise using a thermistor for feedback.

BTW I am still trying to solve the problem I am reading stuff for hours and I found nothing so far.

How do I suppress back emf ? Both ways. Everyone says freewheeleng diode but It works only one direction.

There's no back EMF problem with H-bridges like L293. No additional protection needed.

I haven't yet heard relevant details about the intended control method. PWM? On/off control?

If PWM, you have all options to perform a smooth speed ramp. If it's simple on/off control, you should check if the peak current with direct reversal can be handled by L293. Motor Rdc is the important information in this regard. The motor itself won't have problems with direct reversal if the inertia torque is small. What's connected to the motor shaft?

I have also a similar problem....
i want to change direction by switch1 n 2....
in a particular direction i want to flow initiallly slow then fast then slow then completely stop
while same in reverse case... for that i had designed a code here...

The problem is that it changed the direction....fwd n reverse
in fwd case the pwm worked successfully....as i need..
but problem in sw2 case...as i press it, it rotates in its direction but at a constant speed..
even while sw2 is running ...if i press sw1...it slow for 1s then it rotates in sw2 direction..
here is my code..

Code:
#include <avr/io.h>  // header file that enables AVR peripherals
#include <util/delay.h>  // header file to use time delay

void motor_fwd();
void motor_rev();
void SetPWMOutput(uint8_t duty);
void Wait();
uint8_t brightness=0;
uint8_t brightness2=0;
void SetPWMOutput2(uint8_t duty);
void Wait2();

void motor_fwd()
{
DDRB|=(1<<PB3);
//PORTC = 0b011110; _delay_ms(300); PORTC = 0b11111111; _delay_ms(10);
PORTC = 0b111110;
OCR2=35;_delay_ms(60);
OCR2=30;_delay_ms(30);
OCR2=20;_delay_ms(30);

for(brightness=0;brightness<255;brightness++)
{
//Now Set The Brighness using PWM

SetPWMOutput(brightness);

//Now Wait For Some Time
Wait();
//PORTC = 0b111101;
//DDRB|=(0<<PB3);

}
OCR2=100;_delay_ms(100); OCR2=255;PORTC = 0b110111;

}

void motor_rev()
{

//PORTC = 0b101101; _delay_ms(100); PORTC = 0b11111111; _delay_ms(10);
//void scan();

DDRB = 0x06;//DDRB|=(1<<PB1);
//PORTC = 0b011110; _delay_ms(300); PORTC = 0b11111111; _delay_ms(10);
PORTC = 0b111101;
OCR1A = 60; _delay_ms(60);
OCR1A = 120; _delay_ms(60);
OCR1A = 200; _delay_ms(60);
//OCR1A=35;_delay_ms(60);
//OCR1A=30;_delay_ms(30);
//OCR1A=20;_delay_ms(30);

for(brightness2=0;brightness2<255;brightness2++)
{
//Now Set The Brighness using PWM

SetPWMOutput2(brightness2);

//Now Wait For Some Time
Wait();
//PORTC = 0b111101;
//DDRB|=(0<<PB3);

}
//OCR1A=100;_delay_ms(100); OCR1A=255;
PORTC = 0b111011;

}

void SetPWMOutput(uint8_t duty)
{
OCR2=10;
}

void SetPWMOutput2(uint8_t duty)
{
OCR1A = 63;//0x01FF;//OCR1B=10;
}

/**
*void Wait()
*{
* _delay_loop_2(500);
*}
*/

void Wait()
{
_delay_loop_2(500);
}

int main (void)                //main program starts here
{
DDRD = 0b11110000; //switch
DDRC = 0b11111111; // led & motor
//PORTC = 0xFF; // all leds off

TCCR2|=(1<<WGM20)|(1<<WGM21)|(1<<COM21)|(1<<CS20);

//TCCR1A|=(1<<WGM10)|(1<<WGM11)|(1<<COM1A1)|(1<<CS10);
//TCCR1A|=(1<<WGM10)|(1<<WGM11)|(1<<COM1A1)|(1<<CS10);
TCCR1B = (1<<WGM12)|(1<<CS12)     // OC1A and OC1B are cleared on compare match
|(1<<CS10);
//TCCR1A |= (1 << COM1A1)|(1 << WGM11) | (1 << WGM10);
//TCCR1B |= (1 << CS11);

//TCCR1B|= (1<<CS10);

//DDRB|=(1<<PB3);

PORTC= 0x00;  _delay_ms(50); PORTC= 0xFF; _delay_ms(50);
while(1)                         //Never ending loop starts here
{

PORTD = 0xFF;

//motor_fwd();

if(PIND == 0b11111110) {motor_fwd(); }//{PORTC = 0b11111110;}

else if(PIND == 0b11111101) {motor_rev();}//{PORTC = 0b11111101;}

else if(PIND == 0b11111011) {PORTC = 0b11111011;}

else if(PIND == 0b11110111) {PORTC = 0b11110111;}

else{;}

}

}
- - - Updated - - -

motor is connected through l293d to pb3 n pb1 of atmega8
crystal 16mhz
on portc= status leds
Portd = for switches

Please forgive me.....i had tried to attached code in file but somehow i am unable to attache so i had paste it in a comment box

- - - Updated - - -

@ Deccoyie,

you can solve your problem from above code....which is ok till the direction changing without any problem.

Last edited by a moderator:

Status
Not open for further replies.