![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hi! I’m working with a simple delay loop that can generate a PWM part (without a PWM module).
My target is to fade a LED smoothly. I have a pair of tested values. By loading one of these values & call Main routine it will show the LED dim or full brightness. What I need is to change DIM values to BRIGHT values nicely (linear) to make the LED fade. Any method greatly appreciated. Thanks Code:
LED is very DIM by loading these values ;DIM movlw .255 ; movwf SaveONtime ; movlw .1 ; movwf saveONcount ; movlw .1 ; movwf SaveOFFtime ; movlw .40 ; movwf saveOFFcount LED is fully BRIGHT by loading these values ;BRIGHT movlw .1 ; movwf SaveONtime ; movlw .40 ; movwf saveONcount ; movlw .255 ; movwf SaveOFFtime ; movlw .1 ; movwf saveOFFcount Main call ON call OFF goto Main ON movlw 0xff ;turn on leds movwf PORTB movf SaveONtime,W movwf ONtime movf saveONcount,W movwf ONcount loopON incfsz ONtime,F ;count up the on time goto loopON decfsz ONcount,F goto $-3 return OFF movlw 0x00 ;turn off leds movwf PORTB movf SaveOFFtime,W movwf OFFtime movf saveOFFcount,W movwf OFFcount loopOFF incfsz OFFtime,F ;count up the off time goto loopOFF decfsz OFFcount,F goto $-3 return |
|
|
|
|
|
|
(permalink) |
|
Try something like this. Timer 2 is good for generating the interrupt which takes care of the PWM. Then gradually change the value of ledPwm variable from 0x00 (led off) to 0xFF (led 100% on) to fade the LED.
Code:
; define variables
;
cblock 0x20
ledPwm ; LED PWM value
pwmCntr ; PWM 'ramp' counter
pwmWkg ; working variable
endc
; call this from a timer driven interrupt
; every 40uS for 98Hz refresh.
_pwm incfsz pwmCntr,F
goto _noRollover
_resetPWM incf pwmCntr,F
movfw ledPwm
movwf pwmWkg
incfsz pwmWkg,W
bcf PORTA, LED
_noRollover incf pwmWkg,f
skpnz
bsf PORTA, LED
; exit ISR here
; ---------------------------------------
_loop ; software fade delay code here
incf ledPwm,F
incfsz ledPwm,W
goto _loop
; stop when ledPWM == 0xFF
Last edited by geko; 3rd December 2007 at 09:55 AM. |
|
|
|
|
|
|
(permalink) |
|
Thanks geko I'll try your coding I'm working hard with my coding to get a smooth fade but I couldn't.
Now I'll check with your one. Thanks for the help. |
|
|
|
|
|
|
(permalink) |
|
Maybe this is smooth enough?
http://www.youtube.com/watch?v=isftM5mUqRU And this is multi-smooth: http://www.youtube.com/watch?v=aeHFavqIe7U |
|
|
|
|
|
|
(permalink) | |
|
Quote:
Do you have any coding ideas to share? |
||
|
|
|
|
|
(permalink) |
|
|
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Keil C problem | sarang1_in | Micro Controllers | 3 | 27th February 2005 05:05 AM |
| Problem; Random pic performance | timothyjackson | Micro Controllers | 7 | 19th February 2005 06:19 PM |
| Big problem!! | zezito | Electronic Projects Design/Ideas/Reviews | 4 | 29th October 2004 02:05 AM |
| Analog output PLC CQM1H problem | goekgoek | General Electronics Chat | 0 | 24th June 2003 08:07 AM |
| Ballast / Igniter Problem | O B 1 KNooB | Electronic Projects Design/Ideas/Reviews | 1 | 6th March 2003 09:22 PM |