Altera_Forum
Honored Contributor
20 years agoTrouble of NIOS2's timer interrupt
HI everyone
i have purchased the NIOS2 evaluate board--EP1C12 from the Altera. and i program a timer interrupt routine to create a square wave based on the evaluate board's standard design. my routines is below:# include "system.h"# include "sys/alt_irq.h"# include "altera_avalon_pio_regs.h"# include "altera_avalon_timer_regs.h"# include "alt_types.h" alt_u8 x = 0x55; static void timer_interrupts(void* context, alt_u32 id) { IOWR_ALTERA_AVALON_TIMER_STATUS(SYS_CLOCK_TIMER_BASE, 0); x = x ^ 0xFF; IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, x); } int main() { alt_irq_register(SYS_CLOCK_TIMER_IRQ, 0, timer_interrupts); IOWR_ALTERA_AVALON_TIMER_PERIODL(SYS_CLOCK_TIMER_BASE, 0x1F40);// timer interrupt period is 100us IOWR_ALTERA_AVALON_TIMER_PERIODH(SYS_CLOCK_TIMER_BASE, 0x00); IOWR_ALTERA_AVALON_TIMER_CONTROL(SYS_CLOCK_TIMER_BASE, 7); while(1) { ; } } i download the routine into the evaluate board and run it, then the square wave's period is 200us as designed. when i add some float calculation in the ISR, the period changed and bacame more than designed. the ISR is below: static void timer_interrupts(void* context, alt_u32 id) { float i; IOWR_ALTERA_AVALON_TIMER_STATUS(SYS_CLOCK_TIMER_BASE, 0); x = x ^ 0xFF; for(i=0;i<100;i++); IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, x); } The period is 2.784ms!!!!!! If "float" became "alt_u8", the period is 200us as designed. static void timer_interrupts(void* context, alt_u32 id) { alt_u8 i; IOWR_ALTERA_AVALON_TIMER_STATUS(SYS_CLOCK_TIMER_BASE, 0); x = x ^ 0xFF; for(i=0;i<100;i++); IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, x); } I wonder if there can not be float calculation in the timer interrupt or the float calculation is very slow in NIOS2????