Re: how to connect button to external interrputs of an AVR?

the problem with your design is that what is the voltage at the Int0 pin when the switch is open? It's not connected to anything so there's no telling if the voltage is high enough to not cause a reset.

Reply to
Gary Kato
Loading thread data ...

and the pin may not have current limiting appropriate to the design. Easier to use two resistors, one for current limit (the one connectoed to the pin), and one to make a pull up (the one connectoed to vdd/vcc) than to have to change the chip for problems associated.

Andrew

Gary Kato wrote:

Reply to
Andrew Paule

you could use the on chip pull ups too. Just connect the button to the pin and the other end to ground and presto. (But make sure you enable the pullup in the software!)

int0 -------/(switch!)/------ GND

Reply to
Brett

When the button is released in this diagram, the voltage potential on the pin doesn't necessarily become ground. It 'floats' up and down, and can be influenced by nearby signals, noise, etc, causing false triggers and other problems. This is fixed with a resistor on the MCU pin that bleeds off the voltage to ground. The lower the value, the faster the transition (and the greater the power draw when the button is pressed).

The AVR series have pull-ups in the MCU (that raise the potential to Vcc), so I'm curious why the AVRfreaks example is suggesting an external pull-up. Maybe for simplicity of the tutorial? It'd be worth asking them.

For inputs, I've seen inline resistors recommended more in the context of protecting against static discharge from the user's finger. For outputs they're needed to keep the LED, etc. from drawing too much current from the MCU. Or perhaps as a precaution against you accidentally enabling the port as an output and then pressing the button.

For a simple experimenter, you could get by with just the external pushbutton to ground, by using the internal MCU pull-up. In the AVR, it's a matter of writing a value to the port register when it's in input mode. The 8515 datasheet explains it in detail.

'Debouncing' is a topic you may want to read up on. Your ISR won't fire just when the button is released (on the rising edge) - it'll fire many times for one button push.

Reply to
Richard

See the 8515 Datasheet under I/O ports (page 62 in my copy). When the port is in input mode, you write a 1 value to the pin via the output port.

Note: you write this to the *output* port address (e.g., PORTD), not the input pin register (PIND).

Reply to
Richard

The first and second examples have a pullup resistor so that when the switch is open, the input is pulled to a known high state. This might or might not be mandatory depending on the characteristics of the pin.

The first example also has a current-limiting resistor to reduce power consumption when the switch is closed. This would also provide some sanity-checking against, for instance, code that has configured the pin as an open-source LOW output.

Reply to
Lewin A.R.W. Edwards

This circuit is likely to produce multiple interrupts due to the pushbutton ringing. The good way to avoid it will be disabling interrupts for about 50msec after the very first interrupt. Vladimir Vassilevsky, Ph.D.

DSP and Mixed Signal Design Consultant

formatting link

Brett wrote:

Reply to
Vladimir Vassilevsky

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.