Hello Folks, I have been working on this for quite a while now and am not getting the results that I wanted to acheive. I am using a a few switches to control the sequence of LEDs through PWM. I have pasted my code here ... Hope someone can help me find the solution to this.
==============Code starts here===================
start:
'Values of Variables being used
Cycle1 = 2
Save = 0
'start of sequence
For Duty = 0 to 2000 'All OFF ---> BLUE
If(Stop_Switch = 0) Then Flag1 = 1 'Set FLAG to Zero because Ext. Int. Occurred
if(Flag1 = 1) then
Duty = Duty - 1 'PAUSE PWM actually occurs here
'jumping to subroutines
if(INC_BRIGHT = 0) then GoSub INCREASE_BRIGHT 'bright switch
endif
if(Resume_Switch = 0) && (Stop_Switch = 1) then 'if resume switch is pressed then return back and continue
Flag1 = 0 'Since Pausing is no longer performing, Flag is refreshed back to 1
Endif 'to resume PWM where it was left off
For cycles = 0 to Cycle1 'if Nothing is pressed then Perform normal PWM sequence
Portb = %00000000
Pauseus 2000 - Duty
Portb = %11100000
Pauseus Duty
Next cycles
Next Duty
'start of subroutine
INCREASE_BRIGHT:
While(INC_BRIGHT = 0)
if(Save = 0) then 'making sure whether INCreasing or DECreasing
'Global Brightness switch is pressed first
A = 0 'if Increasing switch is pressed first then start
'with initial values
else 'OtherWise
A = Save 'if the Decrease global Switch is pressed first, then
'start with the values stored in the variable SAVE
Endif 'ending the condition loop
For i = A to 100 'if increasing switch is pressed continuously then
PortB.4 = 0 'Normal PWM
Pauseus 100 - i
PortB.4 = 1
Pauseus i
Save = i 'saving the value of the PWM state just incase the DEC-GlOB is pressed
if(INC_BRIGHT = 1) && (DEC_GLOB_BRIGHT_SWITCH = 1) then 'if button is let go then return
Return
endif
Next i 'if switch is kept pressed then proceed to next increment
Wend
==============================================
I am performing a simple software pwm with three leds connected to PORTB.7, PORTB.6, and PORTB.5 ... Here is what I want to do with the code I have attached above. When the increase brightness switch is pressed (at random) I want the brightness to change without noticing the flickering. I notice that once the code jumps into the subroutine the LEDs become full brightness, and does not stay at a random (PWM VALUE) this is because the last thing that is executed in the main loop is
PORTB = %11100000 this keeps the three LEDs full brightness.
For example lets say that the button is pressed when all of the three LEDS are 40% ON. and for the amount of time the button is pressed, the leds increases in brightness. How do I prevent the behavior I see from my code. Any help on this would be greatly appreciated. many Thanks in advance
srigopal
Bookmarks