10f200 debouncing and a new compiler

I’ve noticed some people doing search terms for debouncing and I figured I would post my method of debouncing inputs from switches. Some people have a big thing with using caps and resistors and gates with hysteresis but I prefer to simply use a cheap microcontroller because the result is programmable, MCU’s are cheap and there are fewer parts than the usual arrangements. Here is a crude circuit diagram of the debouncer. for this circuit the arrangement is (Input GP3 -> Output GP1)(Input GP2 -> Output GP0)

The problem with some other MCU methods is that people often try checking every 5ms to see if two successive input were high. This is a faulty approach since it can be computationally wasteful and can still produce noise. My approach is as follows:

  1. read the input on a loop
  2. if the input is high, increment a counter up to a certain maximum (say 90)
  3. if the counter goes above a certain amount (say 60) then turn on the output
  4. if the input is low, decrement the counter until it reaches 0
  5. if the counter goes below a certain amount (say 30) then turn off the output
  6. Don’t change the value of the output between 30 and 60

What this does is ensures that there is an area of hysteresis where the noise or bounce of the switch will not generate noise on the output. You can play with the rules to suit your specific need and improve responsiveness or make the output resilient to accidental triggering. This is the reason why for some more important things I have used this method. I have used a pic16f505 for this purpose as well with larger arrays of buttons. Having a programmed method that you can change easily can give you an easy ‘jellybean’ solution for these kinds of problems. Mind you of course when dealing with switches in high noise environments you may need to optoisolate or run TVSs on the switch.

If you’ve read any of my other posts you’ll know that I like the PIC10F200 MCUs simply because of their simplicity and the fact that a lot of people write them off as useless. This design is pretty crude as you can see and that leads me into the topic of the compiler. First,  here is a sample hex file for debouncing – debounce. This hex is programmed to premit a pressed switch to activate after 11ms.

I recently bought a suite of compilers from OshonSoft since I drifted over there out of pure chance. This company is a one man show who sells a variety of BASIC compilers for PIC, Z80 and 8085 processors. I tried the 10f compiler and was immediately impressed with how, for so inexpensively, there was a useful tool for simulation and programming.

I’ve only used the 10f compiler so far but it beats the tar out of PicBASIC Pro, as far as I can tell thus far. Not a lot of frills or gimmicks but it outputs very tight code. Here’s the source for the debouncer pic10f200. You can download a demo version of the 10f simulator at his website.

debouncesrc.zip

Well, anyways, that’s my little treatise on the subject. Also, for those of you on a tight budget and just getting into microcontrollers, Oshonsoft might be a good place to buy a compiler that’s reasonably simple.