RTC: Usage

Real Time Clock

RTC
Usage

Usage

Example1: This example demonstrates how to use the RTC APP to generate a periodic (second) interrupt and an alarm interrupt using XMC4500 hexagon board.

Instantiate the RTC APP and update its GUI with the following configuration

Configure the APP

  1. Enter date and time
    Note: By default date is 01/01/1970 and time is 00:00:00.
  2. Enter Alarm date and alarm time
    Note: By default date is 01/01/1970 and time is 00:01:00.


  1. Select "seconds" check box in the periodic events group
  2. Select the check box for "Enable alarm interrupt"


Instantiate DIGITAL_IO APP and set the following configuration:

Generate code
Files are generated here: `<project_name>/Dave/Generated/' (`project_name' is the name chosen by the user during project creation). APP instance definitions and APIs are generated only after code generation.

  • Note: Code must be explicitly generated for every change in the GUI configuration.
    Important: Any manual modification to these generated code files will be overwritten by a subsequent code generation operation.


Sample Application (main.c)

 #include <DAVE.h>

 void Time_Handler(void)
 {
   DIGITAL_IO_ToggleOutput(&DIGITAL_IO_0);
 }

 void Alarm_Handler(void)
 {
   XMC_RTC_ALARM_t alarm_time;

   RTC_GetAlarmTime(&alarm_time);     // Read the current alarm time


  if(++alarm_time.minutes > 59)
  {
      alarm_time.minutes = 0;
      alarm_time.hours++;
  }

  RTC_Stop();
  RTC_SetAlarmTime(&alarm_time);     // Reconfigure alarm time for next minute
  RTC_Start();
 }

  int main(void)
  {
   RTC_Stop();
   DAVE_Init(); // RTC_Init(&RTC_0) is called inside DAVE_Init
   while(1)
   {}
    return 0;
  }



Build and Run the Project

Observation

every second, RTC toggles the P3.9 on the XMC4500 hexagon board.
Keep breakpoint in Alarm_Handler function.
After 60 seconds, program halts in Alarm_Handler function.

Example2:
This example demonstrates how to use the RTC alarm event to trigger the NMI(Non Maskable Interrupt) on XMC4500/XMC4800 hexagon board.

Instantiate the RTC APP and update its GUI with the following configuration

Configure the APP

  1. Enter date and time
    Note: By default date is 01/01/1970 and time is 00:00:00.
  2. Enter Alarm date and alarm time
    Note: By default date is 01/01/1970 and time is 00:01:00.


Timer event settings:
Select "seconds" check box in the periodic events group
Select "SCU Interrupt" option for the Event trigger
Alarm event settings:
Select the check box for "Enable alarm interrupt"
Select "NMI Interrupt" option for the Event trigger

Instantiate DIGITAL_IO APP and set the following configuration:

Generate code
Files are generated here: `<project_name>/Dave/Generated/' (`project_name' is the name chosen by the user during project creation). APP instance definitions and APIs are generated only after code generation.

  • Note: Code must be explicitly generated for every change in the GUI configuration.
    Important: Any manual modification to these generated code files will be overwritten by a subsequent code generation operation.


Sample Application (main.c)

 #include <DAVE.h>

 void Time_Handler(void)
 {
   DIGITAL_IO_ToggleOutput(&DIGITAL_IO_0);
 }

 void NMI_Handler(void)
 {
   XMC_RTC_ALARM_t alarm_time;

   XMC_SCU_INTERRUPT_ClearEventStatus((XMC_SCU_INTERRUPT_EVENT_t)XMC_SCU_INTERRUPT_EVENT_RTC_ALARM);

   RTC_GetAlarmTime(&alarm_time);     // Read the current alarm time


  if(++alarm_time.minutes > 59)
  {
      alarm_time.minutes = 0;
      alarm_time.hours++;
  }

  RTC_Stop();
  RTC_SetAlarmTime(&alarm_time);     // Reconfigure alarm time for next minute
  RTC_Start();
 }

  int main(void)
  {
    RTC_Stop();
    DAVE_Init(); // RTC_Init(&RTC_0) is called inside DAVE_Init
    while(1)
    {}
    return 0;
  }



Build and Run the Project

Observation

every second, RTC toggles the P3.9 on the XMC4500 hexagon board.
Keep breakpoint in NMI_Handler function.
After 60 seconds, program halts in NMI_Handler function and reconfigures alarm for next minute.
So every minute the NMI hadler gets executed.