Microchip® Advanced Software Framework

Quick Start Guide for the AST driver

This is the quick start guide for the SAM4L Asynchronous Timer (AST) Driver, with step-by-step instructions on how to configure and use the driver for a specific use case.The code examples can be copied into the main application loop or any other function that will need to control the AST module.

Use Cases

AST Basic Usage

This use case will demonstrate how to initialize the AST module to calendar or counter mode.

Setup Steps

Prerequisites

This module requires the following service:

Setup Code

Add this to the main loop or a setup function:

Workflow

  1. Enable the AST module:
    ast_enable(AST);
  2. Initialize the AST to counter mode:
    * struct ast_config ast_conf;
    * ast_conf.mode = AST_COUNTER_MODE;
    * ast_conf.osc_type = AST_OSC_32KHZ;
    * ast_conf.psel = AST_PSEL_32KHZ_1HZ;
    * ast_conf.counter = 0;
    * ast_set_config(AST, &ast_conf);
    *
  3. Or initialize the AST to calendar mode:
    * struct ast_calendar calendar;
    * struct ast_config ast_conf;
    * struct ast_config ast_conf;
    * ast_conf.mode = AST_CALENDAR_MODE;
    * ast_conf.osc_type = AST_OSC_32KHZ;
    * ast_conf.psel = AST_PSEL_32KHZ_1HZ;
    * ast_conf.calendar = calendar;
    * ast_set_config(AST, &ast_conf)
    Note
    We need to set the clock after prescaler to 1Hz.

Usage Steps

Usage Code

We can get the calendar value by:

Or we can get the counter value by:

We can set the alarm interrupt by:

* ast_set_callback(AST, ast_interrupt_alarm, ast_alarm_callback,
* AST_ALARM_IRQn, 1);

And we can set the periodic interrupt by:

* ast_set_callback(AST, ast_interrupt_per, ast_per_callback,
* AST_PER_IRQn, 1);