Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How To Rotate Motor In Reverse Diection

Status
Not open for further replies.

sarikagole78

New Member
HELLO,
I'VE WRITTEN CODE TO GENERATE SQUARE WAVE PULSES FOR ROTATING A MOTOR IN BOTH DIRECTION i.e in forward and in reverse direction for 5 second each for that i'm rotating the port pins for required frequency and motor is running successfully but in only one direction its not reversing the direction. for this i interchanged the status of phase R and Y how i can achieve this as i'm new to this i'm not geeting the fault.pls help me.
CODE:


phase equ B'00111000'
revphase equ B'00001110'


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


START
rcall INIT


HERE:
rcall PHASE
rcall DELAY5sec

rcall REVPHASE

rcall DELAY5sec
GOTO HERE



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

;****************************************
;INTIALISATION OF PORT PINS IN NORMAL MODE
;****************************************
PHASE:
movlw phase
movwf PORTD
return

;***********************************
;PORT PINS IN REVERSE MODE
;***********************************
REVPHASE:
MOVFF COUNT5,PORTD
BTFSC PORTD,5
JL:GOTO OO1
JL1:BCF PORTD,1
BCF PORTD,5
GOTO OO2
OO1:BSF PORTD,1
BCF PORTD,5
OO2: BTFSC PORTD,2
KL:GOTO KL2
KL1:BCF PORTD,4
BCF PORTD,2
GOTO KL3
KL2: BSF PORTD,4
BCF PORTD,2
KL3:MOVFF PORTD,COUNT6
MOVFF COUNT5,PORTD
BTFSC PORTD,1
ZX:GOTO YU1
ZX1:BCF PORTD,5
BCF PORTD,1
GOTO YU3
YU1:BSF PORTD,5
BCF PORTD,1
YU3: BTFSC PORTD,4
ZX2:GOTO ZX3
ZX4:BCF PORTD,2
BCF PORTD,4
GOTO ZX5
ZX3:BSF PORTD,2
BCF PORTD,4
ZX5:CLRF W
MOVF PORTD,W
IORWF COUNT6,W
MOVWF PORTD
return



;FIRST MOTOR SHOULD RUN FOR 5SEC IN 1 DIRECTION AND FOR NEXT 5;SEC ;IN REVERSE DIRECTION

DELAY5sec:
bcf PIR2,TMR3IF ;Clear the TMR3 interrupt flag.

MOVLW 0X02
MOVWF COUNT2
FT1: movlw D'10';'50'
movwf COUNT1

sec3: movlw 0xFF ;Load TMR3 with the value 0xFFF0
movwf TMR3H
movlw 0xF0
movwf TMR3L
bSf T3CON,TMR3ON ;Clear the Timer3 interrupt flag again.
T3POLL3
btfss PIR2,TMR3IF ;Poll TMR3 interrupt flag to wait for another TMR3 overflow.
bra T3POLL3
BTFSC PORTA,2
DD1: GOTO DD2
DD3: GOTO VOLTAGE_C
DD2:
rcall TENMS
bcf PIR2,TMR3IF ;Clear the Timer3 interrupt flag again.
bcf T3CON,TMR3ON ;Clear the Timer3 interrupt flag again.
decfsz COUNT1,1
goto sec3
DECFSZ COUNT2,1
GOTO FT1;sec3
MOVFF PORTD,COUNT5

return
;**********************************************************************************
;THIS ROUTINE IS FOR 5HZ 120DEGREE PHASE SHIFT
;************************************************************************************
TENMS
MOVLW TENMSH
MOVWF COUNTH
MOVLW TENMSL
MOVWF COUNTL
TEN1
DECFSZ COUNTL,F
GOTO TEN1
DECFSZ COUNTH,F
GOTO TEN1
rrcf PORTD,F
bcf PORTD,7
btfsc STATUS,C
bsf PORTD,5

TENMSEND

return
 
Can you post the schematic? Type of motor? Maybe repost the program again.

Type [.code] paste the program and type [./code]. Without the
. in from of the word code and /code
 
thank u for replying,
i'm controlling 3=phase induction motor through pic18f452 for that i've to generate 6 pulses which i'm giving to pwn driver chip. motor is running successfully but only in one direction but if we interchange any 2 phases then motor will run in reverse direction and i'm doing same in my code then why its not happening
Code:
phase equ B'00111000'
revphase equ B'00001110'


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


START
rcall INIT


HERE:
rcall PHASE
rcall DELAY5sec     ;this routine is for rotating motor in one direction

rcall REVPHASE  ;this routine is for interchanging 2 phases R and Y

rcall DELAY5sec    ;this routine is for rotating motor in one direction

GOTO HERE



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

;****************************************
;INTIALISATION OF PORT PINS IN NORMAL MODE
;****************************************
PHASE:
movlw phase
movwf PORTD
return

;***********************************
;interchange R and Y to reverse the motor direction
;***********************************
REVPHASE:
MOVFF COUNT5,PORTD
BTFSC PORTD,5
JL:GOTO OO1
JL1:BCF PORTD,1
BCF PORTD,5
GOTO OO2
OO1:BSF PORTD,1
BCF PORTD,5
OO2: BTFSC PORTD,2
KL:GOTO KL2
KL1:BCF PORTD,4
BCF PORTD,2
GOTO KL3
KL2: BSF PORTD,4
BCF PORTD,2
KL3:MOVFF PORTD,COUNT6
MOVFF COUNT5,PORTD
BTFSC PORTD,1
ZX:GOTO YU1
ZX1:BCF PORTD,5
BCF PORTD,1
GOTO YU3
YU1:BSF PORTD,5
BCF PORTD,1
YU3: BTFSC PORTD,4
ZX2:GOTO ZX3
ZX4:BCF PORTD,2
BCF PORTD,4
GOTO ZX5
ZX3:BSF PORTD,2
BCF PORTD,4
ZX5:CLRF W
MOVF PORTD,W
IORWF COUNT6,W 
MOVWF PORTD
return



;FIRST MOTOR SHOULD RUN FOR 5SEC IN 1 DIRECTION AND FOR NEXT 5;SEC ;IN REVERSE DIRECTION

DELAY5sec:
bcf PIR2,TMR3IF ;Clear the TMR3 interrupt flag.

MOVLW 0X02
MOVWF COUNT2
FT1: movlw D'10';'50'
movwf COUNT1

sec3: movlw 0xFF ;Load TMR3 with the value 0xFFF0
movwf TMR3H
movlw 0xF0 
movwf TMR3L
bSf T3CON,TMR3ON ;Clear the Timer3 interrupt flag again.
T3POLL3
btfss PIR2,TMR3IF ;Poll TMR3 interrupt flag to wait for another TMR3 overflow.
bra T3POLL3
BTFSC PORTA,2
DD1: GOTO DD2
DD3: GOTO VOLTAGE_C
DD2:
rcall TENMS
bcf PIR2,TMR3IF ;Clear the Timer3 interrupt flag again. 
bcf T3CON,TMR3ON ;Clear the Timer3 interrupt flag again. 
decfsz COUNT1,1
goto sec3
DECFSZ COUNT2,1
GOTO FT1;sec3
MOVFF PORTD,COUNT5

return
;************************************************* *********************************
;THIS ROUTINE IS FOR 5HZ 120DEGREE PHASE SHIFT
;************************************************* ***********************************
TENMS
MOVLW TENMSH
MOVWF COUNTH
MOVLW TENMSL
MOVWF COUNTL
TEN1
DECFSZ COUNTL,F 
GOTO TEN1
DECFSZ COUNTH,F
GOTO TEN1
rrcf PORTD,F 
bcf PORTD,7 
btfsc STATUS,C 
bsf PORTD,5 

TENMSEND

return
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top