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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/19/09 06:58
Read: times


 
#162563 - Simple PWM to drive led
Hello, I want to make a simple PWM to drive a led. I need it when value is 0 the PWM output is all time 0, and when value is 255 the PWM output is all time 1.

Please, take a look in my code, I'm trying to figure out if it is making what I want.
Of course in later time I will modify to put it in the timer interrupt.


TL       EQU 078h
TH       EQU 079h
PWMPos   EQU 07Bh
PWMVal   EQU 07Ch


        MOV PWMVal,#0

Run:
        MOV TL,#0
        MOV TH,#10
        CALL Delay
        
        DEC PWMPos
        MOV A,PWMPos
        
        CJNE A,PWMVal,CEND
        JMP Run

CEND:   MOV P2.0,C
        JMP Run


Delay:  DJNZ TL,$
        MOV TL,#255
        DJNZ TH,Delay
        RET

END

 


Also, it is first time I work with PWM, even very fast, I know that the led is alwasy blinking, can I add something like a capacitor to make it a bit more smooth?


Thanks a lot!

List of 29 messages in thread
TopicAuthorDate
Simple PWM to drive led            01/01/70 00:00      
   Loop lasts too long!            01/01/70 00:00      
      I put the delay...            01/01/70 00:00      
         Did you see?            01/01/70 00:00      
            didnt noticed!            01/01/70 00:00      
               Ok, try the following...            01/01/70 00:00      
                  the JMP            01/01/70 00:00      
                     I thought this was your intention...            01/01/70 00:00      
   Another try            01/01/70 00:00      
   is possible to filter the pwm output...            01/01/70 00:00      
      PWM from a Timer interrupt?            01/01/70 00:00      
      questions            01/01/70 00:00      
   best code until now            01/01/70 00:00      
      read replies            01/01/70 00:00      
         will lower refresh rate            01/01/70 00:00      
            Time to switch...            01/01/70 00:00      
            Wrong.            01/01/70 00:00      
               my code is doing what I want            01/01/70 00:00      
                  TIming            01/01/70 00:00      
                     FOR NOW!!!!            01/01/70 00:00      
                        The old story...            01/01/70 00:00      
               DJNZ            01/01/70 00:00      
                  Dec            01/01/70 00:00      
                     Do nothing?            01/01/70 00:00      
                        Speed            01/01/70 00:00      
                           slowdown            01/01/70 00:00      
                              Chico            01/01/70 00:00      
                                 Not yet...            01/01/70 00:00      
                                    good catch            01/01/70 00:00      

Back to Subject List