Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/08/07 06:43
Read: times


 
#147983 - PWM code thoughts and help?
Hi all, long time reader, first time poster :)

I'm wondering if anyone could spend a bit of time looking over my code (I've been programming 8051's for about a month now so it's quite average). Basically I'm trying to generate a pwm signal with the on time controlled via the serial ..

Long story short, its not working! the ouput seems to have about a 99% ontime and 1% off time... Anyway if anyone could see what I'm trying to achieve and could guide me I'd greatly appreciate it! :)

Thanks in advance!



$MOD652

ORG 23h

MOV A,S0BUF
MOV R4,A
;CLR P3.7
CLR RI
RETI

org 100h

RPMDES EQU R0
TON EQU R3
TOFF EQU R2 
RPMACT EQU R7


INIT:


SETB ES0 ; enable serial interrupt
MOV S0CON,#50H ; SET TO SERIAL MODE1
MOV TMOD,#20H ; SET TIMER 1 TO MODE 2 (8 BIT AUTO RELAOD)
MOV TH1,#253 ;SET BAUD TO 9600
SETB TR1
SETB EA

RPMINPUT:

MOV RPMDES, #00Bh;

MOV A,#0FFh
MOV TOFF,A ; SET OFF TIME TO 100%

MOV A,#000h
MOV TON,A ; SET ON TIME TO 0% 

RAMP:

CALL RAMPUP

RPMREAD:
 
ADJUSTPWM:
CALL PWMOUT

JMP RPMREAD

RAMPUP:
INC TON
DEC TOFF
MOV A,TON
SUBB A,#150 ; ramp up to half speed - min 50, max 200
JNZ RAMPUP
CLR C
RET

PWMOUT:
SETB P3.7
CALL DELAYON
CLR P3.7
CALL DELAYOFF
RET

DELAYON:
;MOV TON,R4
MOV R5,#000h
DELAYONA:
INC R5
MOV A,TON
SUBB A,R5
JNZ DELAYONA
CLR C
RET

DELAYOFF:

DELAYOFFA:
INC R5
MOV A,R5
CJNE A,#0FFh,CONT
CONT:
RET

end


List of 22 messages in thread
TopicAuthorDate
PWM code thoughts and help?            01/01/70 00:00      
   Some thoughts and help            01/01/70 00:00      
      very good help Russ            01/01/70 00:00      
      cheers!            01/01/70 00:00      
      character for 32            01/01/70 00:00      
         Good            01/01/70 00:00      
      A & R4 fatal occurence            01/01/70 00:00      
         Info on interrupts            01/01/70 00:00      
            Right next to me...            01/01/70 00:00      
               Aha            01/01/70 00:00      
      tell the truth!            01/01/70 00:00      
         Take a few deep breaths            01/01/70 00:00      
            no arteries popping            01/01/70 00:00      
   hows this? :)            01/01/70 00:00      
      Better, but still has problems            01/01/70 00:00      
         running out of subject line ideas            01/01/70 00:00      
            re: running out of subject line ideas :)            01/01/70 00:00      
            Some comments            01/01/70 00:00      
   Interrupts and shared resources            01/01/70 00:00      
   a thought - if it is help is up to you            01/01/70 00:00      
   More on the PWM program            01/01/70 00:00      
      Purpose of my question            01/01/70 00:00      

Back to Subject List