XMEGA32D3 Interrupt Mask Not Working

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I have run into a bug that I just can't seem to fix. I have 2 switches configured with pullups/falling edge triggers located on PC2 and PC3. Now both of the switches work fine triggering when they are pressed until I simultaneously toggle some LEDs on PC0 and PC1. When I do that PC2 starts triggering the interrupt with every toggle but PC3 still works fine. I have configured the INT0MASK for only PC2 and PC3 so I have no idea how the toggling of PC0 and PC1 would trigger that interrupt. I suspect that it has something to do with pin2 being an async pin but I can't be sure. Does anyone know why this could be happening? Also I have scoped the signals and when I toggle the LEDs the switches do not trigger so I am confident this is a software issue. Here is a sample that causes the bug:

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

int main(void)
{
    cli();
    
    PMIC.CTRL = PMIC_LOLVLEN_bm;
    
    PORTC.DIRSET = PIN0_bm | PIN1_bm;
    PORTC.OUTSET = PIN0_bm | PIN1_bm;
    
    PORTC.PIN2CTRL = PORT_OPC_PULLUP_gc | PORT_ISC_FALLING_gc;
    PORTC.PIN3CTRL = PORT_OPC_PULLUP_gc | PORT_ISC_FALLING_gc;
    
    PORTC.INT0MASK = PIN2_bm | PIN3_bm;
    PORTC.INTCTRL = PORT_INT0LVL_LO_gc;
    
    sei();
    
    while (1) 
    {
        _delay_ms(500);
        PORTC.OUTTGL = PIN0_bm | PIN1_bm; //This line causes the PORTC_INT0_vect to trigger
    }
}

ISR(PORTC_INT0_vect) 
{
    
}

 

Last Edited: Thu. May 11, 2017 - 11:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Never-mind I finally figured it out. Turning on the LEDs caused a spike on the switch lines. I couldn't see it with the scope because the probe capacitance fixed the problem. Added a small cap to each switch line and the problem is fixed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have current limiting resistors on the LEDs?

It would also be a good idea to software debounce the switches.