# Timer (Overview)

## Description

There are four 16-bit hardware timers in the DS. Each can be used independently, or they can be combined to make 32-bit, 48-bit, or 64-bit timers.

However, the user must abide by certain conditions when using these timers. When using a timer inside the NitroSDK OS, the user cannot directly use that timer.

Inside the NitroSDK, there are two features that use the timer: the tick system and the alarm system. By default, the tick system uses timer 0, while the alarm system uses timer 1. Also, the tick system is required when using the alarm system. These give rise to the following restrictions:

When using the tick system but not the alarm system, timer 0 cannot be used.

When using the alarm system (and in such a case, the tick system must be used), neither timer 0 nor 1 can be used.

Both restrictions apply to the default configuration.

When performing a DEBUG build with the NitroSDK, when trying to access the timer being used by the system by using the timer function, a warning appears and processing halts.

Timer Operations

By setting a value in the timer count register and setting the enable flag of the timer control register, a regular-interval count begins. It is possible to configure and choose a multiple of the system clock (1x, 64x, 256x, or 1024x) for the increment interval.

A timer interrupt occurs when the counter wraps around from 0xFFFF to 0x0000. If the timer interrupt handler is set in advance with `OS_SetIrqFunction()`, that handler will be called.

According to the hardware specifications, unless you explicitly stop the timer, the count up and interrupt will repeat any number of times. However, interrupt handlers are only called when the first interrupt occurs. The timer continues to count up and interrupts continue to occur afterwards, but interrupt handlers are not called unless you reset.

Timer Configuration and Startup

The following functions set appropriate values to the timer count register and the timer control register, then start the timer.

`OS_StartTimer()
OS_StartTimer32()
OS_StartTimer48()
OS_StartTimer64()`

Stopping the Timer

The functions below clear the enable flag of the timer control register and stop the timer.

`OS_StopTimer()
OS_StopTimer32()
OS_StopTimer48()
OS_StopTimer64()`

## See Also

An Overview of OS Functions (Timer), An Overview of OS Functions (Time), An Overview of OS Functions (Alarm)

## Revision History

03/08/2005 Unified the Japanese term for "interrupt."
12/13/2004 Corrected terms and word endings.
11/16/2004 Initial version.