Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Paul E Bennett Newsgroups: comp.arch.embedded Subject: Re: Counting 2ms long pulses on several input pins Date: Tue, 24 Sep 2013 11:15:50 +0100 Organization: Hidecs Consultancy Lines: 59 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: individual.net aAL7oC6abt7Y/uWLWi5iJwfKxfewj/jcPd0fYamLqBu0d+E1wd Cancel-Lock: sha1:+FuYEmF3J6fz0diME69gUPwZtFc= User-Agent: KNode/4.10.5 Xref: csiph.com comp.arch.embedded:13851 pozz wrote: > I have a 5 microswitches > (www.tamiyausa.com/images/product/470/75016/header_75016.jpg) connected > to some inputs of a microcontroller. The switches are normally closed > and put the level to low. When they are open, the level is high thanks > to pull-up resistors. > > I have to count the pulses generated from the microswitches. They are > managed by a rotating cam (en.wikipedia.org/wiki/Cam) that push/release > continuously the switches. > > The rotation speed could change. When it is slow, the complete pulse > width could be up to 15-20ms, where the last part (about 3-5ms) is > composed by many bouncing oscillations. > When the rotation is fast, the complete pulse width is about 1-2ms and > the boucing oscillations takes about 2-3ms. > > What is the best approach/algorithm to debounce and detect/count pulses > on all the lines, without stressing the microcontroller too much? > > My approach is to sample each input lines every 1ms in the ISR of a > timr. Usually it is at low level. When I see the first 1, I increase > the counter and change to HIGH status. Now I have to see two > consecutives 0 to go back to LOW status. > > Do you have better ideas? There is insufficient information here to determine:- 1. Is the use of mechanical switches adequate to the task being undertaken. 2. The best de-bounce method (in either hardare or software) that should be employed. 3. Whether polling or edge triggered inturrupts are the best strategy. So Pozz, a simple test on which you should then report the results here. Mount one of the switches as intended and strap it into a circuit configuration that will resemble the input circuit you are using. Attach a scope across the points where the input would be taken and set the trigger to capture the resultant input. Rotate the cam-shaft over the full range of rates you expect it to operate at and report the results in the form of shoing us the scope traces (on a link) or tabulated as figures relating how long the contacts bounce for at what speed. Of course, once you have done this you may discover your own answer to your problem. Either ay I think the other responders and myself will be interested in your findings. -- ******************************************************************** Paul E. Bennett IEng MIET..... Forth based HIDECS Consultancy............. Mob: +44 (0)7811-639972 Tel: +44 (0)1235-510979 Going Forth Safely ..... EBA. www.electric-boat-association.org.uk.. ********************************************************************