DAC Sinewave Example.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include "asf.h"
#include "conf_board.h"
#include "conf_clock.h"
#include "conf_dacc_sinewave_example.h"
Macros | |
#define | DACC_ANALOG_CONTROL |
Analog control value. More... | |
#define | DEFAULT_FREQUENCY 1000 |
Default frequency. More... | |
#define | MAX_AMPLITUDE (DACC_MAX_DATA) |
The maximal (peak-peak) amplitude value. More... | |
#define | MAX_DIGITAL (0x7ff) |
The maximal sine wave sample data (no sign) More... | |
#define | MAX_FREQUENCY 3000 |
Max frequency. More... | |
#define | MIN_AMPLITUDE (100) |
The minimal (peak-peak) amplitude value. More... | |
#define | MIN_FREQUENCY 200 |
Min frequency. More... | |
#define | SAMPLES (100) |
SAMPLES per cycle. More... | |
#define | STRING_EOL "\r" |
#define | STRING_HEADER |
#define | VAL_INVALID 0xFFFFFFFF |
Invalid value. More... | |
#define | wave_to_dacc(wave, amplitude, max_digital, max_amplitude) (((int)(wave) * (amplitude) / (max_digital)) + (max_amplitude / 2)) |
Functions | |
static void | configure_console (void) |
Configure console. More... | |
static void | display_menu (void) |
Display main menu. More... | |
static uint32_t | get_input_value (uint32_t ul_lower_limit, uint32_t ul_upper_limit) |
Get input from user, and the biggest 4-digit decimal number is allowed. More... | |
int | main (void) |
DAC Sinewave application entry point. More... | |
void | SysTick_Handler (void) |
SysTick IRQ handler. More... | |
Variables | |
int32_t | g_l_amplitude = 0 |
Amplitude. More... | |
uint8_t | g_uc_wave_sel = 0 |
Waveform selector. More... | |
uint32_t | g_ul_frequency = 0 |
Frequency. More... | |
uint32_t | g_ul_index_sample = 0 |
Current g_ul_index_sample. More... | |
const int16_t | gc_us_sine_data [SAMPLES] |
100 points of sinewave samples, amplitude is MAX_DIGITAL*2 More... | |
#define DACC_ANALOG_CONTROL |
Analog control value.
Referenced by main().
#define DEFAULT_FREQUENCY 1000 |
Default frequency.
Referenced by main().
#define MAX_AMPLITUDE (DACC_MAX_DATA) |
The maximal (peak-peak) amplitude value.
Referenced by display_menu(), main(), and SysTick_Handler().
#define MAX_DIGITAL (0x7ff) |
The maximal sine wave sample data (no sign)
Referenced by SysTick_Handler().
#define MAX_FREQUENCY 3000 |
Max frequency.
Referenced by display_menu(), and main().
#define MIN_AMPLITUDE (100) |
The minimal (peak-peak) amplitude value.
Referenced by display_menu(), and main().
#define MIN_FREQUENCY 200 |
Min frequency.
Referenced by display_menu(), and main().
#define SAMPLES (100) |
SAMPLES per cycle.
Referenced by main(), and SysTick_Handler().
#define STRING_EOL "\r" |
#define STRING_HEADER |
Referenced by main().
#define VAL_INVALID 0xFFFFFFFF |
Invalid value.
Referenced by get_input_value(), and main().
#define wave_to_dacc | ( | wave, | |
amplitude, | |||
max_digital, | |||
max_amplitude | |||
) | (((int)(wave) * (amplitude) / (max_digital)) + (max_amplitude / 2)) |
Convert wave data to DACC value Put the sinewave to an offset of max_amplitude/2.
wave | Waveform data |
amplitude | Amplitude value |
max_digital | Maximal digital value of input data (no sign) |
max_amplitude | Maximal amplitude value |
Referenced by SysTick_Handler().
|
static |
Configure console.
References uart_rs232_options::baudrate, stdio_serial_init(), and sysclk_enable_peripheral_clock().
Referenced by main().
|
static |
Display main menu.
References g_l_amplitude, g_uc_wave_sel, g_ul_frequency, MAX_AMPLITUDE, MAX_FREQUENCY, MIN_AMPLITUDE, and MIN_FREQUENCY.
Referenced by main().
|
static |
Get input from user, and the biggest 4-digit decimal number is allowed.
ul_lower_limit | The lower limit of input |
ul_upper_limit | The upper limit of input |
References usart_serial_getchar(), and VAL_INVALID.
Referenced by main().
int main | ( | void | ) |
DAC Sinewave application entry point.
References board_init(), configure_console(), DACC_ANALOG_CONTROL, dacc_enable(), dacc_enable_channel(), dacc_reset(), dacc_set_analog_control(), dacc_set_channel_selection(), dacc_set_power_save(), dacc_set_timing(), dacc_set_transfer_mode(), DEFAULT_FREQUENCY, display_menu(), g_l_amplitude, g_uc_wave_sel, g_ul_frequency, get_input_value(), MAX_AMPLITUDE, MAX_FREQUENCY, MIN_AMPLITUDE, MIN_FREQUENCY, SAMPLES, STRING_HEADER, sysclk_enable_peripheral_clock(), sysclk_get_cpu_hz(), sysclk_init(), usart_serial_getchar(), and VAL_INVALID.
void SysTick_Handler | ( | void | ) |
SysTick IRQ handler.
References dacc_get_interrupt_status(), dacc_write_conversion_data(), g_l_amplitude, g_uc_wave_sel, g_ul_index_sample, gc_us_sine_data, MAX_AMPLITUDE, MAX_DIGITAL, SAMPLES, status, and wave_to_dacc.
int32_t g_l_amplitude = 0 |
Amplitude.
Referenced by display_menu(), main(), and SysTick_Handler().
uint8_t g_uc_wave_sel = 0 |
Waveform selector.
Referenced by display_menu(), main(), and SysTick_Handler().
uint32_t g_ul_frequency = 0 |
Frequency.
Referenced by display_menu(), and main().
uint32_t g_ul_index_sample = 0 |
Current g_ul_index_sample.
Referenced by SysTick_Handler().
const int16_t gc_us_sine_data[SAMPLES] |
100 points of sinewave samples, amplitude is MAX_DIGITAL*2
Referenced by SysTick_Handler().