hello everyone, I am trying to do a PWM with a few leds connected to PortB and have a switch that is connected to one of the pin in PortC. I want to halt the design when I pressed the switch once.

I have the following in my code.
But I have to press the switch twice for the PWM to stop and twice for the PWM to continue. but I only want to halt the design when I press the switch once. I have set the flag = 1 at the top of my program... and when the switch is pressed I clear the flag.. any help on this will be greatly appreciated. Many thanks in advance

srigopal



==============================================
Flag = 1
For Duty = 0 to 999

If Switch = 0 Then
Flag = ~Flag

Endif

if(Flag = 0) then
Duty = Duty - 1
Endif
Flag = 1

For cycles = 0 to Cycle1
Portb = %00000000
Pauseus 999 - Duty
Portb = %00000010
Pauseus Duty
Next cycles

Next Duty