SAM OSC8MHz Calibration Application.
Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include "conf_example.h"
Macros | |
#define | CALIBRATION_RESOLUTION CONF_CALIBRATION_RESOLUTION |
Resolution of the calibration binary divider; lower powers of two will reduce the calibration resolution. More... | |
#define | COMM_CAL_MAX 0x7F |
#define | COMM_CAL_MIN 0x00 |
#define | FRANGE_CAL_MAX 0x03 |
#define | FRANGE_CAL_MIN 0x00 |
OSC8M calibration info. More... | |
#define | REFERENCE_CLOCK GCLK_GENERATOR_3 |
Calibration reference clock generator index. More... | |
#define | REFERENCE_CLOCK_HZ 32768 |
Frequency of the calibration reference clock in Hz. More... | |
#define | TARGET_FREQUENCY 8000000 |
Target OSC8M calibration frequency. More... | |
#define | TEMP_CAL_MAX 0x1F |
#define | TEMP_CAL_MIN 0x00 |
#define | TEMP_CAL_OFFSET 0x07 |
Functions | |
static uint32_t | get_osc_frequency (void) |
Retrieves the current system clock frequency, computed from the reference clock. More... | |
int | main (void) |
static void | setup_clock_out_pin (void) |
Set up the clock output pin so that the current system clock frequency can be monitored via an external frequency counter or oscilloscope. More... | |
static void | setup_events (struct events_resource *event) |
Set up the event system, linking the measurement and comparison timers so that events generated from the reference timer are linked to the measurement timer. More... | |
static void | setup_tc_channels (void) |
Set up the measurement and comparison timers for calibration. More... | |
static void | setup_tc_events (void) |
Set up the measurement and comparison timer events. More... | |
static void | setup_usart_channel (void) |
Set up the USART for transmit-only communication at a fixed baud rate. More... | |
Variables | |
static struct tc_module | tc_calib |
Software instance of the TC module used for calibration measurement. More... | |
static struct tc_module | tc_comp |
Software instance of the TC module used for calibration comparison. More... | |
static struct usart_module | usart_edbg |
Software instance of the USART upon which to transmit the results. More... | |
#define CALIBRATION_RESOLUTION CONF_CALIBRATION_RESOLUTION |
Resolution of the calibration binary divider; lower powers of two will reduce the calibration resolution.
Referenced by get_osc_frequency(), and setup_tc_channels().
#define COMM_CAL_MAX 0x7F |
Referenced by main().
#define COMM_CAL_MIN 0x00 |
Referenced by main().
#define FRANGE_CAL_MAX 0x03 |
Referenced by main().
#define FRANGE_CAL_MIN 0x00 |
OSC8M calibration info.
Referenced by main().
#define REFERENCE_CLOCK GCLK_GENERATOR_3 |
Calibration reference clock generator index.
Referenced by setup_tc_channels().
#define REFERENCE_CLOCK_HZ 32768 |
Frequency of the calibration reference clock in Hz.
Referenced by get_osc_frequency().
#define TARGET_FREQUENCY 8000000 |
Target OSC8M calibration frequency.
Referenced by main().
#define TEMP_CAL_MAX 0x1F |
Referenced by main().
#define TEMP_CAL_MIN 0x00 |
Referenced by main().
#define TEMP_CAL_OFFSET 0x07 |
Referenced by main().
|
static |
Retrieves the current system clock frequency, computed from the reference clock.
References CALIBRATION_RESOLUTION, REFERENCE_CLOCK_HZ, tc_calib, tc_clear_status(), tc_comp, TC_COMPARE_CAPTURE_CHANNEL_0, tc_get_capture_value(), tc_get_status(), tc_start_counter(), and TC_STATUS_CHANNEL_0_MATCH.
Referenced by main().
int main | ( | void | ) |
References COMM_CAL_MAX, COMM_CAL_MIN, delay_cycles, delay_init(), delay_ms, FRANGE_CAL_MAX, FRANGE_CAL_MIN, get_osc_frequency(), max, min, port_pin_set_output_level(), port_pin_toggle_output_level(), printf, setup_clock_out_pin(), setup_events(), setup_tc_channels(), setup_tc_events(), setup_usart_channel(), SYSTEM_CLOCK_SOURCE_OSC8M, system_clock_source_write_calibration(), system_init(), TARGET_FREQUENCY, TEMP_CAL_MAX, TEMP_CAL_MIN, and TEMP_CAL_OFFSET.
|
static |
Set up the clock output pin so that the current system clock frequency can be monitored via an external frequency counter or oscilloscope.
References system_pinmux_config::mux_position, system_pinmux_get_config_defaults(), and system_pinmux_pin_set_config().
Referenced by main().
|
static |
Set up the event system, linking the measurement and comparison timers so that events generated from the reference timer are linked to the measurement timer.
Referenced by main().
|
static |
Set up the measurement and comparison timers for calibration.
References CALIBRATION_RESOLUTION, tc_config::clock_prescaler, tc_config::clock_source, tc_16bit_config::compare_capture_channel, tc_config::counter_16_bit, tc_config::counter_size, tc_config::enable_capture_on_channel, REFERENCE_CLOCK, tc_calib, TC_CLOCK_PRESCALER_DIV1, tc_comp, TC_COUNTER_SIZE_16BIT, TC_COUNTER_SIZE_32BIT, tc_get_config_defaults(), tc_init(), TC_WAVE_GENERATION_NORMAL_FREQ, and tc_config::wave_generation.
Referenced by main().
|
static |
Set up the measurement and comparison timer events.
References tc_events::generate_event_on_compare_channel, tc_events::on_event_perform_action, tc_calib, tc_comp, tc_enable(), and tc_enable_events().
Referenced by main().
|
static |
Set up the USART for transmit-only communication at a fixed baud rate.
References usart_config::baudrate, usart_config::mux_setting, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, usart_edbg, usart_enable(), and usart_get_config_defaults().
Referenced by main().
|
static |
Software instance of the TC module used for calibration measurement.
Referenced by get_osc_frequency(), setup_tc_channels(), and setup_tc_events().
|
static |
Software instance of the TC module used for calibration comparison.
Referenced by get_osc_frequency(), setup_tc_channels(), and setup_tc_events().
|
static |
Software instance of the USART upon which to transmit the results.
Referenced by setup_usart_channel().