Analog-to-Digital Converter (ADC/ADC12B) example for SAM.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
Macros | |
#define | ADC_DONE_MASK ( (1<<NUM_CHANNELS) - 1 ) |
There are two peripherals ADC and ADC12B in SAM3U, you can select one of them. More... | |
#define | BUFFER_SIZE NUM_CHANNELS |
Size of the receive buffer and transmit buffer. More... | |
#define | MENU_HEADER |
#define | STRING_EOL "\r" |
ADC channel for potentiometer. More... | |
#define | STRING_HEADER |
#define | VOLT_REF (3300) |
Reference voltage for ADC, in mv. More... | |
Enumerations | |
enum | { TRIGGER_MODE_SOFTWARE = 0, TRIGGER_MODE_ADTRG, TRIGGER_MODE_TIMER } |
ADC trigger modes. More... | |
Functions | |
static void | configure_console (void) |
Configure UART console. More... | |
static void | configure_time_trigger (void) |
Configure to trigger ADC by TIOA output of timer. More... | |
static void | display_menu (void) |
Display ADC configuration menu. More... | |
int | main (void) |
adc12 Application entry point. More... | |
static void | mdelay (uint32_t ul_dly_ticks) |
Wait for the given number of milliseconds (using the dwTimeStamp generated by the SAM microcontrollers' system tick). More... | |
static void | set_adc_test_mode (void) |
Set ADC test mode. More... | |
static void | start_adc (void) |
Read converted data through PDC channel. More... | |
void | SysTick_Handler (void) |
Systick handler. More... | |
Variables | |
enum { ... } | e_trigger_mode |
ADC trigger modes. More... | |
struct { | |
uint8_t uc_ch_num [NUM_CHANNELS] | |
uint16_t us_done | |
uint16_t us_value [NUM_CHANNELS] | |
} | g_adc_sample_data |
ADC sample data. More... | |
struct { | |
uint8_t uc_gain_en | |
uint8_t uc_offset_en | |
uint8_t uc_pdc_en | |
uint8_t uc_sequence_en | |
uint8_t uc_trigger_mode | |
} | g_adc_test_mode |
ADC test mode structure. More... | |
static volatile uint32_t | gs_ul_ms_ticks = 0 |
Global timestamp in milliseconds since start of application. More... | |
#define ADC_DONE_MASK ( (1<<NUM_CHANNELS) - 1 ) |
There are two peripherals ADC and ADC12B in SAM3U, you can select one of them.
Total number of ADC channels in use ADC convention done mask.
Referenced by main().
#define BUFFER_SIZE NUM_CHANNELS |
Size of the receive buffer and transmit buffer.
Referenced by start_adc().
#define MENU_HEADER |
Referenced by display_menu().
#define STRING_EOL "\r" |
ADC channel for potentiometer.
#define STRING_HEADER |
Referenced by main().
#define VOLT_REF (3300) |
Reference voltage for ADC, in mv.
Referenced by main().
anonymous enum |
|
static |
Configure UART console.
References uart_rs232_options::baudrate, stdio_serial_init(), and sysclk_enable_peripheral_clock().
Referenced by main().
|
static |
Configure to trigger ADC by TIOA output of timer.
References ADC_TRIG_TIO_CH_0, gpio_configure_pin, pmc_enable_periph_clk(), sysclk_get_cpu_hz(), tc_find_mck_divisor(), tc_init(), and tc_start().
Referenced by start_adc().
|
static |
Display ADC configuration menu.
References g_adc_test_mode, MENU_HEADER, TRIGGER_MODE_ADTRG, TRIGGER_MODE_SOFTWARE, and TRIGGER_MODE_TIMER.
Referenced by main(), and set_adc_test_mode().
int main | ( | void | ) |
adc12 Application entry point.
References adc_disable_interrupt(), ADC_DONE_MASK, adc_start(), board_init(), configure_console(), display_menu(), g_adc_sample_data, g_adc_test_mode, MAX_DIGITAL, mdelay(), pwm_channel_disable(), set_adc_test_mode(), start_adc(), STRING_HEADER, sysclk_get_cpu_hz(), sysclk_init(), tc_start(), TRIGGER_MODE_SOFTWARE, uart_read(), us_value, and VOLT_REF.
|
static |
Wait for the given number of milliseconds (using the dwTimeStamp generated by the SAM microcontrollers' system tick).
ul_dly_ticks | Delay to wait for, in milliseconds. |
References gs_ul_ms_ticks.
Referenced by main().
|
static |
Set ADC test mode.
References display_menu(), g_adc_test_mode, TRIGGER_MODE_ADTRG, TRIGGER_MODE_SOFTWARE, TRIGGER_MODE_TIMER, and uart_read().
Referenced by main().
|
static |
Read converted data through PDC channel.
p_adc | The pointer of adc peripheral. |
p_s_buffer | The destination buffer. |
ul_size | The size of the buffer. Start ADC sample. Initialize ADC, set clock and timing, and set ADC to given mode. |
References adc_enable_channel(), adc_enable_interrupt(), ADC_GAINVALUE_0, ADC_GAINVALUE_2, adc_get_status(), adc_read_buffer(), ADC_TRIG_EXT, ADC_TRIG_SW, BUFFER_SIZE, configure_time_trigger(), g_adc_sample_data, g_adc_test_mode, gpio_configure_pin, pmc_enable_periph_clk(), sysclk_get_cpu_hz(), TRIGGER_MODE_ADTRG, TRIGGER_MODE_SOFTWARE, and TRIGGER_MODE_TIMER.
Referenced by main().
void SysTick_Handler | ( | void | ) |
Systick handler.
References gs_ul_ms_ticks.
enum { ... } e_trigger_mode |
ADC trigger modes.
struct { ... } g_adc_sample_data |
ADC sample data.
Referenced by main(), and start_adc().
struct { ... } g_adc_test_mode |
ADC test mode structure.
Referenced by display_menu(), main(), set_adc_test_mode(), and start_adc().
|
static |
Global timestamp in milliseconds since start of application.
Referenced by mdelay(), and SysTick_Handler().
uint8_t uc_ch_num[NUM_CHANNELS] |
uint8_t uc_gain_en |
uint8_t uc_offset_en |
uint8_t uc_pdc_en |
uint8_t uc_sequence_en |
uint8_t uc_trigger_mode |
uint16_t us_done |
uint16_t us_value[NUM_CHANNELS] |
Referenced by ili9325_lcd_get_16(), and main().