Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20704 Discussions

Interval Timer Core Interrupt for Nios II

Altera_Forum
Honored Contributor II
5,350 Views

I have seen many examples of using PIO cores to generate interrupts...say for button presses, and I have a grasp on those, but I am looking for a clear example of generating an interrupt using the timer core. My hardware is setup to generate a 1ms interval clock (see image attached for the setup) to IRQ 1 (high value interrupt) as I want to perform a specific task every millisecond (for example take a reading from an ADC), but I cannot grasp how to properly make this happen in the C code (I'm new to C programming not to hardware design...so it's the programming that I'm having issue with). If someone could help out a bit with a clear and small example of this that would be helpful, or point me in a direction where there is an example. Thanks, Jason

0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
2,714 Views

Initialize the interrupt in your main application code this way: 

// register the timer irq to be serviced by handle_timer_interrupt() function alt_irq_register(SYS_CLK_TIMER_IRQ, 0, handle_timer_interrupt); // activate the time IOWR_ALTERA_AVALON_TIMER_CONTROL(SYS_CLK_TIMER_BASE, ALTERA_AVALON_TIMER_CONTROL_CONT_MSK | ALTERA_AVALON_TIMER_CONTROL_START_MSK | ALTERA_AVALON_TIMER_CONTROL_ITO_MSK);  

 

This is the template for the interrupt service function: 

void handle_timer_interrupt(void*p, alt_u32 param) { // clear irq status in order to prevent retriggering IOWR_ALTERA_AVALON_TIMER_STATUS(SYS_CLK_TIMER_BASE, 0); // your isr code here // .... }
0 Kudos
Altera_Forum
Honored Contributor II
2,714 Views

Thanks for the reply, seems very straight forward. 

 

For the pushbutton interrupts, the code seemed to pass the edge capture register around using pointers, is this not necessary with the interval timer (Using the timer TO bit in the status register)? Or would that be for using the counter in another manner?
0 Kudos
Reply