Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

having trouble with interrupt

Hello everyone ,

I'm try for a very long time to do a simple interrupt with nios ii.

this is my problem:

i have button in sratix ii dev kit and all i want to do in nios is just to turn on led (with interrupt) when the button is pressed.

i defined rising_edge and all the others in sopc and i checked that the button is connected to the sopc module in quartus.

everything passed the compile but when i run the debug the program ignore my clicks on the button and do nothing.

this is my program:

the program ignore my clicks and doesn't get to here :\

void led_interrupt()

{

//turn on led//

//Delay//

}

void main()

{

alt_irq_registerr(button_IRQ, led_interrupt );

//turn off led//

while(1); // waiting for interrupt;

}

I hope somebody can help me.

sorry for my bad english:)

thanks you(:

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Add these before alt_irq_register:

    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(button_IRQ, <irq_bit_mask>); // enable irq

    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(button_IRQ, <irq_bit_mask>); // clear irq

    You also need to clear the edge capture bit in irq handler function, otherwise the irq will keep on retriggering.

    Also make sure of these points:

    - in qsys/sopc button pio must be defined with interrupt capability enabled

    - the button pio is correctly routed to fpga pin and pio is working: begin with polling the pio in while loop to test this point.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    Could you elaborate on the definition of "irq_bit_mask"?

    In SOPC builder, my PIO IRQ (width = 1 bit) is on IRQ line 9.

    Does this mean my "irq_bit_mask" is bit 9?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(button_base_address,1); // enable irq

    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(button_base_address, 1); // clear irq

    Infact you are using PIO bit 0, then mask = 1.

    For clarity: if you had a 8 bit wide PIO and you connected the button to pio_input[6], then you'd had irq_bit_mask=0x40

    IRQ line nr is involved only in alt_irq_register() call.