Forum Discussion

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

How to use two interval timers

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;

}

1 Reply

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

    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.