Forum Discussion

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

Use of timer in Nios

I have beginner level question about using timer in Nios. In timer datasheet there is an example:# include "nios.h"

int main(void)

{

int t = 0;

// Set timer for 1 second

na_timer1->np_timerperiodl = (short)(nasys_clock_freq & 0x0000ffff);

na_timer1->np_timerperiodh = (short)((nasys_clock_freq >> 16) & 0x0000ffff);

// Set timer running, looping, no interrupts

na_timer1->np_timercontrol = np_timercontrol_start_mask + np_timercontrol_cont_mask;

// Poll timer forever, print once per second

while(1)

{

if(na_timer1->np_timerstatus & np_timerstatus_to_mask)

{

printf("A second passed! (%d)\n",t++);

// Clear the to (timeout) bit

na_timer1->np_timerstatus = 0; // (any value)

}

}

}

When i compile and run this it works fine. But in my own application i nee timer that counts 455us not to 1 s. and i tried to change timerperiod register values. Th way I understood, they have used timer period of 33.333.000 in nasys_clock freq, which gives a time of 1 s. When i try to change it for example 15167 which is approx. 455us, there is a compiler error which says "parse error before '=' at the lines where i try to change the timer value. I tried it with the same timer example but with the different value:

# include "nios.h"# define count_time = 15167

int main(void)

{

int t = 0;

// Set timer for 1 second

na_timer1->np_timerperiodl = (short)(count_time & 0x0000ffff);

na_timer1->np_timerperiodh = (short)((count_time >> 16) & 0x0000ffff);

// Set timer running, looping, no interrupts

na_timer1->np_timercontrol = np_timercontrol_start_mask + np_timercontrol_cont_mask;

// Poll timer forever, print once per second

while(1)

{

if(na_timer1->np_timerstatus & np_timerstatus_to_mask)

{

printf("A second passed! (%d)\n",t++);

// Clear the to (timeout) bit

na_timer1->np_timerstatus = 0; // (any value)

}

}

}

It suddenly doesnt work? What's the problem?

Thanks!

-jarkko