Microchip® Advanced Software Framework

tc_example3.c File Reference

Timer/Counter example 3.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include <stdint.h>
#include <stdbool.h>
#include "sysclk.h"
#include "board.h"
#include "print_funcs.h"
#include "tc.h"
#include "gpio.h"
#include "intc.h"
#include "conf_example.h"


int main (void)
 Main function: More...
static void tc_init (volatile avr32_tc_t *tc)
 TC Initialization. More...
static void tc_irq (void)
 TC interrupt. More...


static volatile uint32_t tc_tick = 0
static volatile bool update_timer = true

int main ( void  )

Main function:

  • Configure the CPU to run at 12MHz
  • Configure the USART
  • Register the TC interrupt (GCC only)
  • Configure, enable the CPCS (RC compare match) interrupt, and start a TC channel in waveform mode
  • In an infinite loop, update the USART message every second.
the call to sysclk_init() will disable all non-vital peripheral clocks, except for the peripheral clocks explicitly enabled in conf_clock.h.

References cpu_irq_disable, cpu_irq_enable, EXAMPLE_TC, EXAMPLE_TC_IRQ, init_dbg_rs232(), INTC_init_interrupts(), INTC_register_interrupt(), print_dbg(), print_dbg_ulong(), sysclk_enable_peripheral_clock(), sysclk_get_pba_hz(), sysclk_init(), tc_init(), tc_irq(), tc_tick, and update_timer.

static void tc_init ( volatile avr32_tc_t *  tc)

TC Initialization.

Initializes and start the TC module with the following:

  • Counter in Up mode with automatic reset on RC compare match.
  • fPBA/8 is used as clock source for TC
  • Enables RC compare match interrupt
    tcBase address of the TC module

References tc_waveform_opt_t::channel, tc_interrupt_t::etrgs, EXAMPLE_TC_CHANNEL, sysclk_get_pba_hz(), TC_CLOCK_SOURCE_TC3, tc_configure_interrupts(), TC_EVT_EFFECT_NOOP, tc_init_waveform(), TC_SEL_NO_EDGE, tc_start(), TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER, and tc_write_rc().

Referenced by main().

static void tc_irq ( void  )

TC interrupt.

The ISR handles RC compare interrupt and sets the update_timer flag to update the timer value.

References EXAMPLE_TC, EXAMPLE_TC_CHANNEL, tc_read_sr(), tc_tick, and update_timer.

Referenced by init_timer(), and main().

volatile uint32_t tc_tick = 0

Referenced by main(), and tc_irq().

volatile bool update_timer = true

Referenced by main(), and tc_irq().