Microchip® Advanced Software Framework

adc_temp_sensor_example.c File Reference

ADC temperature sensor example for SAM.

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

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "asf.h"
#include "conf_board.h"

Macros

#define BUFFER_SIZE   (100)
 Size of the receive buffer and transmit buffer. More...
 
#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)
 ADC interrupt handler. More...
 
static uint32_t adc_read_buffer (Adc *pADC, int16_t *pwBuffer, uint32_t dwSize)
 Read converted data through PDC channel. More...
 
static void configure_console (void)
 Configure UART console. More...
 
int main (void)
 adc_temp_sensor Application entry point. More...
 
static void print_temp (float temp)
 Simple function to replace printf with float formatting. More...
 
void SysTick_Handler (void)
 Systick handler, start new conversion. More...
 

Variables

static int16_t gs_s_adc_values [BUFFER_SIZE] = { 0 }
 adc buffer More...
 

#define BUFFER_SIZE   (100)

Size of the receive buffer and transmit buffer.

Referenced by ADC_Handler(), and main().

#define STRING_EOL   "\r"

The maximal digital value.

#define STRING_HEADER
Value:
"-- ADC Temperature Sensor 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_temp_sensor_example.c:144

Referenced by main().

#define VOLT_REF   (3300)

Reference voltage for ADC,in mv.

Referenced by ADC_Handler().

void ADC_Handler ( void  )
static uint32_t adc_read_buffer ( Adc *  pADC,
int16_t *  pwBuffer,
uint32_t  dwSize 
)
static

Read converted data through PDC channel.

Parameters
pADCThe pointer of adc peripheral.
pwBufferThe destination buffer.
dwSizeThe size of the buffer.

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

static void configure_console ( void  )
static
int main ( void  )

adc_temp_sensor Application entry point.

Initialize adc to 12-bit, enable channel 15,turn on temp sensor, pdc channel interrupt for temp sensor and start conversion.

Returns
Unused (ANSI-C compatibility).

References adc_enable_channel(), adc_enable_interrupt(), adc_read_buffer(), adc_start(), ADC_TRIG_SW, board_init(), BUFFER_SIZE, configure_console(), gs_s_adc_values, pmc_enable_periph_clk(), SAM4C, SAM4CM, STRING_HEADER, sysclk_get_cpu_hz(), and sysclk_init().

static void print_temp ( float  temp)
static

Simple function to replace printf with float formatting.

One decimal with rounding support.

References Assert.

Referenced by ADC_Handler().

void SysTick_Handler ( void  )

Systick handler, start new conversion.

References adc_get_status(), and adc_start().

int16_t gs_s_adc_values[BUFFER_SIZE] = { 0 }
static

adc buffer

Referenced by ADC_Handler(), and main().