Reply by Carsten July 7, 20052005-07-07
On Wed, 29 Jun 2005 12:43:08 +0200, "Antti Lukats"
<antti@openchip.org> wrote:

>"Sylvain Munaut" <com.246tNt@tnt> schrieb im Newsbeitrag >news:42c27a2c$0$29635$ba620e4c@news.skynet.be... >> >> Hi Antti, >> >> > >> > >> > if in hurry then you must either use TQFP100 package or BGA >> >> >> Finally I think I wont use PLD at all. >> A RC filter for "quick & dirty" pre-debounce and a simple 8bit &#4294967295;C >> to handle to rest of the logic will do. It doesn't need to be very >> fast anyway. >> >> >> Sylvain > >HAHA, that is good optimization!!!! from 500LE down to 0! >with proper firmware you may not need the external debounce but it all >depends sometime the rc network is good choice > >sure if there is no direct need for high speed logic then small flash micro >is better choice. > >my current favorite is ATmega8 in QFN32 package, but thats all a matter of >taste > >Antti >
Here is a neat debouncer for the Atmega's (It does 8 keys at a time , PORTD in this example) written for AVR-GCC / WinAVR Rgds Carsten /**************************************************************************** Title: Debouncing 8 Keys Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury, based on algorithm of Peter Dannegger <danni@specs.de> Date: December 2003 Software: AVR-GCC 3.3 Hardware: AT90S8515 at 4 Mhz, STK200 compatible starter kit Description: Demonstrates debouncing 8 keys. The state of the eight keys is sampled four times using a timer interrupt. If a key is pressed longer than four seconds, the corresponding bit in the key_press global variable is set. The main loop checks if a bit is set in this global variable and resets the bit. Pressing the key connected to PIND2 increments a counter, while pressing the key connected to PIND3 decrements the counter. The value of this counter is displayed using LEDs on PORTB. *****************************************************************************/ #include <inttypes.h> #include <avr/io.h> #include <avr/interrupt.h> #include <avr/signal.h> #ifndef CTC1 #define CTC1 WGM12 // for compatibility with ATmega #endif #define XTAL 4000000L // Crystal frequency in Hz #define DEBOUNCE 200L // debounce clock 200Hz = 5msec /* * Module global variable, informs the main programm when a key is pressed. * This variable must be declared 'volatile, since it is accessed from * both interrupt und main loop. */ static volatile uint8_t key_press; SIGNAL (SIG_OUTPUT_COMPARE1A) { static uint8_t key_state; // debounced and inverted key state: static uint8_t ct0, ct1; // holds two bit counter for each key uint8_t i; /* * read current state of keys (active-low), * clear corresponding bit in i when key has changed */ i = key_state ^ ~PIND; // key changed ? /* * ct0 and ct1 form a two bit counter for each key, * where ct0 holds LSB and ct1 holds MSB * After a key is pressed longer than four times the * sampling period, the corresponding bit in key_state is set */ ct0 = ~( ct0 & i ); // reset or count ct0 ct1 = (ct0 ^ ct1) & i; // reset or count ct1 i &= ct0 & ct1; // count until roll over ? key_state ^= i; // then toggle debounced state /* * To notify main program of pressed key, the correspondig bit * in global variable key_press is set. * The main loop needs to clear this bit */ key_press |= key_state & i; // 0->1: key press detect } int main( void ) { uint8_t count = 0; TCCR1B = _BV(CTC1) + _BV(CS10); // clear timer on compare match, no prescaler OCR1A = XTAL/DEBOUNCE; // timer = 5 msec TIMSK = _BV(OCIE1A); // enable Output Compare 1 overflow interrupt DDRB = 0x00; // use all pins on PortD for input PORTD = 0xff; // with pull-up enabled DDRB = 0xff; // use all pins on PortB for output PORTB = 0xff; // turn all LED off sei(); // enable interrupt for(;;) { if (key_press & _BV(2) ) { // key 2 pressed, increment counter count++; PORTB = ~count; key_press = 0; } else if ( key_press & _BV(3) ) { // key 3 pressed, decrement counter count--; PORTB = ~count; key_press = 0; } } }
Reply by jai....@gmail.com June 30, 20052005-06-30
Why not a small microcontroller like a PIC 10F series?

Reply by Thomas Stanka June 30, 20052005-06-30
Sylvain Munaut <com.246tNt@tnt> wrote:
> I'd like to find a really small FPGA that I could solder by hand, > like in a VQ44 or VQ64 package. Ideally, it should only require a > single 3.3v supply, but a dual supply core/io would be OK too if > really necessary.
Actel has the A1010B in CQ84. I don't think there are smaller packages left on market. Backdraw is the high price, and the fpga is only one time programmable. The fpga needs also 5V. And 500LE migth be far more logic than the a1020 provides. If you come to numbers >1000 you could Ask actel for the a54sx in the same package. The A54Sx come along with 3.3V. If your requirement small is only because of hand soldering, you could also look at other packages with 0.5 pin pitch like PQ and TQ. bye thomas
Reply by Peter Alfke June 29, 20052005-06-29
If you need to debounce 8 switches, you might want to use a common
anti-bounce delay cicuit.
Accept any activation of any key, but immediately start a delay circuit
that ignores all key level changes.  That should suppress the bounce.
Peter Alfke

Reply by Jim Granville June 29, 20052005-06-29
Sylvain Munaut wrote:
> Falk Brunner wrote: > >>"Sylvain Munaut" <com.246tNt@tnt> schrieb im Newsbeitrag >>news:42c27017$0$23344$ba620e4c@news.skynet.be... >> >> >> >>>Yes, indeed my "style" is more based on FPGA experience. >>>What would be the "CPLD" way to code a debouncer ? >> >> >>A counter and some logic will do. CPLD or FPGA doesnt matter here. >> >>Regarads >>Falk > > > The problem is that I need 8 of them + some other stuff, > the debouncers fits but uses most of the 72 macrocells and the price > goes high quickly for more macrocells.
Then use less :) A debounce really just needs to remove the unwanted edges, so you do not need many macrocells/key. ie Slower clock, and fewer MC is another way. -jg
Reply by Falk Brunner June 29, 20052005-06-29
"Sylvain Munaut" <com.246tNt@tnt> schrieb im Newsbeitrag
news:42c2cdce$0$337$ba620e4c@news.skynet.be...

> The problem is that I need 8 of them + some other stuff, > the debouncers fits but uses most of the 72 macrocells and the price > goes high quickly for more macrocells.
I assume the debouncers are for push buttons? This can be easyly handled in a microcontroller. And this is also very cheap. Regards Falk
Reply by Sylvain Munaut June 29, 20052005-06-29
Falk Brunner wrote:
> "Sylvain Munaut" <com.246tNt@tnt> schrieb im Newsbeitrag > news:42c27017$0$23344$ba620e4c@news.skynet.be... > > >>Yes, indeed my "style" is more based on FPGA experience. >>What would be the "CPLD" way to code a debouncer ? > > > A counter and some logic will do. CPLD or FPGA doesnt matter here. > > Regarads > Falk
The problem is that I need 8 of them + some other stuff, the debouncers fits but uses most of the 72 macrocells and the price goes high quickly for more macrocells. Sylvain
Reply by Falk Brunner June 29, 20052005-06-29
"Sylvain Munaut" <com.246tNt@tnt> schrieb im Newsbeitrag
news:42c27017$0$23344$ba620e4c@news.skynet.be...

> Yes, indeed my "style" is more based on FPGA experience. > What would be the "CPLD" way to code a debouncer ?
A counter and some logic will do. CPLD or FPGA doesnt matter here. Regarads Falk
Reply by Antti Lukats June 29, 20052005-06-29
"Sylvain Munaut" <com.246tNt@tnt> schrieb im Newsbeitrag
news:42c27a2c$0$29635$ba620e4c@news.skynet.be...
> > Hi Antti, > > > > > > > if in hurry then you must either use TQFP100 package or BGA > > > Finally I think I wont use PLD at all. > A RC filter for "quick & dirty" pre-debounce and a simple 8bit &#4294967295;C > to handle to rest of the logic will do. It doesn't need to be very > fast anyway. > > > Sylvain
HAHA, that is good optimization!!!! from 500LE down to 0! with proper firmware you may not need the external debounce but it all depends sometime the rc network is good choice sure if there is no direct need for high speed logic then small flash micro is better choice. my current favorite is ATmega8 in QFN32 package, but thats all a matter of taste Antti
Reply by Sylvain Munaut June 29, 20052005-06-29
Hi Antti,

> > > if in hurry then you must either use TQFP100 package or BGA
Finally I think I wont use PLD at all. A RC filter for "quick & dirty" pre-debounce and a simple 8bit &#4294967295;C to handle to rest of the logic will do. It doesn't need to be very fast anyway. Sylvain