Microchip® Advanced Software Framework

Use case #1

In this use case, the RTC is configured for:

  • Clock source: 1 kHz from internal 32 kHz ULP
  • Prescaling: RTC clock/1024

This use case shows how to set an alarm for the RTC.

Setup steps

Prerequisites

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

  1. PMIC for interrupt handling.
  2. Sleep Manager.
  3. A callback function, called alarm, that reschedules the alarm must be provided by the user:
    static void alarm(uint32_t time)
    {
    }

Example code

Content of conf_rtc.h:

#define CONFIG_RTC_PRESCALER RTC_PRESCALER_DIV1024_gc

Needed in conf_clock.h:

#define CONFIG_RTC_SOURCE SYSCLK_RTCSRC_ULP

Add to application initialization:

Workflow

  1. Ensure that conf_rtc.h is present for the driver.
    • Note
      This configuration file is used by the driver and should not be included by the user.
  2. Call the init function of the PMIC driver to enable all interrupt levels:
  3. Initialize system clock:
    • Note
      Make sure the define CONFIG_RTC_SOURCE is defined in conf_clock.h
  4. Call the init function of the sleep manager driver to be able to sleep waiting for alarm:
  5. Call RTC driver's own init function to start up the RTC and start counting from zero:
  6. Set callback function to call on alarm:
  7. Enable interrupts globally:

Usage steps

Example code

Workflow

  1. Set the alarm to trigger on next time unit roll over:
  2. Sleep between each triggered alarm: