Hi srigopal,
There are quite a few ways to do this. Here's one. This version just stops your PWM change.
And if you want to stop PWM altogether, then a slight change in this routine would do it for you.Code:Stop_Switch VAR PORTC.0 ' Whatever pin you prefer Go_Switch VAR PORTC.1 ' Whatever pin you prefer Duty VAR WORD ' Duty cycle LowCycle VAR WORD ' Low cycle HighCycle VAR WORD ' High cycle Period VAR WORD ' Frequency period Cycles VAR WORD ' Active VAR BIT ' Active/Inactive flag bit YEP CON 1 ' PWM will be Active NOPE CON 0 ' PWM will not be Active End_Cycles CON 500 ' Increase value to slow PWM duty cycle change Active = YEP ' PWM defaults to Active TRISC = %00000011 ' Make em inputs TRISB = 0 ' All outs Period = 500 ' Set frequency here. 500 = ~1.983kHz ' 250 = ~3.825kHz, etc, Duty = 250 ' Set whatever you prefer here to start with ' 250 = ~50% (1/2 of period) Main: IF Go_Switch = 0 THEN ' Go_Switch pressed? Active = YEP ' Yes, toggle flag bit ENDIF IF Stop_Switch = 0 THEN ' Stop_Switch pressed? Active = NOPE ' Yes. toggle flag bit ENDIF IF Active = YEP THEN IF Duty < Period THEN Duty = Duty + 1 ELSE Duty = 0 ' Limit Duty from 0 to 100% ENDIF ENDIF ' Compute high & low cycles of Period LowCycle = Period - Duty HighCycle = Period - LowCycle For Cycles = 0 to End_Cycles Portb = %00000000 Pauseus LowCycle Portb = %00000001 Pauseus HighCycle Next Cycles GOTO MainOf course there are many other ways to do this, but this gives you a good idea of at least 1 way.Code:IF Active = YEP THEN For Cycles = 0 to End_Cycles Portb = %00000000 Pauseus LowCycle Portb = %00000001 Pauseus HighCycle Next Cycles ENDIF




Bookmarks