Hasan Khan wrote: > Thanks to everyone who gave advice. I have the following options now. > - Switch to F628 use CCP for triac gate pulses and use the left over > cycles for debounce and other chores. > - Spread debounce over multiple ISR calls. > - Use vertical counter algorithm. > - use register rotation method ( i haven't found out exactly what that > is). Hasan, I have just finished writing a tutorial introducing interrupts on midrange PICs (such as the 16F628, although a 12F629 is used in the examples): http://www.gooligum.com.au/tutorials/midrange/PIC_Mid_A_6.pdf It includes a section on using a timer interrupt to debounce a single switch (multiple ISR calls, each samples the switch, sets a "switch changed" flag and updates "current debounced state" variable when the same new state has been seen some number of times in a row). Not as elegant as vertical counters and register rotation (which is in fact a way of counting - it's essentially the same algorithm - it's explained in one of Ganssle's debouncing papers) - but my intent was to show how interrupts could be used to re-implement the debounce algorithm I'd introduced before - and it actually works very well. So - hopefully of some use to you with your option 2! David Meiklejohn www.gooligum.com.au > -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On > Behalf Of > Sent: Monday, 29 December 2008 5:27 PM > To: Microcontroller discussion list - Public. > Subject: Re: [PIC] How to do switch debounce quick enough > > > For now I am going to experiment with the first two and see how that > goes. I didn't check at the time but more featured F628 is actually > cheaper than very basic and old F84. Depending on time, I will explore > the other options too. > > Coming from big software engineering (Java, C++) back ground, I long to > use > C. But I will stick to advice given on this forum else where and stick > to assembler. This will be my third and last project in assembler and > then I am going to switch to C no matter what you say...yeah! :-) > > -Hasan > > > > ----- Original Message ---- > > From: Hasan Khan > > > > 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. > > > -- > 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