Hi I need to light up three LEDs with three brightness levels.
I have written a code with software loops.
Problem is I can see a small flickering in all three LEDs.
Can anybody help me to improve my looping system to make it smoother?
(Note: I’ve used 255 steps.
Ex: If I need to dim half then LED must turn on 128 times & the other 128 time must off the LED)
I need to do this with software loops not with PWM modules.
I use 16F628A with 4Mhz
I have written a code with software loops.
Problem is I can see a small flickering in all three LEDs.
Can anybody help me to improve my looping system to make it smoother?
(Note: I’ve used 255 steps.
Ex: If I need to dim half then LED must turn on 128 times & the other 128 time must off the LED)
I need to do this with software loops not with PWM modules.
I use 16F628A with 4Mhz
Code:
Start clrf OFFtime ;OFFtime = space time bits
movlw .200 ;more bright
movwf S_CH1
movwf CH1
movlw .50 ;less bright
movwf S_CH2
movwf CH2
movlw .10 ;very dim
movwf S_CH3
movwf CH3
;********************************************************************************
;Do channel one
;********************************************************************************
L4_Do_CH1 btfsc OFFtime,1 ;is it mark or space?
goto L4_CH1_OFF ;it is space
L4_CH1_ON bsf PORTB,0 ;it is mark then turn on RB0
decfsz CH1,F
goto L4_Do_CH2
bsf OFFtime,1
movf S_CH1,W ;get the bakup brightness value
movwf CH1
L4_CH1_OFF bcf PORTB,0 ;turn off RB0
incfsz CH1,F
goto L4_Do_CH2
bcf OFFtime,1 ;turn off off time
movf S_CH1,W ;load backup value for next turn
movwf CH1
;********************************************************************************
;Do channel two
;********************************************************************************
L4_Do_CH2 btfsc OFFtime,2 ;is it mark or space?
goto L4_CH2_OFF ;it is space
L4_CH2_ON bsf PORTB,1 ;it is mark then turn on RB1
decfsz CH2,F
goto L4_Do_CH4
bsf OFFtime,2
movf S_CH2,W ;get the bakup brightness value
movwf CH2
L4_CH2_OFF bcf PORTB,1 ;turn off RB1
incfsz CH2,F
goto L4_Do_CH3
bcf OFFtime,2 ;turn off off time
movf S_CH2,W ;load backup value for next turn
movwf CH2
;********************************************************************************
;Do channel three
;********************************************************************************
L4_Do_CH3 btfsc OFFtime,3 ;is it mark or space?
goto L4_CH3_OFF ;it is space
L4_CH3_ON bsf PORTB,2 ;it is mark then turn on RB2
decfsz CH3,F
goto L4_Do_CH1
bsf OFFtime,3
movf S_CH3,W ;get the bakup brightness value
movwf CH3
L4_CH3_OFF bcf PORTB,2 ;turn off RB2
incfsz CH3,F
goto L4_Do_CH1
bcf OFFtime,3 ;turn off off time
movf S_CH3,W ;load backup value for next turn
movwf CH3
goto L4_Do_CH1