Forum Discussion

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

how to use timer

hello all

I use the timer core ,but when i write the timer there is something wrong with it .

my programm is :

void handle_time_interrupt()

{

IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE, 0x0b);

count++;

if(count==1)

{

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0xfe);

}

if(count==2)

{

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0xfd);

}

if(count==3)

{

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0xfc);

}

if(count==4)

{

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,0xfb);

count=0;

}

}

void init_time()

{

IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE, 0x07);

alt_irq_register( TIMER_0_IRQ ,

NULL,

handle_time_interrupt );

}

int main()

{

count=0;

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xaa);

init_time();

while (1)

{

}

return 0;

}

the time is 5 second,and i only see the result of 0xfb,cann't see the oxfd and 0xfc

6 Replies

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

    I suspect that your problem is that a driver is using the timer at the same time as your code, which is not a good position to be in. You can confirm this by looking in the file alt_sys_init.c if you find a MACRO TIMER_0_INIT then my diagnosis is correct.

    You should read the Nios II Software Developers Handbook to learn more about the automaticallt installed drivers and how to remove them.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hello

    the handbook is too large,can you tell me which chaper should i see.

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

    For details of how the initialisation sequence performed by the function alt_sys_init() works I suggest you load up the software developers handbook and search (Ctrl-F) for the string alt_sys_init.

    This will provide you with the information you need.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hello

    i had seen the alt_sys_init(),but it can not solve my problem. Do you have any other suggestion?

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

    I'm not sure what you mean by I had seen the alt_sys_init. If alt_sys_init has any timer calls in it, this will be your problem

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

    hello:

    i find the ALTERA_AVALON_TIMER_INIT( TIMER_0, timer_0 ) in the alt_sys_init();And try to remove it but it failed. it automatically generate the contents of alt_sys_init.c.How can i.

    Could you tell me the way?

    thanks.