natasie
Member level 2
hey,
please i need help with PWM asm code for dc motor speed control. i found a code and edited it and it works but there is still a lot of problems. the code that works is this:
ORG 00H
AJMP START
LOW_DONE:
SETB F0 ;F0=1 TO INIDICATE START OF HIGH SECTION
SETB P1.1 ;TURN OFF LED
MOV TH0, R7 ;LOAD HIGH BYTE OF TIMER WITH R7 (OUR PULSE WIDTH CONTROL VALUE)
CLR TF0 ;CLR TO FLAG
TIMER0:
JB F0, HIGH_DONE ;F0 IS SET WHEN THE HIGH SECTION OF THE CYCLE IS DONE SO JUMP TO HIGH_DONE
;
HIGH_DONE: ;
CLR F0 ;F0=0 TO INDICATE THE START OF LOW SECTION
CLR p1.1 ;TURN OFF LED
MOV A, #0FFH ;MOVE 255 TO A
CLR C ;CLR CARRY BIT
SUBB A, R7 ;SUBTRACT R7 FROM A i.e. 255-R7
MOV TH0, A ;SO THE VALUE LOADED INTO TH0+R7=255
CLR TF0 ;CLR THE TIMER 0 FLAG INTR
AJMP LOOP
START:
MOV PSW, #00H
LOOP:
;SET PULSE WIDTH TO DIM
SJMP LOW_DONE
END
but it is clearly not correct even though when i connect the motor to p1.1, there is a decrease in motor speed but the porblem is that the code still has instructions for timer 0 and i do not know how to edit it and remove the codes. please help, i rily do not know anything abt pwm programming.
please i need help with PWM asm code for dc motor speed control. i found a code and edited it and it works but there is still a lot of problems. the code that works is this:
ORG 00H
AJMP START
LOW_DONE:
SETB F0 ;F0=1 TO INIDICATE START OF HIGH SECTION
SETB P1.1 ;TURN OFF LED
MOV TH0, R7 ;LOAD HIGH BYTE OF TIMER WITH R7 (OUR PULSE WIDTH CONTROL VALUE)
CLR TF0 ;CLR TO FLAG
TIMER0:
JB F0, HIGH_DONE ;F0 IS SET WHEN THE HIGH SECTION OF THE CYCLE IS DONE SO JUMP TO HIGH_DONE
;
HIGH_DONE: ;
CLR F0 ;F0=0 TO INDICATE THE START OF LOW SECTION
CLR p1.1 ;TURN OFF LED
MOV A, #0FFH ;MOVE 255 TO A
CLR C ;CLR CARRY BIT
SUBB A, R7 ;SUBTRACT R7 FROM A i.e. 255-R7
MOV TH0, A ;SO THE VALUE LOADED INTO TH0+R7=255
CLR TF0 ;CLR THE TIMER 0 FLAG INTR
AJMP LOOP
START:
MOV PSW, #00H
LOOP:
;SET PULSE WIDTH TO DIM
SJMP LOW_DONE
END
but it is clearly not correct even though when i connect the motor to p1.1, there is a decrease in motor speed but the porblem is that the code still has instructions for timer 0 and i do not know how to edit it and remove the codes. please help, i rily do not know anything abt pwm programming.