Forum Discussion

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

Usage of Timer in Nios II

Dear friends

We are using Stratix II device. We have built a SOPC system with system clk timer feature. Through nios II we are trying to create an interrupt after certain time interval. But we are not able to access the timer. Can anyone plz guide us with a procedure to make use of the timer to create an interrupt. Our clock used in SOPC is 19.44 Mhz. (Other features like accessing parallel IO , Printing binary count etc are working).

1 Reply

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

    Hello,

    You can find this information in the chapter 24 (Interval Timer Core) of the Quartus II Handbook Volume 5 : Embedded Peripherals (http://www.altera.com/literature/hb/nios2/n2cpu_nii5v3.pdf). Else, here is a code where a counter is incremented according to timer interrupt and the value is displayed on leds

    #include "system.h"# include "sys/alt_irq.h"# include "altera_avalon_pio_regs.h"# include "altera_avalon_timer_regs.h"
    void handleTimerInterrupt (void* context, alt_u32 id)
    {
        static alt_u8 value = 0x00;
        value = value + 1;
        IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, ~value);                          // Display the value with leds
        IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_BASE, 0);                             // Clear the interrupt flag
    }
    int main (void)
    {
        alt_irq_register(TIMER_IRQ, 0, handleTimerInterrupt);                       // Register the ISR for timer
        while(1);
    }