Hasan, Maybe you could change from the F84 to the F628. Then you could use the H/W PWM. If you are using a H/W PWM, the CCP unit will retain it's setting until it is changed. So you could deboune the switch over 2-3 cycles, then update. The cost of this part is typically less than the F84 too, so you could save a few cents per unit. And it's pin for pin compatible I believe too. Jim ----- Original Message ----- From: "Hasan Khan" To: "PIC List" Sent: Friday, December 26, 2008 12:31 PM Subject: [PIC] How to do switch debounce quick enough > Hi, > Well, I am finally moving from hobby to pro zone. I got a simple project > where I have to design a triac based ac power controller with two push > buttons, one to increase power to triac and one to decrease power. Power > level is displayed on a single 7-seg display. > > Hardware design is based on 16F84 because they are available dirt cheap > here. Timing of the circuit it based around zero crossings which at 50 Hz > happens at every 10ms. I have an ISR that does the following every zero > crossing. > - pulse triac gate at set time delay > - read and act on button state > - display power level on the display > > These steps can be done easily in 10ms except that doing software based > switch debouncing needs longer than 20ms (10ms for switch down, 10ms for > switch up). This results in ISR being called while still reading switches > and ISR calls switch reading routine again and therefore I have recursion > and a quick stack overflow error. > > How do I do switch debouncing here? Will a reduced debounce time of 8ms > work? Is there a better software design? > > PS: The whole project is in simulation stage and no breadboarding done > yet. Small size and low cost are important considerations so I can't do > hardware debouncing. > > Thanks for your help. > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist