Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Use of timer in Nios

Altera_Forum
Honored Contributor II
1,202 Views

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
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
468 Views

Hi jarkko, 

 

> What's the problem? 

 

-# define count_time = 15167  

+# define count_time 15167  

 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
468 Views

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/dry.gif ehhhh.... thanks! 

 

-jarkko
0 Kudos
Reply