Quick Start Guide for the TC driver

This is the quick start guide for the SAM3/4S/4L/4E/4N/4CM/4C/G Timer Counter (TC) 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

TC Capture Mode Basic Usage

This use case will demonstrate how to initialize the TC module to operate in capture mode using interrupts. Note, that the macros used to select the TC channel are device specific. Refer to the appropriate device-specific datasheet for more information.

Setup Steps

Prerequisites

This module requires the following services:

Setup Code

Add these macros to the top of your main application C-file:

/* Use TC Peripheral 0. */
#define TC TC0
#define TC_PERIPHERAL 0
/* Configure TC0 channel 2 as capture input. */
#define TC_CHANNEL_CAPTURE 2
#define ID_TC_CAPTURE ID_TC2
#define PIN_TC_CAPTURE PIN_TC0_TIOA2
#define PIN_TC_CAPTURE_MUX PIN_TC0_TIOA2_MUX
/* Use TC2_Handler for TC capture interrupt. */
#define TC_Handler TC2_Handler
#define TC_IRQn TC2_IRQn

Add this macro and functions to your main application C-file:

Workflow

  1. Enable the TC module's capture pin:
  2. Initialize the capture channel to the following:
    • Load RA on the rising edge of TIOA
    • Load RB on the falling edge of TIOA
    • Set the external trigger to TIOA
    • Set the external trigger to falling edge
  3. Enable the TC interrupt using NVIC:
  4. Enable the capture channel interrupt:
  5. In the TC_Handler() function, the load. RB interrupt can be checked by:
    }
  6. In the TC_Handler() function, the RA value. can be read by:
    uint32_t gs_ul_captured_ra;
  7. In the TC_Handler() function, the RB value. can be read by:
    uint32_t gs_ul_captured_rb;

TC Waveform Mode Basic Usage

This use case will demonstrate how to initialize the TC module to operate in waveform mode. Note, that the macros used to select the TC channel are device specific. Refer to the appropriate device-specific datasheet for more information.

Setup Steps

Prerequisites

This module requires the following services:

Setup Code

Add these macros to the top of your main application C-file:

/* Use TC Peripheral 0. */
#define TC TC0
#define TC_PERIPHERAL 0
/* Configure TC0 channel 1 as waveform output. */
#define TC_CHANNEL_WAVEFORM 1
#define ID_TC_WAVEFORM ID_TC1
#define PIN_TC_WAVEFORM PIN_TC0_TIOA1
#define PIN_TC_WAVEFORM_MUX PIN_TC0_TIOA1_MUX

Add these macros and function to your main application C-file:

#define TC_WAVEFORM_TIMER_SELECTION TC_CMR_TCCLKS_TIMER_CLOCK4
#define TC_WAVEFORM_DIVISOR 128
#define TC_WAVEFORM_FREQUENCY 178
#define TC_WAVEFORM_DUTY_CYCLE 30
static void tc_waveform_initialize(void)
{
uint32_t ra, rc;
// Configure the PMC to enable the TC module.
// Init TC to waveform mode.
TC_WAVEFORM_TIMER_SELECTION // Waveform Clock Selection
| TC_CMR_WAVE // Waveform mode is enabled
| TC_CMR_ACPA_SET // RA Compare Effect: set
| TC_CMR_ACPC_CLEAR // RC Compare Effect: clear
| TC_CMR_CPCTRG // UP mode with automatic trigger on RC Compare
);
// Configure waveform frequency and duty cycle.
TC_WAVEFORM_DIVISOR /
TC_WAVEFORM_FREQUENCY;
ra = (100 - TC_WAVEFORM_FREQUENCY_DUTY_CYCLE * rc / 100;
// Enable TC TC_CHANNEL_WAVEFORM.
}

Workflow

  1. Enable the TC module's waveform pin:
  2. Initialize the waveform channel to the following:
    • Output frequency of 178Hz, with a duty-cycle of 30%
    • Use TC_CMR_TCCLKS_TIMER_CLOCK4, with a divisor of 128


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:18:00