Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

Timers

Altera_Forum
Honored Contributor II
1,309 Views

Hello, 

Im new to Nios. 

In my system there are 2 timers:timer_0 and timer_1. 

Defined as follow in system.h: 

 

/* 

* timer_0 configuration 

*/ 

 

 

#define 

TIMER_0_NAME "/dev/timer_0" 

#define 

 

TIMER_0_TYPE "altera_avalon_timer" 

#define 

 

TIMER_0_BASE 0x00042400 

#define 

 

TIMER_0_SPAN 32 

#define 

 

TIMER_0_IRQ 0 

#define 

 

TIMER_0_ALWAYS_RUN 0 

#define 

 

TIMER_0_FIXED_PERIOD 0 

#define 

 

TIMER_0_SNAPSHOT 1 

#define 

 

TIMER_0_PERIOD 1 

#define 

 

TIMER_0_PERIOD_UNITS "ms" 

#define 

 

TIMER_0_RESET_OUTPUT 0 

#define 

 

TIMER_0_TIMEOUT_PULSE_OUTPUT 0 

#define 

 

TIMER_0_LOAD_VALUE 24999 

#define 

 

TIMER_0_COUNTER_SIZE 32 

#define 

 

TIMER_0_MULT 0.0010 

#define 

 

TIMER_0_TICKS_PER_SEC 1000 

#define 

 

TIMER_0_FREQ 25000000 

#define 

 

ALT_MODULE_CLASS_timer_0 altera_avalon_timer 

 

/* 

* timer_1 configuration 

*/ 

 

#define 

 

TIMER_1_NAME "/dev/timer_1" 

#define 

 

TIMER_1_TYPE "altera_avalon_timer" 

#define 

 

TIMER_1_BASE 0x00042420 

#define 

 

TIMER_1_SPAN 32 

#define 

 

TIMER_1_IRQ 1 

#define 

 

TIMER_1_ALWAYS_RUN 0 

#define 

 

TIMER_1_FIXED_PERIOD 0 

#define 

 

TIMER_1_SNAPSHOT 1 

#define 

 

TIMER_1_PERIOD 100 

#define 

 

TIMER_1_PERIOD_UNITS "us" 

#define 

 

TIMER_1_RESET_OUTPUT 0 

#define 

 

TIMER_1_TIMEOUT_PULSE_OUTPUT 0 

#define 

 

TIMER_1_LOAD_VALUE 2499 

#define 

 

TIMER_1_COUNTER_SIZE 32 

#define 

 

TIMER_1_MULT "1.0E-6" 

#define 

 

TIMER_1_TICKS_PER_SEC 10000 

#define 

 

TIMER_1_FREQ 25000000 

#define ALT_MODULE_CLASS_timer_1 altera_avalon_timer 

 

 

 

What i want to know is:
  1. When i use the function : alt_alarm_start i see that the system automatically use timer_0 to set the alarm,why timer_0? 

  2. What should i do if i want the alarm every 100 micro seconds and still use the function : alt_alarm_start? 

 

0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
108 Views

I think you may config your timer in sopc builder

Altera_Forum
Honored Contributor II
108 Views

and if want to use it in your nios, you may registry it first and then install it 

 

hope this will help
Altera_Forum
Honored Contributor II
108 Views

timer_0 must be defined as the system timer by default. You can change it to timer_1 by updating it in the bsp settings in NIOS SBT tool. 

 

The prototype for alarm start is: 

int alt_alarm_start 

( alt_alarm* alarm,  

alt_u32 nticks,  

alt_u32 (*callback) (void* context), 

void* context ) 

 

Think nticks is what you are looking for. You can use it to trigger a callback function after 100us systicks. One the callback is triggered, you can restart the same alarm within the callback itself.
Reply