Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

dc motor speed control usinfg 8051

Status
Not open for further replies.

raja555

Junior Member level 1
Junior Member level 1
Joined
Feb 15, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,373
hi,
i m using a 12v dc motor with 8051 m cu. i want to know how i control its speed in different stages means i have connected a switch p2.5 for which i control my dc motor in different speed like in ,
1st stage: the motor rotate slow
2nd: medium
3rd:fast
4th:stop
so i want to know the details of it to control my motor..
pl z help me.


thank you sir
 

raja555

Junior Member level 1
Junior Member level 1
Joined
Feb 15, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,373
i know but pl z tell me the how the use of it pwm method.. pl z tell me the assembly program of it.how i will give the time delay ..its so urgent sir.




thank you sir.

- - - Updated - - -

hi,
plz tell me its so important for me...........

- - - Updated - - -

hi,
i m using a 12v dc motor with 8051 m cu. i want to know how i control its speed in different stages means i have connected a switch p2.5 for which i control my dc motor in different speed like in ,
1st stage: the motor rotate slow
2nd: medium
3rd:fast
4th:stop
so i want to know the details of it to control my motor..
pl z help me.


thank you sir

- - - Updated - - -

hi,
i m using a 12v dc motor with 8051 m cu. i want to know how i control its speed in different stages means i have connected a switch p2.5 for which i control my dc motor in different speed like in ,
1st stage: the motor rotate slow
2nd: medium
3rd:fast
4th:stop
so i want to know the details of it to control my motor..
pl z help me.


thank you sir
 

Jestin_cubetech

Advanced Member level 1
Advanced Member level 1
Joined
Jun 24, 2012
Messages
499
Helped
76
Reputation
152
Reaction score
73
Trophy points
1,328
Activity points
3,697
Code:
#include <REGX52.H>

sbit FAN    = P3^1;	

unsigned int duty1,duty2,pwm_count;
////////////////////////    PWM     ///////////////////// 
void pwm() interrupt 1	     //timer 1
{
TF0=0;
TH1=100;
pwm_count++; 

if(pwm_count<=duty1)   FAN=1;    else  FAN=0;      // duty1=  duty cycle     [dutycycle  must be less than or equal to pwm_count]

if(pwm_count>100)                                                       //  pwm_count  = TIME PERIOD 
{
pwm_count=0;
FAN=0;
}
}
}


////////////////////////////////  main  //////////////////// 
void main()
{
P0=0X0C; TMOD=0X33; IE=0X8A;
FAN=0;
TH0=0X0;	  TR0=0x1;
/////////////////////////////////MAIN LOOP /////////////////////////////// 
while(1)
{


// user code  duty++ ;  increase the fan speed
// duty-- ;  decrease the fan speed
	
}
}
 

raja555

Junior Member level 1
Junior Member level 1
Joined
Feb 15, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,373
i need a assembly code sir ,,,,,plz help me its urgent...........

- - - Updated - - -

hi,
i m using a 12v dc motor with 8051 m cu. i want to know how i control its speed in different stages means i have connected a switch p2.5 for which i control my dc motor in different speed like in ,
1st stage: the motor rotate slow
2nd: medium
3rd:fast
4th:stop
so i want to know the details of it to control my motor..
pl z help me.


thank you sir
 

Advanced Member level 4
Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
When the delay is being executed the uC cannot do any other thing. It is good to use counters and pwm. https://www.edaboard.com/threads/216730/

Check this. http://www.pages.drexel.edu/~kws23/tutorials/PWM/PWM.html

https://www.edaboard.com/threads/220963/

What type of motor are you using. DC motor, servo motor, stepper motor. Can you zip and post your schematic?

Convert this C Code to asm

Code:
#include <reg51.h>
sbit MTR = P1^0;
void MSDelay(unsigned int value);

void main() {
	unsigned char z;
P2 = 0xFF;
z = P2;
z = z & 0x03;
	MTR = 0;
while (1) {
	switch(z) {
	case(0):{
		MTR = 1;
		MSDELAY(25);
		MTR = 0;
		MSDelay(75);
		break;

}
case(1):{
		MTR = 1;
		MSDELAY(50);
		MTR = 0;
		MSDelay(50);
		break;

}
case(2):{
		MTR = 1;
		MSDELAY(75);
		MTR = 0;
		MSDelay(25);
		break;

}
default:
MTR = 1;
	
}
}

void MSDelay(unsigned int value)
{
    unsigned char x,y;
    for(x=0; x<1275; x++);
    for(y=0; y<value; y++);
}
 
Last edited:

raja555

Junior Member level 1
Junior Member level 1
Joined
Feb 15, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,373
actually i m using dc motor.....how i chnge my 4 steps speed by using counter..plz tell me briefly.



thank you sir
 

Advanced Member level 4
Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
See between the port on time and off time there are different delays which generates pwm signal which varies the speed of motor or brightness of led. I don't know 8051 asm. I know C.

- - - Updated - - -

with the above code the motor rotates at 4 speeds. 25%, 50%, 75%, and 100% depending wheather SW1 and SW2 is 0, SW1=0 and SW2 = 1, SW1 = 1, SW2 = 0, or SW1 = 1 and SW2 = 1.

Counter is just used for button. If only one button is used which varies the speed in 25%, 50%, 75% , 100% speeds. Then you can make the counter = 0 for motor off. counter = 1 means the pwm should be 25%, if counter = 2, pwm = 50%, counter = 3 means pwm = 75%, counter = 4 means pwm = 100%. using different amount od delays between the on time and off time of the pulse (port) you can create pwm signals. more the width of the signal more the speed will be. Less the width of the pulse, less the speed of motor. The code in the above post uses 2 switches. you can modify it so that it uses one switch and 4 different speed is achieved.

Can you zip and upload the proteus .dsn file. so that I can try to code.
 
Last edited:

raja555

Junior Member level 1
Junior Member level 1
Joined
Feb 15, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,373
sir,,
plz tell me how i control motor in different speed with out using counter,interrupt and timer.....plz tell me the normal way of control it with using 8051.......so urgent sir..................


thnk u sir
 

Advanced Member level 4
Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
Check my last 2 posts. The C Code is given. Can you upload your proteus .dsn file?

- - - Updated - - -

Try this mikroC Code.

Code:
#define SW P2_7_bit
#define MOTOR P1_0_bit

void main() {
unsigned int speed;

    while (1) {
    
       if(SW == 1) {
          Delay_ms(20);
          if(SW == 1) {
               speed = speed + 1;
          }
       }

       if(speed == 5) {
         speed = 0;
       }
       
       switch(speed) {
	case(0):{
		MOTOR = 0;
  		break;

        }
        case(1):{
		MOTOR = 1;
		Delay_ms(25);
		MOTOR = 0;
		Delay_ms(75);
		break;

        }
        case(2):{
		MOTOR = 1;
                Delay_ms(50);
		MOTOR = 0;
                Delay_ms(50);
		break;

        }
        case(3):{
                MOTOR = 1;
                Delay_ms(75);
		MOTOR = 0;
                Delay_ms(25);
		break;
        }
        case(4):{
                MOTOR = 1;
                break;
        }
        default:
                ;

    }
  }
}
 

raja555

Junior Member level 1
Junior Member level 1
Joined
Feb 15, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,373
i want to the asm code and just tell me about it with out using counter,interrupt and timer.....plz tell me the normal way of control it with using 8051.......so urgent sir..................


thnk u sir

- - - Updated - - -

i dont know about c code,,,,,,,,so i cant understand it.....plz give me referance about asm code......

- - - Updated - - -

i dont know about c code,,,,,,,,so i cant understand it.....plz give me referance about asm code..
 

Advanced Member level 4
Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
Try this. I don't know 8051 ASM. This works for 8051 and 8052.

ASM Code

Code:
;=====================================================
;	Pin Definations
;=====================================================
mot1for         equ             a0h             ;address of Port 2.0
mot1rev         equ             a1h             ;address of port 2.1
mot2for         equ             a2h             ;address of port 2.2
mot2rev         equ             a3h             ;address of port 2.3
;=====================================================
;	Main Program starts from here
;=====================================================
 		call slowstart
		call slowstop
here             jmp here
;=====================================================
; Sub routines starts from here
;=====================================================
slowstart:		jnb 21h,mot2
		;goto mot2 if motor 2 is selected
                 	jnb 20h,rev_rise_on1
		;goto rev_rise_on1 if reverse direction is selected
		jnb 27h,slowstop_invert_dir
		;if motor is in reverse dir stop motor&rotate forward
		jnb 26h,slowstart_ret
		;if motor is in forward dir don't rotate forward again

		call mot1_for_start
slowstart_ret       ret
slowstop_invert_dir call mot1_rev_stop
		call mot1_for_start
		ret
rev_rise_on1       jnb 26h,slowstart_invert
		;don't start if motor is in forward direction
		jnb 27h,slowstart_ret1
		;don't start if motor is in reverse direction
		call mot1_rev_start
slowstart_ret1     ret
slowstart_invert   call mot1_for_stop
                call mot1_rev_start
                ret
mot2                jnb 20h,mot2_rev
		jnb 29h,slowstart_inv
		jnb 28h,slowstart_ret2
		call mot2_for_start
slowstart_ret2      ret
slowstart_inv   call mot2_rev_stop
                call mot2_for_start
                ret
mot2_rev            jnb 28h,slowstart_inve
		jnb 29h,slowstart_ret3
		call mot2_rev_start
slowstart_ret3      ret
slowstart_inve  call mot2_for_stop
                call mot2_rev_start
                ret
;=========================================================
slowstop            jnb 21h,for_rise_off_mot2
		jnb 20h,rev_rise_off_mot1
		jb 22h,slowstop_ret
		call mot1_for_stop
slowstop_ret        ret

rev_rise_off_mot1  jb 23h,slowstop_ret1
		call mot1_rev_stop
slowstop_ret1      ret

for_rise_off_mot2    jnb 20h,rev_rise_off_mot2
		jb 24h,slowstop_ret2
		call mot2_for_stop
slowstop_ret2        ret

rev_rise_off_mot2    jb 25h,slowstop_ret3
		call mot2_rev_stop
slowstop_ret3       ret
;=========================================================
mot1_for_start      clr mot1for       ;on period of pwm
		mov r2,30H
		djnz r2,$
		setb mot1for        ;off period of pwm
		mov r2,31H
		djnz r2,$
		djnz r3,mot1_for_start   ;repeat the loop 10 times
		mov r3,#10
		mov a,30H
		add a,# 5          ;increment on period by 10 microsec
		mov 30H,a
		mov a,31H
		subb a,# 5         ;decrement off period by 10 microsec
		mov 31H,a
		djnz r4,mot1_for_start   ;repeat the loop 20 times
		mov r4,#20
		clr mot1for
		clr 22h            ;sense stop key as mot1+for
		clr 26h            ;motor1+rev
		ret
;=========================================================
mot1_rev_start      clr mot1rev            ;on period of pwm
		mov r2,30H
		djnz r2,$
		setb mot1rev             ;off period of pwm
		mov r2,31H
		djnz r2,$
		djnz r3,mot1_rev_start    ;repeat the loop 10 times
		mov r3,#10
		mov a,30H
		add a,# 5               ;increment on period by 10 microsec
		mov 30H,a
		mov a,31H
		subb a,# 5         ;decrement off period by 10 microsec
		mov 31H,a
		djnz r4,mot1_rev_start  ;repeat the loop 20 times
		mov r4,#20
		clr mot1rev
		clr 23h		;sense stop key as mot1+rev
		clr 27h		;mot1+for
		ret
;=========================================================
mot2_for_start     clr mot2for      ;on period of pwm
		mov r2,30H
		djnz r2,$
		setb mot2for       ;off period of pwm
		mov r2,31H
		djnz r2,$
		djnz r3,mot2_for_start  ;repeat the loop 10 times
		mov r3,#10
		mov a,30H
		add a,# 5          ;increment on period by 10 microsec
		mov 30H,a
		mov a,31H
		subb a,# 5         ;decrement off period by 10 microsec
		mov 31H,a
		djnz r4,mot2_for_start  ;repeat the loop 20 times
		mov r4,#20
		clr mot2for
		clr 24h               ;sense stop key as mot2+for
		clr 28h               ;mot2+rev
		ret
;=========================================================
mot2_rev_start      clr mot2rev            ;on period of pwm
		mov r2,30H
		djnz r2,$
		setb mot2rev             ;off period of pwm
		mov r2,31H
		djnz r2,$
		djnz r3,mot2_rev_start       ;repeat the loop 10 times
		mov r3,#10
		mov a,30H
		add a,# 5          ;increment on period by 10 microsec
		mov 30H,a
		mov a,31H
		subb a,# 5         ;decrement off period by 10 microsec
		mov 31H,a
		djnz r4,mot2_rev_start ;repeat the loop 20 times
		mov r4,#20
		clr mot2rev
		clr 25h                 ;sense stop key as mot2+rev
		clr 29h                 ;mot2+for
		ret
;=========================================================
mot1_for_stop       clr mot1for   ;on period of pwm
		mov r2,31H
		djnz r2,$
		setb mot1for    ;off period of pwm
		mov r2,30H
		djnz r2,$
		djnz r3,mot1_for_stop   ;repeat the loop 10 times
		mov r3,#10
		mov a,30H
		add a,# 5          ;increment off period by 10 microsec
		mov 30h,a
		mov a,31h
		subb a,# 5         ;decrement on period by 10 microsec
		mov 31h,a
		djnz r4,mot1_for_stop   ;repeat the loop 20 times
		mov r4,#20
		setb mot1for
		setb 22h  ;don't sense stop key if moh1+for is not started
		setb 26h         ;if mot1+for then don't start mot1+rev
		ret
;=========================================================
mot1_rev_stop      clr mot1rev      ; on period of pwm
		mov r2,31h
		djnz r2,$
		setb mot1rev       ;off period of pwm
		mov r2,30h
		djnz r2,$
		djnz r3,mot1_rev_stop  ;repeat the loop 10 times
		mov r3,#10
		mov a,30h
		add a,# 5          ;increment off period by 10 microsec
		mov 30h,a
		mov a,31h
		subb a,# 5         ;decrement on period by 10 microsec
		mov 31h,a
		djnz r4,mot1_rev_stop   ;repeat the loop 20 times
		mov r4,#20
		setb mot1rev
		setb 23h
		;don't sense stop key if mot1+rev is not started
		setb 27h          ;if mot1+rev then don't start mot1+for
		ret
;=========================================================
mot2_for_stop        clr mot2for     ;on period of pwm
		mov r2,31h
		djnz r2,$
		setb mot2for      ;off period of pwm
		mov r2,30h
		djnz r2,$
		djnz r3,mot2_for_stop   ;repeat the loop 10 times
		mov r3,#10
		mov a,30h
		add a,# 5          ;increment off period by 10 microsec
		mov 30h,a
		mov a,31h
		subb a,# 5         ;decrement on period by 10 microsec
		mov 31h,a
		djnz r4,mot2_for_stop   ;repeat the loop 20 times
		mov r4,#20
		setb mot2for
		setb 24h ;don't sense stop key if mot2+for is not started
		setb 28h       ;if mot2+for then don't start mor2+rev
		ret
;=========================================================
mot2_rev_stop      clr mot2rev    ;on period of pwm
		mov r2,31h
		djnz r2,$
		setb mot2rev      ;off period of pwm
		mov r2,30h
		djnz r2,$
		djnz r3,mot2_rev_stop  ;repeat the loop 10 times
		mov r3,#10
		mov a,30h          ;increment off period by 10 microsec
		add a,# 5
		mov 30h,a
		mov a,31h
		subb a,# 5         ;decrement on period by 10 microsec
		mov 31h,a
		djnz r4,mot2_rev_stop   ;repeat the loop 20 times
		mov r4,#20
		setb mot2rev
		setb 25h  ;don't sense stop key if mot2+rev is not started
		setb 29h     ;if mot2+rev then don't start mot2+for
		ret
;=====================================================
;      	Program ENDS here
;=====================================================

Try this. It varies the brightness of LED

Code:
outp equ P2
org 0h

main:mov r4,#0ffh
up0: mov r0,#100d     ;Set duty cycle
mov r1,#01d
acall out        ;light up LED
djnz r4,up0      ;loop for dome time

mov r4,#0ffh
up1: mov r0,#90d
mov r1,#10d
acall out
djnz r4,up1

mov r4,#0ffh
up2: mov r0,#80d
mov r1,#20d
acall out
djnz r4,up2

mov r4,#0ffh
up3: mov r0,#70d
mov r1,#30d
acall out
djnz r4,up3

mov r4,#0ffh
up4: mov r0,#60d
mov r1,#40d
acall out
djnz r4,up4

mov r4,#0ffh
up5: mov r0,#50d
mov r1,#50d
acall out
djnz r4,up5

mov r4,#0ffh
up6: mov r0,#40d
mov r1,#60d
acall out
djnz r4,up6

mov r4,#0ffh
up7: mov r0,#30d
mov r1,#70d
acall out
djnz r4,up7

mov r4,#0ffh
up8: mov r0,#20d
mov r1,#80d
acall out
djnz r4,up8


mov r4,#0ffh
up9: mov r0,#10d
mov r1,#90d
acall out
djnz r4,up9


mov r4,#0ffh
up11: mov r0,#10d
mov r1,#90d
acall out
djnz r4,up11

mov r4,#0ffh
up12: mov r0,#20d
mov r1,#80d
acall out
djnz r4,up12

mov r4,#0ffh
up13: mov r0,#30d
mov r1,#70d
acall out
djnz r4,up13

mov r4,#0ffh
up14: mov r0,#40d
mov r1,#60d
acall out
djnz r4,up14

mov r4,#0ffh
up15: mov r0,#50d
mov r1,#50d
acall out
djnz r4,up15

mov r4,#0ffh
up16: mov r0,#60d
mov r1,#40d
acall out
djnz r4,up16

mov r4,#0ffh
up17: mov r0,#70d
mov r1,#30d
acall out
djnz r4,up17

mov r4,#0ffh
up18: mov r0,#80d
mov r1,#20d
acall out
djnz r4,up18

mov r4,#0ffh
up19: mov r0,#90d
mov r1,#10d
acall out
djnz r4,up19

mov r4,#0ffh
up20: mov r0,#100d
mov r1,#01d
acall out
djnz r4,up20

ajmp main        ;Loop

**************************************************
;Out subroutine
out: mov outp,#0ffh
djnz r0,out
out1:mov outp,#00h
djnz r1,out1
ret

**************************************************
end

Code:
outp equ P0
org 0h

main:mov dptr,#pwm_data ;load pointer for lookup table
clr a
movc a,@a+dptr
mov r2,a
inc dptr
up:  clr a
movc a,@a+dptr
mov 40h,a          ;ON period
clr a
inc dptr
movc a,@a+dptr
mov 41h,a          ;OFF period
inc dptr
acall out
djnz r2,up
sjmp main

;*************************************************
out: mov r4,#02h
lp0: mov r3,#0ffh
lp:  mov r0,40h
mov r1,41h
lp1: mov outp,#0ffh
djnz r0,lp1
lp2: mov outp,#00h
djnz r1,lp2
djnz r3,lp
djnz r4,lp0
ret

;*************************************************
;Lookup table
pwm_data: db 15h  ;no of elements in the 
db 100d,001d      ;lookup table
db 090d,010d;       
db 080d,020d      ;each element consisting
db 070d,030d      ;of 2 bytes
db 060d,040d;
db 050d,050d      ;first byte is value 
db 040d,060d      ;for ON period
db 030d,070d      ;second byte is value 
db 020d,080d      ;for OFF period
db 010d,090d;
db 001d,100d;
db 010d,090d;
db 020d,080d;
db 030d,071d;
db 040d,060d;
db 050d,050d;
db 060d,040d;
db 070d,030d;
db 080d,020d;
db 090d,010d;
db 100d,001d;

;*************************************************

end
 

Attachments

  • PCAcookbook.pdf
    580 KB · Views: 89
Last edited:

raja555

Junior Member level 1
Junior Member level 1
Joined
Feb 15, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,373
thx for help me sir,,,,,i need 4 steps speed but its only clk and anti clkwise program.......so i hv more problem..so help me sir



thnk u sir
 

raja555

Junior Member level 1
Junior Member level 1
Joined
Feb 15, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,373
thx for help me sir,,,,,i need 4 steps speed but its only clk and anti clkwise program.......so i hv more problem..so help me sir



thnk u sir
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top