yankee
- 8th April 2009, 21:13
I'm using a very good quality normally open switch to change HPWM for an array of LEDs. This switch has some sort of compound action where the contacts snap closed when the button is pressed. A lot of times I press the switch and nothing happens. I've played with the pause time in the code and changed it to different settings from 1 ms to 100 ms, but it doesn't seem to make much difference. Is there are more reliable code for a switch like this? Here's the code:
~ Dave
@ device pic16F628A, INTRC_OSC_NOCLKOUT, wdt_off, mclr_off, lvp_off, protect_off
CMCON = 7
CounterA Var Byte
CounterA=0
start:
HPWM 1,64,2000 ' hardware pulse width modulate channel 1, 25% duty, 2khz
goto Main
Main:
If PORTA.1=0 then
If CounterA<=1 then
CounterA=CounterA+1
else
CounterA=0
endif
endif
While PORTA.1=0 : Wend : pause 10
BRANCHL CounterA,[LabelOne,LabelTwo]
Goto Main
LabelOne:
HPWM 1,64,2000 ' hardware pulse width modulate channel 1, 25% duty, 2khz
goto Main
LabelTwo:
HPWM 1,254,2000 ' hardware pulse width modulate channel 1, 99.6% duty, 2khz
goto Main
~ Dave
@ device pic16F628A, INTRC_OSC_NOCLKOUT, wdt_off, mclr_off, lvp_off, protect_off
CMCON = 7
CounterA Var Byte
CounterA=0
start:
HPWM 1,64,2000 ' hardware pulse width modulate channel 1, 25% duty, 2khz
goto Main
Main:
If PORTA.1=0 then
If CounterA<=1 then
CounterA=CounterA+1
else
CounterA=0
endif
endif
While PORTA.1=0 : Wend : pause 10
BRANCHL CounterA,[LabelOne,LabelTwo]
Goto Main
LabelOne:
HPWM 1,64,2000 ' hardware pulse width modulate channel 1, 25% duty, 2khz
goto Main
LabelTwo:
HPWM 1,254,2000 ' hardware pulse width modulate channel 1, 99.6% duty, 2khz
goto Main