Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

how to control the dc motor speed

Status
Not open for further replies.

pradeep23

Member level 5
Joined
Aug 20, 2012
Messages
86
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,866
hi everyone can anyone please tell me how to control the speed of dc motor with 8051 using PWM .......i dont know how to program for that ......please help me......thanks in advance
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545

pradeep23

Member level 5
Joined
Aug 20, 2012
Messages
86
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,866
ya thanks for replying and i am interfacing with 8051 .......
i am using this circuit only.......sir
l293d.gif
but i can't control that motor speed and i don't know how?
can anyone please tell me where can i refer for that.........

- - - Updated - - -

#include<reg51.h>

sbit sw1=P3^2;
sbit sw2=P3^3;

sbit L293D_A = P2^0; //Make positive of motor 1
sbit L293D_B = P2^1; //Make negative of motor 0
sbit L293D_E = P2^2; //Enable L293D



void rotate_f(void); //Forward run funtion
void rotate_b(void); //Backward run function
void breaks(void); //Motor stop function
void delay(void); //Some delay

void main(){
P3=0xFF;
P2=0x00;
//Our main function
while(1){ //Infinite loop


if(sw1==1 && sw2==0)
{
rotate_f(); //Run forward
delay(); //Some delay
breaks(); //Stop
delay(); //Some delay
}

if(sw2==1 && sw1==0)
{
rotate_b(); //Run Backwards
delay(); //Some delay
breaks(); //Stop
delay(); //Some delay
} //Do this infinitely
}
}


in the above program is correct or i don't know sir ok in this program i am using external interrupt int0 and int1 but it is not working correctly what will be the problem ....if i give interrupt also its not working
 

Jigar 4 Electronics

Full Member level 5
Joined
Apr 28, 2011
Messages
313
Helped
40
Reputation
80
Reaction score
38
Trophy points
1,318
Location
Hamilton, ON, Canada
Activity points
3,390
use L298N or make your own H-Bridge or use a small motor which have a current requirement less or equal to 500 mA, then you will get control on speed using PWM.

- - - Updated - - -

how much delay you have add, in program ?
Better you first make a program to just "ON & OFF" the motor.
 

pradeep23

Member level 5
Joined
Aug 20, 2012
Messages
86
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,866
it working for first interrupt ......it's only running in backward direction not in forward in that any sequence is wrong.....
 

Joined
Dec 4, 2012
Messages
4,294
Helped
822
Reputation
1,654
Reaction score
793
Trophy points
1,393
Location
Bangalore, India
Activity points
0
Are you using bi-directional dc motor? You only have to swap the outputs of your mcu going to l239D to reverse the direction. You can do that in code. If you are using switched then you should use debounce delays for sw1 and sw2. Which Compiler are you using? Keil uVision? Post your full code. I don't see the interrupt routine, and code for rotate_b(), rotate_f(), break() functions.
 

pradeep23

Member level 5
Joined
Aug 20, 2012
Messages
86
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,866
#include<reg51.h>

sbit sw1=P3^2;
sbit sw2=P3^3;

sbit L293D_A = P1^0; //Make positive of motor 1
sbit L293D_B = P1^1; //Make negative of motor 0
sbit L293D_E = P1^2; //Enable L293D



void rotate_f(void); //Forward run funtion
void rotate_b(void); //Backward run function
void breaks(void); //Motor stop function
void delay(void); //Some delay

void main(){
P3=0xFF;
P1=0x00;
//Our main function
while(1){ //Infinite loop


if(sw1==1 && sw2==0)
{
rotate_f(); //Run forward
delay(); //Some delay
breaks(); //Stop
delay(); //Some delay
}

if(sw2==1 && sw1==0)
{
rotate_b(); //Run Backwards
delay(); //Some delay
breaks(); //Stop
delay(); //Some delay
} //Do this infinitely
}
}

void rotate_f(){
L293D_A = 1; //Make positive of motor 1
L293D_B = 0; //Make negative of motor 0
L293D_E = 1; //Enable L293D
}

void rotate_b(){
L293D_A = 0; //Make positive of motor 0
L293D_B = 1; //Make negative of motor 1
L293D_E = 1; //Enable L293D
}

void breaks(){
L293D_A = 0; //Make positive of motor 0
L293D_B = 0; //Make negative of motor 0
L293D_E = 0; //Disable L293D
}

void delay(){ //Some delay...
unsigned char i,j,k;
for(i=0;i<0x20;i++)
for(j=0;j<255;j++)
for(k=0;k<255;k++);

}

- - - Updated - - -

i am using keil 3 uvision only......it's working for only one interrupt only.........
another interrupt is not taking ....it....wat will be the problem
 

Jigar 4 Electronics

Full Member level 5
Joined
Apr 28, 2011
Messages
313
Helped
40
Reputation
80
Reaction score
38
Trophy points
1,318
Location
Hamilton, ON, Canada
Activity points
3,390
it working for first interrupt ......it's only running in backward direction not in forward in that any sequence is wrong.....
That's natural with L293D. :)
what source you're using?

Adapter?
If yes then use Battery with 1 A (max.) rating, Because IC L293D has Temperature protection.
When the temp. of IC increases over a threshold (specified in datasheet) then it'll get off or will draw less current & so after switching from backward to forward it'll gets off or will reverse in very slowly....

That's because of Current, you're using a motor which may need or can stay upto 1 A, & L293D is not ready to provide that, it can provide upto 600-700mA (do confirm from the Datasheet).

& that's why I've advice to use L298N in my first comment, I am not sure but L298 can provide upto 2A.

To solve your current problem use a battery instead of adapter or use a heat sink.
 

pradeep23

Member level 5
Joined
Aug 20, 2012
Messages
86
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,866
how to give interrupt program for that can u please help me in that.....

- - - Updated - - -

i dont know how to give program in that ....

- - - Updated - - -

pwm_switch1.jpg .........i am using this circuit only.....

- - - Updated - - -

for the above program i posted before......any problem in that....
 

pradeep23

Member level 5
Joined
Aug 20, 2012
Messages
86
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,866
can you please help me in that how to program for that ?
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top