At 08:06 1998-10-28 -0800, you wrote: >Brace yourself for a newbie electronics question: > >I need to make a push button "toggle": push goes high, next push goes >low, and so on. In effect I need to "store" button presses: the PIC will >be polling for them, but I can't use interrupts and can't guarantee the >polling frequency. The button is a N.O. one, SPST. I also need to >debounce, of course. > >I know I can get this with some cross-coupled gates (for debounce) and a >flip flop (divide by two, basically) but I'm hoping there's a simpler >(read: fewer components) way to do this. Are there ICs with this sort of >function? Or some other cool way to pull (push?) this off? > >Thanks, > >Dave Johnson > YES Just two inverters, two R, and a C ! (preferrably CMOS inverters, 4069 or 74HC04 etc) Connect the inverters in series, with the second output to PIC input, and through a 1k-10k resistor back to the first inverter input. * Thus we made a bistable latch, which we can set as we want by short pulses * Connect a resistor R2 from the connection between the inverters to C1, a 10n to 1µF cap, other cap end to GND. R2= approx 5 x R1 * Thus the cap will hold the opposite state of output (=currently the input) * Connect the pushbutton between that cap and first inverter input. Push, and the opposite state will be induced. * Got it ? * :) By higher R2 and C1 values we can set the minimum accepted time between button pushes. * This superseeds "debounce" function. * (hope I am not wrong here...) Extra 1 If the button is located outside encapsulation: Add a RCR "pi" filter between button and inverter input. Both R= R1/10, C = C1/10 This will take care of both EMI and some ESD. For higher ESD protection add a Zener over this C. Extra 2 Add a 220 ohm R directly in series with the second inverter output. Thus, by making the PIC pin an output, the PIC can set the state as desired! (useful to guarantee the right power up state!) If the inverter is 4069 (etc) is possible even withput the R (CMOS are weak). Extra 3 Indication by a LED through an R preferrably connected from the connection between inverters (because of "Extra 2") For the inverters to cope, use HC type, (or AC types for high current), or make a driver from parallelling unused gates. Extra 4 If R1 = 10 x R2, and inverters (at least the first) are schmidt trigger (40106 or HC14) the cirquit will oscillate when pressing button, then stop high or low when button released. (Sure somebody might find it useful for something...?) Tip: There is a logic buffer (forgot its number) containing four buffers with both inverting and noninvering output on each gate. = one gate per toggle cirquit, four per IC. Regards /Morgan Morgan Olsson ph +46(0)414 70741 MORGANS REGLERTEKNIK fax +46(0)414 70331 H€LLEKS (in A-Z letters: "HALLEKAS") SE-277 35 KIVIK, SWEDEN mrt@iname.com ______________________________________________________________