/* p7_2.c: A to D conversion of internal temperature sensor * * This program converts the analog input from channel 0x18, * the internal temperature sensor. * Channel 0x18 is configured as single-ended input. * Default internal 1.0V reference is used. * Clock prescaler is left at 0 (divided by 4) and Sampling * time is set to 5 clock cycles (20 us). * Software trigger is used. * * Tested with Atmel Studio 7 v7.0.1006 and Keil MDK-ARM v5.21a. */ #include "samd21.h" int result; int main (void) { REG_SYSCTRL_VREF |= 2; /* turn on int. temp. sensor */ REG_PM_APBCMASK |= 0x10000; /* enable bus clock for ADC */ REG_GCLK_CLKCTRL = 0x401E; /* GCLK0 to ADC */ REG_ADC_SAMPCTRL = 5; /* sampling time 5 clocks */ REG_ADC_INPUTCTRL = 0x1818; /* V- = GND; V+ = int. temp. */ REG_ADC_SAMPCTRL = 20; /* sampling time */ REG_ADC_CTRLA = 2; /* enable ADC */ REG_PORT_DIRSET1 = 0x40000000; /* PB30 output for LED0 */ while (1) { REG_ADC_SWTRIG = 2; /* start a conversion */ while(!(REG_ADC_INTFLAG & 1)); /* wait for conv complete */ result = REG_ADC_RESULT; /* read conversion result */ } }