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

How to use two interval timers

Altera_Forum
Honored Contributor II
1,169 Views

hello, 

 

i want to use two timers with my nios core. but with this code i can only use one timer. the second one wil not work. is there something wrong with my alt_irq_register(,,). declaration. does anyone now the solution of this problem? do i need to use the interrupt vector controller? 

 

thanks! 

 

 

 

 

#include <stdio.h> 

 

#include "system.h" 

 

 

 

 

#include "altera_avalon_timer_regs.h" 

#include "altera_avalon_pio_regs.h" 

#include "sys/alt_irq.h" 

#include"terasic_includes.h" 

 

 

void waypoint()  

IOWR_ALTERA_AVALON_PIO_DATA(TEST_BASE, 0x1);  

IOWR_ALTERA_AVALON_TIMER_STATUS(WAYPOINT_BASE, 0); 

 

 

 

 

void alpha()  

{  

IOWR_ALTERA_AVALON_PIO_DATA(ENA_BASE, 0x1);  

IOWR_ALTERA_AVALON_TIMER_STATUS(ALPHA_BASE, 0);  

 

 

int main()  

{  

 

alt_irq_register( ALPHA_IRQ, null , alpha );  

alt_irq_register( WAYPOINT_IRQ, null , waypoint );  

 

return 0;  

 

0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
509 Views

Is the timer running? 

Probably you need to initialize and start it. 

 

Try this in main: 

 

IOWR_ALTERA_AVALON_TIMER_CONTROL(ALPHA_BASE, 0); 

IOWR_ALTERA_AVALON_TIMER_PERIODL(ALPHA_BASE, (TPERIOD-1) & ALTERA_AVALON_TIMER_PERIODL_MSK); 

IOWR_ALTERA_AVALON_TIMER_PERIODH(ALPHA_BASE, ((TPERIOD-1)>>16) & ALTERA_AVALON_TIMER_PERIODL_MSK); 

 

alt_irq_register(ALPHA_IRQ, NULL, alpha); 

 

IOWR_ALTERA_AVALON_TIMER_CONTROL(ALPHA_BASE,  

ALTERA_AVALON_TIMER_CONTROL_CONT_MSK  

| ALTERA_AVALON_TIMER_CONTROL_START_MSK 

| ALTERA_AVALON_TIMER_CONTROL_ITO_MSK); 

 

Same for WAYPOINT timer.
0 Kudos
Reply