Forum Discussion

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

problem with interrupts

I have tried to make a simple interrupt of a push button and when i registered the ISR it immediately started to execute the ISR like it's an endless loop.:confused:

Another thing, what is the difference between alt_irq_register() and alt_ic_isr_register()?

(i have used alt_irq_register() );

can someone give me an example code for simple interrupt....?

thanks!!!:rolleyes:

5 Replies

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

    it might be that you are not Resetting the Button's edge capture register. give "IOWR_ALTERA_AVALON_PIO_EDGE_CAP(<BASE ADDRESS OF YOUR BUTTON), 0); "

    where the ISR work ends
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have an example (it works fine):

    # include "test_II.h"# define switches_base 0x00101030# define leds_base 0x00101000# define push_base 0x00101020

    // *** Maneja la interrupcion ****

    static void push_isr(void* context, alt_u32 id){

    volatile int *function=(volatile int*) context;

    *function=IORD_ALTERA_AVALON_PIO_EDGE_CAP(push_base);

    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(push_base,0);

    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(push_base,0xF);

    }

    //*************************************

    int main(void)

    { volatile int function=0;

    alt_u32 switches;

    // Activas la interrupcion.

    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(push_base,0xF);

    alt_irq_register(PUSH_IRQ,(void*)&function, push_isr);

    while(1){

    switch(function){

    case 0x1:

    switches= IORD_ALTERA_AVALON_PIO_DATA(switches_base);

    IOWR_ALTERA_AVALON_PIO_DATA(leds_base,switches);

    function=0;

    break;

    default:

    break;

    }

    }

    return 0;

    }

    Maybe it could help you...
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    thank you both!

    i think that i found the problem!! i have writen to the edge cupture register the value '1' insted of '0' and it suddenly works!! i dont know why, does someone has an explanation why?..

    thanks for your help!!!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Possibly, when the interrupt is level triggered, the 'button up' state is the one that was asserting the IRQ. (Even if it were the 'button down' state the ISR would be called repeatedly untill the button was released.)

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

    Bit n in the edgecapture register is set to 1 whenever an edge is detected on input

    port n. An Avalon-MM master peripheral can read the edgecapture register to

    determine if an edge has occurred on any of the PIO input ports. if the option enable

    bit-clearing for edge capture register is turned off, writing any value to the

    edgecapture register clears all bits in the register. otherwise, writing a 1 to a

    particular bit in the register clears only that bit.