Microchip® Advanced Software Framework

Quick start guide for Timeout service

This is the quick start guide for the Timeout service XMEGA, with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

Timeout use cases

Basic use case - Toggle LEDs with periodic timeout

In this use case, two periodic timeouts are used to toggle two leds.

Setup steps

Prerequisites

For the setup code of this use case to work, the following must be added to the project:

  1. System Clock Management
  2. Programmable Multilevel Interrupt Controller
  3. General Purpose Input/Output
  4. Real Time Counter (RTC)
  5. Configuration info for the timeout service must be added to the conf_timeout.h file (located in the config folder):
    #define TIMEOUT_CLOCK_SOURCE_HZ 1024
    #define TIMEOUT_COUNT 8
    #define TIMEOUT_TICK_HZ 4
  6. Configuration info for the RTC driver must be added to the conf_rtc.h file (located in the config folder):
    #define CONFIG_RTC_PRESCALER RTC_PRESCALER_DIV1_gc
    #define CONFIG_RTC_CLOCK_SOURCE CLK_RTCSRC_ULP_gc

Example code

The following must be added to the project:

#define TIMEOUT_0 0
#define TIMEOUT_1 1

Add to application initialization:

Workflow

  1. Initialize system clock:
  2. Initialize the PMIC driver:
  3. Initialize timeout service:
    • timout_init();
  4. Start timeout channel 0 with a period of 1 tick:
  5. Start timeout channel 1 with a period of 2 ticks:

Usage steps

Example code

Add to application C-file:

while (1) {
gpio_toggle_pin(LED0_GPIO);
}
gpio_toggle_pin(LED1_GPIO);
}
}

Workflow

  1. Check if timeout on channel 0 has expired, and toggle led if it has:
  2. Check if timeout on channel 1 has expired, and toggle led if it has: