SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: What is Timer Mode in ARM?
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

What is Timer Mode in ARM?

David Moore
Last updated: September 13, 2023 6:03 am
David Moore 7 Min Read
Share
SHARE

ARM processors provide several different timer modes that allow developers to configure timers for different use cases. The timer mode determines how the timer counts, triggers interrupts, and more. The main timer modes in ARM are:

Contents
Free-Running ModePeriodic ModeOne-Shot ModeChoosing a Timer ModeTimer FeaturesUsing Timers EfficientlyConclusion
  • Free-Running Mode
  • Periodic Mode
  • One-Shot Mode

Free-Running Mode

In free-running mode, the timer continuously counts up or down from an initial value at a fixed rate. The counter automatically resets to the initial value when it reaches the maximum or minimum value. Interrupts can be triggered when the counter reaches a preset value. Free-running mode is useful for measuring time durations in applications that need accurate timekeeping.

To configure a timer in free-running mode:

  1. Load the initial counter value into the timer load register.
  2. Program the timer interval into the timer prescale register to set the tick rate.
  3. Set the appropriate mode control bits in the timer control register to enable free-running mode.
  4. Enable the timer by setting the enable bit in the timer control register.
  5. The counter will now start incrementing or decrementing at each tick based on the prescale value.
  6. Optional: Program the match register value(s) if interrupts are needed when the counter reaches a certain value.

In this mode, the timer keeps running indefinitely once enabled. The counter value can be read to determine elapsed time. Interrupts provide a way to trigger events after certain time durations.

Periodic Mode

In periodic mode, the timer counts from an initial value to a specified terminal value, then reloads the initial value and repeats the count. This creates a periodic timer that triggers an interrupt and restarts at regular intervals. Periodic mode is useful for generating periodic interrupts at a fixed frequency.

To configure periodic mode:

  1. Load the start counter value into the timer load register.
  2. Load the end counter value into the timer match register.
  3. Configure the control register to enable periodic mode.
  4. Enable the timer and interrupt generation on match.

When the counter reaches the match value, it will reset to the initial load value and continue counting. This results in a periodic timer with a frequency determined by the count range and tick rate.

Periodic mode is commonly used to generate interrupts at regular intervals for time-based tasks like reading sensors, blinking LEDs, data refresh rates, motor control pulses, and other repetitive actions.

One-Shot Mode

In one-shot mode, the timer counts from an initial value to a terminal value then stops. An interrupt can be triggered when the terminal value is reached. One-shot mode is useful for creating delay timers and time-based triggers.

To configure a one-shot timer:

  1. Load the start counter value into the timer load register.
  2. Load the end counter value into the timer match register.
  3. Configure the control register for one-shot mode.
  4. Enable the timer and interrupt on match.

When the counter reaches the match value, it will stop counting and trigger the interrupt. The timer will not restart until it is reconfigured and enabled again.

One-shot mode can generate delays, timeouts, pulse widths, and other non-repeating time-based events. The timer expires once and remains in its terminal state until reset.

Choosing a Timer Mode

Here are some guidelines for selecting a timer mode for different use cases:

  • Use free-running mode when you need an always-on counter for elapsed time measurement.
  • Use periodic mode when you need something to happen at regular intervals, like blinking an LED.
  • Use one-shot mode when you need a single timeout or delay, like waiting for sensor data.
  • Avoid free-running mode if you don’t need continuous timekeeping. It uses more power.
  • Prefer periodic mode over repetitive one-shot modes for periodic events.
  • Use one-shot for simple delays rather than busy-wait loops.

The mode can typically be changed dynamically at runtime if requirements change. Most timers allow free-running, periodic, and one-shot modes to be intermixed on the same timer peripheral.

Timer Features

ARM timers offer many configurable features including:

  • Clock source – Timer can use internal clocks or external signal.
  • Clock prescaling – Adjusts the timer tick speed.
  • Count direction – Supports up or down counting.
  • Auto-reload – Timer restarts automatically in periodic mode.
  • Preload – Next load value can be preloaded for seamless transitions.
  • Interrupts – Flexible interrupt generation on match, capture, overflow, etc.
  • Dead timer – Stops counting when the processor halts.
  • Nested interrupts – Allows interrupting active ISRs.

These features allow the timer peripheral to be customized for many different use cases. The timer can act as a simple counter, periodic interrupt source, PWM driver, real-time clock, event timestamp, and more.

Using Timers Efficiently

Here are some tips for using timers efficiently in ARM Cortex-M devices:

  • Pick the simplest timer mode that meets requirements to save power.
  • Use lower-frequency clock sources like internal RC oscillators when possible.
  • Prefer the periodic interrupt mode over software polling.
  • Use prescaling to reduce the tick frequency if a slower rate is acceptable.
  • Combine timers sharing a clock source into a single prescaled counter whenever possible.
  • Use autoreload and preload features to avoid reconfiguring the timers.
  • Prioritize interrupt handling to minimize jitter.
  • Use timestamps and deltas rather than absolute times to simplify software.

Following these best practices will help reduce timer power consumption, lower interrupt overhead, and improve the responsiveness of time-critical operations.

Conclusion

The timer peripheral is one of the most versatile components in ARM Cortex-M microcontrollers. The free-running, periodic, and one-shot modes provide flexible options for timekeeping, timeouts, pulse generation, interrupts, and other core timing functions. Timers can be optimized for low power operation and customized via clock sources, prescalers, autoreload, and interrupt capabilities. Using the right timer features and efficient software design allows building responsive and robust time-based applications on ARM.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article What is EK TM4C123GXL?
Next Article What is the purpose of the SysTick timer in ARM Cortex-M?
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

Why STM32 is Better Than ESP32?

Both STM32 and ESP32 are popular 32-bit microcontroller units (MCUs)…

7 Min Read

Deciphering the (Cortex-M3) STM32F1 Vector Table when Booting from RAM

When booting a Cortex-M3 based STM32F1 microcontroller from RAM instead…

7 Min Read

ARM Cortex-M3 Programming Tips and Tricks

The ARM Cortex-M3 is a popular 32-bit processor based on…

14 Min Read

How many GPIO registers are in ARM processor?

The number of GPIO registers in an ARM processor depends…

6 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account