Microchip® Advanced Software Framework

adc_threshold_wakeup_example.c File Reference

ADC threshold wakeup example for SAM.

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

#include "asf.h"
#include "stdio_serial.h"
#include "conf_board.h"

Macros

#define BOARD_ADC_FREQ   (6000000)
 ADC channel for potentiometer. More...
 
#define MENU_HEADER
 
#define STRING_EOL   "\r"
 The maximal digital value. More...
 
#define STRING_HEADER
 
#define VOLT_REF   (3300)
 Reference voltage for ADC, in mv. More...
 

Functions

void ADC_Handler (void)
 
static void configure_console (void)
 
static void configure_tc0 (void)
 Configure Timer Counter 0 (TC0) to generate an interrupt every second. More...
 
static void display_info (void)
 Display current information,including voltage on potentiometer, thresholds and comparison mode. More...
 
static void display_menu (void)
 Display main menu. More...
 
static void enter_asleep (void)
 Enter sleep mode using WFI instruction. More...
 
static uint32_t f_to_int (float x)
 Transform float data type to int. More...
 
static uint8_t get_comparison_mode (void)
 Get comparison mode. More...
 
static int16_t get_voltage (void)
 Get voltage from user input (range from 0 to 3300 mv). More...
 
int main (void)
 Example entry point. More...
 

Variables

static uint16_t gs_us_high_threshold = 0
 High threshold. More...
 
static uint16_t gs_us_low_threshold = 0
 Low threshold. More...
 

#define BOARD_ADC_FREQ   (6000000)

ADC channel for potentiometer.

ADC clock

#define MENU_HEADER
Value:
"\n\r-- Menu Choices for this example--\n\r" \
"-- 0: Display voltage on potentiometer.--\n\r" \
"-- 1: Modify low threshold.--\n\r" \
"-- 2: Modify high threshold.--\n\r" \
"-- 3: Choose comparison mode.--\n\r" \
"-- i: Display ADC information.--\n\r" \
"-- m: Display this main menu.--\n\r" \
"-- s: Enter sleep mode.--\n\r"

Referenced by display_menu().

#define STRING_EOL   "\r"

The maximal digital value.

#define STRING_HEADER
Value:
"-- ADC Threshold Wakeup Example --\r\n" \
"-- "BOARD_NAME" --\r\n" \
"-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
#define BOARD_NAME
Definition: inc/app_init.h:140
#define STRING_EOL
The maximal digital value.
Definition: adc_threshold_wakeup_example.c:163

Referenced by main().

#define VOLT_REF   (3300)

Reference voltage for ADC, in mv.

Referenced by ADC_Handler(), display_info(), get_voltage(), and main().

static void configure_console ( void  )
static
static void configure_tc0 ( void  )
static

Configure Timer Counter 0 (TC0) to generate an interrupt every second.

This interrupt will be used to display the number of bytes received on the UART.

References pmc_enable_periph_clk(), and tc_init().

Referenced by main().

static void display_info ( void  )
static

Display current information,including voltage on potentiometer, thresholds and comparison mode.

References ADC_CHANNEL_POTENTIOMETER, adc_get_channel_value(), f_to_int(), gs_us_high_threshold, gs_us_low_threshold, MAX_DIGITAL, and VOLT_REF.

Referenced by main().

static void display_menu ( void  )
static

Display main menu.

References MENU_HEADER.

Referenced by main().

static void enter_asleep ( void  )
static

Enter sleep mode using WFI instruction.

Enable interrupt first and then disable it after wake up.

References adc_enable_interrupt(), and adc_get_status().

Referenced by main().

static uint32_t f_to_int ( float  x)
static

Transform float data type to int.

Referenced by display_info(), and main().

static uint8_t get_comparison_mode ( void  )
static

Get comparison mode.

References uart_read().

Referenced by main().

static int16_t get_voltage ( void  )
static

Get voltage from user input (range from 0 to 3300 mv).

References uart_read(), and VOLT_REF.

Referenced by main().

int main ( void  )

Example entry point.

Initialize ADC to 12-bit, enable channel "ADC_CHANNEL_POTENTIOMETER", then enable hardware trigger with TIOA0 every second. Finally, start conversion.

Returns
Unused (ANSI-C compatibility).

References ADC_CHANNEL_POTENTIOMETER, adc_enable_channel(), adc_get_channel_value(), ADC_TRIG_TIO_CH_0, board_init(), configure_console(), configure_tc0(), display_info(), display_menu(), enter_asleep(), f_to_int(), get_comparison_mode(), get_voltage(), gs_us_high_threshold, gs_us_low_threshold, MAX_DIGITAL, pmc_enable_periph_clk(), STRING_HEADER, sysclk_get_cpu_hz(), sysclk_init(), tc_start(), uart_read(), and VOLT_REF.

uint16_t gs_us_high_threshold = 0
static

High threshold.

Referenced by ADC_Handler(), display_info(), and main().

uint16_t gs_us_low_threshold = 0
static

Low threshold.

Referenced by ADC_Handler(), display_info(), and main().