I would try connecting a pulse generator to the keypad input and send it a single pulse. At least this will help narrow it down to either a SW or HW issue.
And unless you can always distinguish expected ISR blinking from BADISR blinking, I would not have the BADISR blink. It could be getting called unexpectedly. I thought Todd's suggestion would have nailed it for sure... And David is right you don't need the reti(); it is only used when writing a naked ISR. Who knows what evil is lurking in the stack on a premature return. -mark On Tue, 14 Jan 2014 18:37:54 +0100 dfx <d...@dfx.it> wrote: > Todd thank you very much for your contribution. > > I added this line to the bottom of the ISR: > > PCIFR | = (1 << PCIF3); > > and I have also added a 10 uF capacitor to remove any possibility of > bouncing (... and seeing the signals to the oscilloscope are very clean > and exactly as expected). > > The behavior remained absolutely identical. :-( > > I can not use a polling technique for reasons of timing, and even a > software debouncing (negate the advantages of the ISR). > > To me it remains unclear why exactly does two flashes on press and on > release the other two flashes (Why not sometime a single 1 or 3?) for a > total of 4 flashes instead of just one. > > Thanks again > > Domenico > > Il 14/01/2014 18:02, Todd Batzler ha scritto: > > You're in that isr a long time. The isr bit that got set that resulted in > > the vector to your isr probably gets cleared upon entry to the isr, but > > could get set again due to switch bounce. Try clearing the ISR pending > > flag for that ISR before returning. > > > > Todd G. Batzler > > Sr Staff Engineer > > Technology Development > > > > Miller Electric Mfg. Co. An ITW Company > > 1635 West Spencer St. > > P.O. Box 1079 > > Appleton, WI 54912-1079 > > 920-735-4230 Office > > 920-735-4488 Fax > > todd.batz...@millerwelds.com > > www.millerwelds.com > > Please consider the environment before printing this email. > > > > -----Original Message----- > > From: avr-gcc-list-bounces+tbatzl=millerwelds....@nongnu.org > > [mailto:avr-gcc-list-bounces+tbatzl=millerwelds....@nongnu.org] On Behalf > > Of dfx > > Sent: Tuesday, January 14, 2014 10:54 AM > > To: avr-gcc-list@nongnu.org > > Subject: [avr-gcc-list] Simple but wrong code > > > > Please consider this code: > > > > #define KEY_PORT PORTD > > #define KEY_DDR DDRD > > #define KEY_FUNC_SEL PIND4 // --> first key (Port D pin 4) .... > > #define LED_PORT PORTB // Test led, to see action on keypress .... > > > > #define FUNC_SEL_KEY 0x10 // First function --> first key (Port D pin 4) > > .... > > > > int main() { > > init(); > > > > while (1) { > > // waits indefinitely for keypress > > } > > return (EXIT_SUCCESS); // Never reached } > > > > void init() { > > cli(); > > LED_DDR |= (1 << DDB0); // Led out Port B pin 0 > > > > KEY_PORT |= (1 << PORTD4) ; // pull-up resistor > > PCICR |= (1 << PCIE3); // Enable interrupts on PORTD (PCINT31:24) > > > > PCMSK0 = 0X00; // Disable unnecessary > > PCMSK1 = 0X00; > > PCMSK2 = 0X00; > > PCMSK3 |= (1 << PCINT28); // Enable key > > sei(); > > } > > > > ISR(PCINT3_vect) { // FUNCTION KEY > > uint8_t i; > > > > i = PORTD; > > if ((i & FUNC_SEL_KEY) > 0) { // Test a key > > LED_PORT |= (1 << PORTB0); > > _delay_ms(100); > > LED_PORT &= ~(1 << PORTB0); > > _delay_ms(300); > > } > > reti(); > > } > > > > > > ISR(BADISR_vect) { > > LED_PORT |= (1 << PORTB0); > > _delay_ms(200); > > LED_PORT &= ~(1 << PORTB0); > > _delay_ms(200); > > LED_PORT |= (1 << PORTB0); > > _delay_ms(200); > > LED_PORT &= ~(1 << PORTB0); > > _delay_ms(200); > > LED_PORT |= (1 << PORTB0); > > _delay_ms(200); > > LED_PORT &= ~(1 << PORTB0); > > _delay_ms(200); > > reti(); > > } > > > > the button has a capacitor 1uF for debouncing (together with the pull-up > > from 10 kohm) > > > > The result is the following: > > > > when I press the button, are generated two flashes (instead of one), > > and when I release the button are generated two more flashes. > > > > Similarly, If I comment out the routine (ISR PCINT3_vect), > > the error routine (ISR BADISR_vect) generates double of the expected > > flashes. > > > > Can anyone help me to understand the problem? > > > > Thank you very much. > > > > > > -- > > Domenico > > > > > > > > --- > > Questa e-mail è priva di virus e malware perché è attiva la protezione > > avast! Antivirus. > > http://www.avast.com > > > > This message (including any attachments) is intended for the sole use of > > the intended recipient/s and may contain material that is CONFIDENTIAL AND > > PRIVATE COMPANY INFORMATION. If you are not the intended recipient of this > > message, you are hereby notified that you must delete the message without > > disseminating, copying or taking any action in reliance upon it. If you > > have received this message in error, please notify the sender via return > > e-mail. Thank you. > > > > --- > Questa e-mail è priva di virus e malware perché è attiva la protezione avast! > Antivirus. > http://www.avast.com _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org https://lists.nongnu.org/mailman/listinfo/avr-gcc-list