PWM code please help

Thread Starter

neil1221

Joined Feb 28, 2009
1
hi please help me with this code I need to run a dc motor at different duty cycles now I have created an assembly code that dictates the the PWM of the motor. but the problem is the on state does not correspond to the set PWM cycle( for example 90% duty cycle). When I check the signal output in oscilloscope it always set for about 50% duty cycle....please help me..

this is my program....please help me
_________________________________________________
L293A EQU P3.0 ; +motor
L293B EQU P3.1 ; -motor
L293E EQU P3.2 ; ENABLE (duty cycle output)
Switch100 EQU P1.2 ; rotate motor to 90% duty cycle
Switch80 EQU P1.3 ; rotate motor to 50% duty cycle
Switch70 EQU P1.4 ; rotate motor to 20% duty cycle
SwitchRu EQU P1.5 ; run motor
Switchsto EQU P1.6 ; stop motor
blinkled EQU P3.4 ;
org 0H
Main:
setb blinkled;
JB P1.2,RMotor90 ; go to 90% duty cycle of motor
JB P1.3,RMotor50 ; go to 50% duty cycle of motor
JB P1.4,RMotor20 ; go to 20% duty cycle of motor
JB P1.5,Runmotor ; go to run motor
JB P1.6,SMotor ; go to Smotor
sjmp Main ;

RMotor90:
Setb L293A ;
clr L293B ;
MOV R7,#0e6H ; Set pulse width control (230 "on state")
acall PWMsetup1 ;
acall TIMER_0_INTERRUPT;
sjmp Main;

RMotor50:
Setb L293A ;
clr L293B ;
MOV R7, #082H; (130 on state)
acall PWMsetup2 ;
acall TIMER_0_INTERRUPT ;
sjmp Main;

RMotor20:
Setb L293A ;
clr L293B ;
MOV R7,#00AH ; (10 on state)
acall PWMsetup3 ;
acall TIMER_0_INTERRUPT ;
sjmp Main;

RunMotor:
Setb L293A;
clr L293B;
Setb L293E;
sjmp Main;

SMotor:
clr L293A;
clr L293B;
clr L293E;

PWMsetup1:
MOV TMOD,#00H ; Timer0 in Mode 0
SETB EA ; Enable Interrupts
SETB ET0 ; Enable Timer 0 Interrupt
SETB TR0 ; Start Timer
ret

PWMsetup2:
MOV TMOD,#00H ; Timer0 in Mode 0
SETB EA ; Enable Interrupts
SETB ET0 ; Enable Timer 0 Interrupt
SETB TR0 ; Start Timer
ret

PWMsetup3:
MOV TMOD,#00H ; Timer0 in Mode 0
SETB EA ; Enable Interrupts
SETB ET0 ; Enable Timer 0 Interrupt
SETB TR0 ; Start Timer
ret
;0000000000000000000000000000000000000000000000000000000000000000000000000
TIMER_0_INTERRUPT:
JB F0, HIGH_DONE ; If F0 flag is set then we just finished
; the high section of the
LOW_DONE: ; cycle so Jump to HIGH_DONE
SETB F0 ; Make F0=1 to indicate start of high section
SETB L293E ; Make PWM output pin High
MOV TH0, R7 ; Load high byte of timer with R7
; (pulse width control value)
CLR TF0 ; Clear the Timer 0 interrupt flag

RETI ; Return from Interrupt to where
; the program came from

HIGH_DONE:
CLR F0 ; Make F0=0 to indicate start of low section
CLR L293E ; Make PWM output pin low
MOV A, #0FFH ; Move FFH (255) to A
CLR C ; Clear C (the carry bit) so it does
; not affect the subtraction
SUBB A, R7 ; Subtract R7 from A. A = 255 - R7.
MOV TH0, A ; so the value loaded into TH0 + R7 = 255
CLR TF0 ; Clear the Timer 0 interrupt flag



RETI ; Return from Interrupt to where
; the program came from

END
 
Top