/***************************************************************************//**
* @brief
*   Configure ADC usage for this application.
*******************************************************************************/
static void ADCConfig(void)
{
  ADC_Init_TypeDef       init       = ADC_INIT_DEFAULT;
  ADC_InitSingle_TypeDef singleInit = ADC_INITSINGLE_DEFAULT;

  /* Init common settings for both single conversion and scan mode */
  init.timebase = ADC_TimebaseCalc(0);
  /* Might as well finish conversion as quickly as possibly since polling */
  /* for completion. */
  /* Set ADC clock to 7 MHz, use default HFPERCLK */
  init.prescale = ADC_PrescaleCalc(7000000, 0);

  /* WARMUPMODE must be set to Normal according to ref manual before */
  /* entering EM2. In this example, the warmup time is not a big problem */
  /* due to relatively infrequent polling. Leave at default NORMAL, */

  ADC_Init(ADC0, &init);

  /* Init for single conversion use. */
  singleInit.reference  = adcRefVDD;
  singleInit.input      = adcSingleInpCh5;
  singleInit.resolution = adcRes12Bit;
  singleInit.prsEnable  = true; /* Enable PRS for ADC */
  ADC_InitSingle(ADC0, &singleInit);

  /* Enable ADC Interrupt when Single Conversion Complete */
  ADC0->IEN = ADC_IEN_SINGLE;

  /* Enable ADC interrupt vector in NVIC*/
  NVIC_EnableIRQ(ADC0_IRQn);
}
/**************************************************************************//**
 * @brief Configure ADC for 12 bit mode, sample channel 0 with Vdd as reference 
 * and use shortest acquisition time.
 *****************************************************************************/
static void ADC_Config(void)
{
  
  CMU_ClockEnable(cmuClock_ADC0, true);
  
  ADC_Init_TypeDef       init       = ADC_INIT_DEFAULT;
  ADC_InitSingle_TypeDef singleInit = ADC_INITSINGLE_DEFAULT;

  /* Init common settings for both single conversion and scan mode- */
  /* Set timebase to 10, this gives 11 cycles which equals 1us at 11 MHz. */
  init.timebase = 10;

  /* Set ADC clock prescaler to 0, we are using 11MHz HFRCO, which results in HFPERCLK < 13MHz- */
  init.prescale = 0;

  ADC_Init(ADC0, &init);

  /* Init for single conversion use, measure channel 0 with Vdd as reference. */
  /* Using Vdd as reference removes the 5us warmup time for the bandgap reference. */
  singleInit.reference  = adcRefVDD;
  singleInit.input      = adcSingleInpCh0;
  
  /* Resolution can be set lower for even more energy efficient operation. */
  singleInit.resolution = adcRes12Bit;

  /* Assuming we are mesuring a low impedance source we can safely use the shortest */
  /* acquisition time. */
  singleInit.acqTime = adcAcqTime1;

  ADC_InitSingle(ADC0, &singleInit);
  
}
/*
 * Function Name: ADC_setup()
 * Description: Configures ADC0
 */
void ADC_Setup(void)

{
    CMU_ClockEnable(cmuClock_ADC0, true);

    // Default Declarations
    ADC_Init_TypeDef       init       = ADC_INIT_DEFAULT;
    ADC_InitSingle_TypeDef singleInit = ADC_INITSINGLE_DEFAULT;

    // ADC Parameters
    init.timebase = ADC_TimebaseCalc(0);
    init.prescale = ADC_PrescaleCalc(857000,0);

    // Initializing ADC
    ADC_Init(ADC0, &init);

    // Single Conversion setup
    // Single Conversion with Repeat ON
    singleInit.reference  = ADC_REF;
    singleInit.input      = adcSingleInpTemp;
    singleInit.resolution = adcRes12Bit;
    singleInit.acqTime = adcAcqTime2;
    singleInit.rep = true;

    // ADC single setup on
    ADC_InitSingle(ADC0, &singleInit);
}
示例#4
0
void analogin_init(analogin_t *obj, PinName pin)
{
    static uint8_t adc_initialized = 0;

    /* Init structure */
    obj->adc = (ADC_TypeDef *) pinmap_peripheral(pin, PinMap_ADC);
    MBED_ASSERT((int) obj->adc != NC);

    obj->channel = pin_location(pin, PinMap_ADC);
    MBED_ASSERT((int) obj->channel != NC);

    /* Only initialize the ADC once */
    if (!adc_initialized) {
        /* Turn on the clock */
        CMU_ClockEnable(cmuClock_ADC0, true);

        /* Init with default settings */
        ADC_Init_TypeDef init = ADC_INIT_DEFAULT;
        init.prescale = 4;
        ADC_Init(obj->adc, &init);

        /* Init for single conversion use */
        ADC_InitSingle_TypeDef singleInit = ADC_INITSINGLE_DEFAULT;

        /* Measure input channel with Vdd reference. */
        singleInit.reference = adcRefVDD;
        singleInit.resolution = adcRes12Bit;
        singleInit.acqTime = adcAcqTime32;

        ADC_InitSingle(obj->adc, &singleInit);

        adc_initialized = 1;
    }
}
示例#5
0
/**************************************************************************//**
 * @brief  Read touchscreen X or Y position (12bit resolution)
 * @param[in] ch X (ADC_X) or Y (ADC_Y) touchscreen readout
 * @return Touchscreen X or Y position
 *****************************************************************************/
static uint32_t getTouchChSample12bit( ADC_SingleInput_TypeDef ch )
{
  int i;
  uint32_t value, min, max, acc;

  if ( ch == ADC_X )
  {
    GPIO_PinModeSet(LCD_TOUCH_Y1, gpioModePushPull, 0);
    GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModePushPull, 1);
    GPIO_PinModeSet(LCD_TOUCH_X1, gpioModeInput, 0);
    GPIO_PinModeSet(LCD_TOUCH_X2, gpioModeInput, 0);
  }
  else
  {
    GPIO_PinModeSet(LCD_TOUCH_X1, gpioModePushPull, 1);
    GPIO_PinModeSet(LCD_TOUCH_X2, gpioModePushPull, 0);
    GPIO_PinModeSet(LCD_TOUCH_Y1, gpioModeInput, 0);
    GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModeInput, 0);
  }

  sInit.input = ch;
  ADC_InitSingle(ADC0, &sInit);

  delayUs( 10 );
  acc = 0;
  max = 0;
  min = 4096;
  for ( i=0; i<5; i++ )
  {
    value = readAdc();
    acc += value;
    min = EFM32_MIN( min, value );
    max = EFM32_MAX( max, value );
  }
  /* Throw away largest and smallest sample */
  acc = acc - min - max;
  /* Average */
  acc = acc / 3;

  if ( ch == ADC_X )
  {
    GPIO_PinModeSet(LCD_TOUCH_Y1, gpioModeInput, 0);
    GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModeInput, 0);
  }
  else
  {
    GPIO_PinModeSet(LCD_TOUCH_X1, gpioModeInput, 0);
    GPIO_PinModeSet(LCD_TOUCH_X2, gpioModeInput, 0);
  }

  return acc;
}
/**************************************************************************//**
 * @brief  Main function
 * Main is called from __iar_program_start, see assembly startup file
 *****************************************************************************/
int main(void)
{  
  /* Initialize chip */
  CHIP_Init();
  
  /* Enable clock for GPIO module */
  CMU_ClockEnable(cmuClock_GPIO, true);
  
  /* Enable clock for ADC0 module */
  CMU_ClockEnable(cmuClock_ADC0, true);
  
  /* Enable clock for PRS module */
  CMU_ClockEnable(cmuClock_PRS, true);
  
  /* Configure PD8 as an input for PB0 button with filter enable (out = 1)*/
  GPIO_PinModeSet(gpioPortD, 8, gpioModeInput, 1); 
  
  /* Select PD8 as PRS output */
  GPIO->EXTIPSELH = (GPIO->EXTIPSELH & !_GPIO_EXTIPSELH_EXTIPSEL8_MASK ) | GPIO_EXTIPSELH_EXTIPSEL8_PORTD;
  
  /* Enable PRS sense */
  GPIO->INSENSE = GPIO->INSENSE | GPIO_INSENSE_PRS;
  
  /* Select GPIO as source and GPIOPIN8 as signal (falling edge) */
  PRS_SourceSignalSet(0, PRS_CH_CTRL_SOURCESEL_GPIOH, PRS_CH_CTRL_SIGSEL_GPIOPIN8, prsEdgeNeg);

  /* Initialize ADC common parts for both single conversion and scan sequence */
  ADC_Init(ADC0, &ADCInit);
  
  /* Initialize ADC single sample conversion */
  ADC_InitSingle(ADC0, &ADCInitSingle);
  
  /* Enable ADC Interrupt when Single Conversion Complete */
  ADC0->IEN = ADC_IEN_SINGLE;
  
  /* Enable ADC interrupt vector in NVIC*/
  NVIC_EnableIRQ(ADC0_IRQn);
   
  while(1)
  {
    /* Enter EM1 */ 
    EMU_EnterEM1();
    
    /* After ADC Single conversion wake up -> Delay 1000mS */  
    Delay(1000);
  }
}
示例#7
0
文件: inttemp.c 项目: havardh/bitless
/**************************************************************************//**
 * @brief Initialize ADC for temperature sensor readings in single poin
 *****************************************************************************/
void setupSensor(void)
{
  /* Base the ADC configuration on the default setup. */
  ADC_Init_TypeDef init = ADC_INIT_DEFAULT;
  ADC_InitSingle_TypeDef sInit = ADC_INITSINGLE_DEFAULT;

  /* Initialize timebases */
  init.timebase = ADC_TimebaseCalc(0);
  init.prescale = ADC_PrescaleCalc(400000,0);
  ADC_Init(ADC0, &init);

  /* Set input to temperature sensor. Reference must be 1.25V */
  sInit.reference = adcRef1V25;
  sInit.input = adcSingleInpTemp;
  ADC_InitSingle(ADC0, &sInit);

  /* Setup interrupt generation on completed conversion. */
  ADC_IntEnable(ADC0, ADC_IF_SINGLE);
  NVIC_EnableIRQ(ADC0_IRQn);
}
示例#8
0
/**************************************************************************//**
 * @brief Configure TIMER to trigger ADC through PRS at a set sample rate
 *****************************************************************************/
void setupAdc(void)
{
  ADC_Init_TypeDef        adcInit       = ADC_INIT_DEFAULT;
  ADC_InitSingle_TypeDef  adcInitSingle = ADC_INITSINGLE_DEFAULT;
  
  /* Configure ADC single mode to sample Ref/2 */
  adcInit.prescale = ADC_PrescaleCalc(7000000, 0); /* Set highest allowed prescaler */
  ADC_Init(ADC0, &adcInit);
  
  adcInitSingle.input     =  adcSingleInpVrefDiv2;  /* Reference */
  adcInitSingle.prsEnable = true;                  
  adcInitSingle.prsSel    = adcPRSSELCh0;           /* Triggered by PRS CH0 */
  ADC_InitSingle(ADC0, &adcInitSingle);
  
  /* Connect PRS channel 0 to TIMER overflow */
  PRS_SourceSignalSet(0, PRS_CH_CTRL_SOURCESEL_TIMER0, PRS_CH_CTRL_SIGSEL_TIMER0OF, prsEdgeOff);
  
  /* Configure TIMER to trigger 100 kHz sampling rate */
  TIMER_TopSet(TIMER0,  CMU_ClockFreqGet(cmuClock_TIMER0)/ADCSAMPLESPERSEC);
  TIMER_Enable(TIMER0, true);
}
示例#9
0
文件: InitDevice.c 项目: kqzca/prj
//================================================================================
// ADC0_enter_DefaultMode_from_RESET
//================================================================================
extern void ADC0_enter_DefaultMode_from_RESET(void) {

	// $[ADC0_Init]
	ADC_Init_TypeDef ADC0_init = ADC_INIT_DEFAULT;

	ADC0_init.ovsRateSel = adcOvsRateSel2;
	ADC0_init.warmUpMode = adcWarmupNormal;
	ADC0_init.timebase = ADC_TimebaseCalc(0);
	ADC0_init.prescale = ADC_PrescaleCalc(7000000, 0);
	ADC0_init.tailgate = 0;
	ADC0_init.em2ClockConfig = adcEm2Disabled;

	ADC_Init(ADC0, &ADC0_init);
	// [ADC0_Init]$

	// $[ADC0_InputConfiguration]
	ADC_InitSingle_TypeDef ADC0_init_single = ADC_INITSINGLE_DEFAULT;

	/* PRS settings */
	ADC0_init_single.prsEnable = 0;
	ADC0_init_single.prsSel = adcPRSSELCh0;
	/* Input(s) */
	ADC0_init_single.diff = 0;
	ADC0_init_single.posSel = adcPosSelAPORT1XCH10;
	ADC0_init_single.negSel = adcNegSelVSS;
	ADC0_init_single.reference = adcRef2V5;
	/* Generic conversion settings */
	ADC0_init_single.acqTime = adcAcqTime1;
	ADC0_init_single.resolution = adcRes12Bit;
	ADC0_init_single.leftAdjust = 0;
	ADC0_init_single.rep = 0;
	ADC0_init_single.singleDmaEm2Wu = 0;
	ADC0_init_single.fifoOverwrite = 0;

	ADC_InitSingle(ADC0, &ADC0_init_single);
	// [ADC0_InputConfiguration]$

}
示例#10
0
/***************************************************************************//**
 * @brief
 *   Configure ADC usage for this application.
 *******************************************************************************/
void initAdc(void)
{
  ADC_Init_TypeDef init = ADC_INIT_DEFAULT;
  ADC_InitSingle_TypeDef singleInit = ADC_INITSINGLE_DEFAULT;
  
  /* Init common issues for both single and scan mode */
  /* TIMERBASE should be set >= 1us for ADC warmup */
  /* When HFPERCLK is running at 48MHz, the maximum TIMERBASE */
  /* is (0x1f + 1) x 1/48M = 6.67us, less (1 - 0.67) = 0.33us if VDD as ref */
  /* If using internal ref, 6 x 0.67us = 4us, less (6 - 4) = 2us */
  /* Use acquisition time in channel configuration to compensate TIMEBASE */ 
  init.ovsRateSel = adcOvsRateSel16; 
  init.prescale = ADC_PrescaleCalc(ADC_CLOCK, 0);
  ADC_Init(ADC0, &init);

  /* Init for single conversion use, enable PRS channel for ADC */
  /* Default reference voltage is 1.25V */
  /* Internal ref, compensate 2us = 24 ADC clock + 1 = 25 minimum */
  singleInit.acqTime = adcAcqTime32;
#if ADC_REF_SELECT == 1
  /* Set reference voltage to 2.5V */
  singleInit.reference = adcRef2V5;
#elif ADC_REF_SELECT == 2
  /* Set reference voltage to VDD */
  singleInit.reference = adcRefVDD;
  /* VDD ref, compensate 0.33us = 4 ADC clock + 1 = 5 minimum */
  singleInit.acqTime = adcAcqTime8;
#endif
  singleInit.prsSel = ADC_PRS_SEL;
  singleInit.leftAdjust = true;
  singleInit.input = ADC_CHANNEL;
#if ADC_OVS_16 == 1
  /* Use oversampling to 16 bit resolution */
  singleInit.resolution = adcResOVS;
#endif
  
  ADC_InitSingle(ADC0, &singleInit);
}
示例#11
0
/**************************************************************************//**
 * @brief  Check if touch screen is "touched"
 * @return true if screen touched
 *****************************************************************************/
static bool touched( void )
{
  uint32_t adcValue;

  GPIO_PinModeSet(LCD_TOUCH_X1, gpioModePushPull, 0);
  GPIO_PinModeSet(LCD_TOUCH_X2, gpioModePushPull, 1);
  GPIO_PinModeSet(LCD_TOUCH_Y1, gpioModeInput, 0);

  GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModePushPull, 1);
  delayUs( 10 );
  GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModeInputPull, 1);
  delayUs( 10 );

  sInit.input = ADC_Y;
  ADC_InitSingle(ADC0, &sInit);

  adcValue = readAdc();

  GPIO_PinModeSet(LCD_TOUCH_X1, gpioModeInput, 0);
  GPIO_PinModeSet(LCD_TOUCH_X2, gpioModeInput, 0);
  GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModeInput, 0);

  return ( adcValue < 3800 ) ? true : false;
}
示例#12
0
/**************************************************************************//**
 * @brief Configure ADC for single conversions
 *****************************************************************************/
static void ADCConfig(void)
{
  ADC_Init_TypeDef       init       = ADC_INIT_DEFAULT;
  ADC_InitSingle_TypeDef singleInit = ADC_INITSINGLE_DEFAULT;

  /* Init common settings for both single conversion and scan mode */
  init.timebase = ADC_TimebaseCalc(0);

  /* Might as well finish conversion as quickly as possibly since polling */
  /* for completion. Set ADC clock to 7 MHz, use default HFPERCLK */
  init.prescale = ADC_PrescaleCalc(7000000, 0);

  /* WARMUPMODE must be set to Normal according to ref manual before
   * entering EM2. In this example, the warmup time is not a big problem
   * due to relatively infrequent polling. Leave at default NORMAL, */
  ADC_Init(ADC0, &init);

  /* Init for single conversion use, measure DAC output with 1.25 reference. */
  singleInit.reference = adcRef1V25;

#ifdef EXTERNAL
  /* ADC channel 3 as ADC input */
  singleInit.input = adcSingleInpCh3;
#else
  /* DAC otput channel 0 as ADC input */
  singleInit.input = adcSingleInpDACOut0;
#endif

  singleInit.resolution = adcRes12Bit;

  /* The datasheet specifies a minimum aquisition time when sampling vdd/3 */
  /* 32 cycles should be safe for all ADC clock frequencies */
  singleInit.acqTime = adcAcqTime32;

  ADC_InitSingle(ADC0, &singleInit);
}
示例#13
0
文件: adc.c 项目: Spike0/Contiki_my
uint16_t adc_get_value(uint8_t u8_adc_channel, ADC_Ref_TypeDef adcref)
{
  ADC_InitSingle_TypeDef sInit = ADC_INITSINGLE_DEFAULT;
  uint32_t rawvalue = 0;

  /* Set reference  */
  sInit.reference = adcref;
  sInit.input = u8_adc_channel;
  ADC_InitSingle(ADC0, &sInit);

  _u8_conv_complete = 0;

  ADC_Start(ADC0, adcStartSingle);
  /* Wait in EM1 for ADC to complete */
  EMU_EnterEM1();

  // Make sure it's ADC interrupt
  // TODO : timeout
  while(_u8_conv_complete == 0);

  rawvalue = ADC_DataSingleGet(ADC0);

  return (uint16_t) rawvalue;
}
示例#14
0
/***************************************************************************//**
 * @brief
 *	Initialize touch panel driver
 *
 * @param config
 *	Driver configuration data.
 ******************************************************************************/
void TOUCH_Init(TOUCH_Config_TypeDef *config)
{
  ADC_Init_TypeDef init = ADC_INIT_DEFAULT;
#ifndef TOUCH_WITHOUT_STORE
  touch_LoadCalibration();
#endif
  CMU_ClockEnable(cmuClock_ADC0, true);
  ADC_IntDisable(ADC0, _ADC_IF_MASK);
  init.prescale     = ADC_PrescaleCalc(config->frequency, 0);
  touch_ignore_move = config->ignore;
  init.ovsRateSel   = config->oversampling;
  ADC_Init(ADC0, &init);
  BSP_PeripheralAccess(BSP_TOUCH, true);
  sInit.input      = ADC_Y;
  sInit.reference  = adcRefVDD;
  sInit.resolution = adcResOVS;
  ADC_InitSingle(ADC0, &sInit);
  ADC_IntClear(ADC0, _ADC_IF_MASK);
  touch_state = TOUCH_INIT;
  NVIC_ClearPendingIRQ(ADC0_IRQn);
  NVIC_EnableIRQ(ADC0_IRQn);
  ADC_IntEnable(ADC0, ADC_IF_SINGLE);
  ADC_Start(ADC0, adcStartSingle);
}
示例#15
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  ADC_Init_TypeDef init = ADC_INIT_DEFAULT;
  ADC_InitSingle_TypeDef singleInit = ADC_INITSINGLE_DEFAULT;
  uint32_t sample;
  uint32_t vpot;
  uint32_t rpot;
  SYSTEM_ChipRevision_TypeDef chipRev;
  int errataShift = 0;

  /* Chip revision alignment and errata fixes */
  CHIP_Init();

  /* ADC errata for rev B when using VDD as reference, need to multiply */
  /* result by 2 */
  SYSTEM_ChipRevisionGet(&chipRev);
  if ((chipRev.major == 1) && (chipRev.minor == 1))
  {
    errataShift = 1;
  }

  /* Initialize DVK board register access */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Connect potentiometer to EFM32 (and ensure ambient light sensor */
  /* sharing same ADC channel is not enabled). */
  BSP_PeripheralAccess(BSP_AMBIENT, false);
  BSP_PeripheralAccess(BSP_POTMETER, true);

  /* Enable clocks required */
  CMU_ClockEnable(cmuClock_HFPER, true);
  CMU_ClockEnable(cmuClock_ADC0, true);

  /* Init common issues for both single conversion and scan mode */
  init.timebase = ADC_TimebaseCalc(0);
  /* Might as well finish conversion as quickly as possibly since polling */
  /* for completion. */
  init.prescale = ADC_PrescaleCalc(7000000, 0);
  /* WARMUPMODE must be set to Normal according to ref manual before */
  /* entering EM2. In this example, the warmup time is not a big problem */
  /* due to relatively infrequent polling. Leave at default NORMAL, */
  ADC_Init(ADC0, &init);

  /* Init for single conversion use. */
  singleInit.reference = adcRefVDD;
  singleInit.input = adcSingleInpCh5; /* According to DVK HW design */
  singleInit.resolution = adcRes8Bit; /* Use at least 8 bit since unlinear voltage */
  ADC_InitSingle(ADC0, &singleInit);

  /* Ensure internal reference settled */
  RTCDRV_Trigger(1, NULL);
  EMU_EnterEM2(true);

  /* Main loop - just check potentiometer and update LEDs */
  while (1)
  {
    ADC_IntClear(ADC0, ADC_IF_SINGLE);
    ADC_Start(ADC0, adcStartSingle);

    /* Wait for completion */
    while (!(ADC_IntGet(ADC0) & ADC_IF_SINGLE));
    sample = ADC_DataSingleGet(ADC0) << errataShift;

    /*
      DVK potentiometer design:

               | Vdd = 3.3V
              +-+
              | | Rpullup = 10kOhm
              +-+
               |
               +------> Vpot (to ADC)
               |
              +-+
              | | Rpot = 0-100kOhm
              +-+
               | Gnd

       Vpot = Rpot * Vdd / (Rpullup + Rpot)

       This gives a non-linear voltage level measured by ADC with respect to
       pot meter position. In order to determine the actual Rpot setting, which
       is linear with respect to position, rewrite the above formula to:

       Rpot = Rpullup * Vpot / (Vdd - Vpot)
    */

    /* Vpot sampled with 8 bit, divide by max value */
    vpot = (POTENTIOMETER_VDD_mV * sample) / 0xff;

    /* Calculate Rpot determining volume */
    rpot = (POTENTIOMETER_PULLUP_OHM * vpot) / (POTENTIOMETER_VDD_mV - vpot);
    /* The potentiometer may not be exact in upper range, make sure we don't use a higher */
    /* value than assumed by defines. */
    if (rpot > POTENTIOMETER_MAX_OHM)
    {
      rpot = POTENTIOMETER_MAX_OHM;
    }

    /* We have 16 LEDs, add half interval for improving rounding effects. */
    rpot += (POTENTIOMETER_MAX_OHM / (16 * 2));

    BSP_LedsSet((uint16_t)((1 << ((16 * rpot) / POTENTIOMETER_MAX_OHM)) - 1));

    /* Wait some time before polling again */
    RTCDRV_Trigger(100, NULL);
    EMU_EnterEM2(true);
  }
}
示例#16
0
/***************************************************************************//**
 * @brief
 *   Calibrate offset and gain for the specified reference.
 *   Supports currently only single ended gain calibration.
 *   Could easily be expanded to support differential gain calibration.
 *
 * @details
 *   The offset calibration routine measures 0 V with the ADC, and adjust
 *   the calibration register until the converted value equals 0.
 *   The gain calibration routine needs an external reference voltage equal
 *   to the top value for the selected reference. For example if the 2.5 V
 *   reference is to be calibrated, the external supply must also equal 2.5V.
 *
 * @param[in] adc
 *   Pointer to ADC peripheral register block.
 *
 * @param[in] ref
 *   Reference used during calibration. Can be both external and internal
 *   references.
 *
 * @param[in] input
 *   Input channel used during calibration.
 *
 * @return
 *   The final value of the calibration register, note that the calibration
 *   register gets updated with this value during the calibration.
 *   No need to load the calibration values after the function returns.
 ******************************************************************************/
rt_uint32_t efm32_adc_calibration(
	ADC_TypeDef 			*adc, 
	ADC_Ref_TypeDef			ref,
	ADC_SingleInput_TypeDef	input)
{
	rt_uint32_t 	cal;
	rt_int32_t 		sample;
	rt_int8_t 		high, mid, low, tmp;
	ADC_InitSingle_TypeDef singleInit 	= ADC_INITSINGLE_DEFAULT;

	/* Init for single conversion use, measure diff 0 with selected reference. */
	singleInit.reference 	= ref;
	singleInit.input 		= adcSingleInpDiff0;
	singleInit.acqTime 		= adcAcqTime32;
	singleInit.diff 		= true;
	/* Enable oversampling rate */
	singleInit.resolution	= adcResOVS;
	ADC_InitSingle(adc, &singleInit);

	/* ADC is now set up for offset calibration */
	/* Offset calibration register is a 7 bit signed 2's complement value. */
	/* Use unsigned indexes for binary search, and convert when calibration */
	/* register is written to. */
	high = 63;
	low = -64;

	/* Do binary search for offset calibration*/
	while (low < high)
	{
		/* Calculate midpoint */
		mid = low + (high - low) / 2;

		/* Midpoint is converted to 2's complement and written to both scan and */
		/* single calibration registers */
		cal = adc->CAL & ~(_ADC_CAL_SINGLEOFFSET_MASK | _ADC_CAL_SCANOFFSET_MASK);
		tmp = mid < 0 ? (mid & 0x3F ^ 0x3F | 0x40) + 1 : mid;
		cal |= tmp << _ADC_CAL_SINGLEOFFSET_SHIFT;
		cal |= tmp << _ADC_CAL_SCANOFFSET_SHIFT;
#ifdef RT_ADC_DEBUG
		rt_kprintf("adc->CAL = %x, cal = %x, tmp = %x\n", adc->CAL, cal, tmp);
#endif			
		adc->CAL = cal;

		/* Do a conversion */
		ADC_Start(adc, adcStartSingle);

		/* Wait while conversion is active */
		while (adc->STATUS & ADC_STATUS_SINGLEACT) ;

		/* Get ADC result */
		sample = ADC_DataSingleGet(adc);

		/* Check result and decide in which part of to repeat search */
		/* Calibration register has negative effect on result */
		if (sample < 0)
		{
			/* Repeat search in bottom half. */
			high = mid;
		}
		else if (sample > 0)
		{
			/* Repeat search in top half. */
			low = mid + 1;
		}
		else
		{
			/* Found it, exit while loop */
			break;
		}
	}
#ifdef RT_ADC_DEBUG
	rt_kprintf("adc->CAL = %x\n", adc->CAL);
#endif

	/* Now do gain calibration, only input and diff settings needs to be changed */
	adc->SINGLECTRL &= ~(_ADC_SINGLECTRL_INPUTSEL_MASK | _ADC_SINGLECTRL_DIFF_MASK);
	adc->SINGLECTRL |= (input << _ADC_SINGLECTRL_INPUTSEL_SHIFT);
	adc->SINGLECTRL |= (false << _ADC_SINGLECTRL_DIFF_SHIFT);

	/* ADC is now set up for gain calibration */
	/* Gain calibration register is a 7 bit unsigned value. */
	high = 127;
	low = 0;

	/* Do binary search for gain calibration */
	while (low < high)
	{
		/* Calculate midpoint and write to calibration register */
		mid = low + (high - low) / 2;

		/* Midpoint is converted to 2's complement */
		cal      = adc->CAL & ~(_ADC_CAL_SINGLEGAIN_MASK | _ADC_CAL_SCANGAIN_MASK);
		cal     |= mid << _ADC_CAL_SINGLEGAIN_SHIFT;
		cal     |= mid << _ADC_CAL_SCANGAIN_SHIFT;
#ifdef RT_ADC_DEBUG
		rt_kprintf("adc->CAL = %x, cal = %x, mid = %x\n", adc->CAL, cal, mid);
#endif		
		adc->CAL = cal;

		/* Do a conversion */
		ADC_Start(adc, adcStartSingle);

		/* Wait while conversion is active */
		while (adc->STATUS & ADC_STATUS_SINGLEACT) ;

		/* Get ADC result */
		sample = ADC_DataSingleGet(adc);

		/* Check result and decide in which part to repeat search */
		/* Compare with a value atleast one LSB's less than top to avoid overshooting */
		/* Since oversampling is used, the result is 16 bits, but a couple of lsb's */
		/* applies to the 12 bit result value, if 0xffe is the top value in 12 bit, this */
		/* is in turn 0xffe0 in the 16 bit result. */
		/* Calibration register has positive effect on result */
		if (sample > 0xffd0)
		{
		  /* Repeat search in bottom half. */
		  high = mid;
		}
		else if (sample < 0xffd0)
		{
		  /* Repeat search in top half. */
		  low = mid + 1;
		}
		else
		{
		  /* Found it, exit while loop */
		  break;
		}
	}
#ifdef RT_ADC_DEBUG
	rt_kprintf("adc->CAL = %x\n", adc->CAL);
#endif

	return adc->CAL;
}
示例#17
0
/******************************************************************//**
* @brief
*	Configure ADC device
*
* @details
*
* @note
*
* @param[in] dev
*	Pointer to device descriptor
*
* @param[in] cmd
*	ADC control command
*
* @param[in] args
*	Arguments
*
* @return
*	Error code
*********************************************************************/
static rt_err_t rt_adc_control(
	rt_device_t 	dev, 
	rt_uint8_t 		cmd, 
	void 			*args)
{
	RT_ASSERT(dev != RT_NULL);

	struct efm32_adc_device_t *adc;

	adc = (struct efm32_adc_device_t *)(dev->user_data);

	switch (cmd)
	{
	case RT_DEVICE_CTRL_SUSPEND:
		/* Suspend device */
		dev->flag |= RT_DEVICE_FLAG_SUSPENDED;
		adc->adc_device->CMD = ADC_CMD_SINGLESTOP | ADC_CMD_SCANSTOP;
		break;

	case RT_DEVICE_CTRL_RESUME:
		/* Resume device */
		dev->flag &= ~RT_DEVICE_FLAG_SUSPENDED;
		
		switch (adc->mode)
		{
		case ADC_MODE_SINGLE:
			ADC_Start(adc->adc_device, adcStartSingle);
			break;
		
		case ADC_MODE_SCAN:
			ADC_Start(adc->adc_device, adcStartScan);
			break;
		
		case ADC_MODE_TAILGATE:
			ADC_Start(adc->adc_device, adcStartScanAndSingle);
			break;
		
		default:
			return -RT_ERROR;
		}
		break;

	case RT_DEVICE_CTRL_ADC_MODE:
		{
			/* change device setting */
			struct efm32_adc_control_t *control;

			control = (struct efm32_adc_control_t *)args;

			switch (control->mode)
			{
			case ADC_MODE_SINGLE:
				ADC_InitSingle(adc->adc_device, control->singleInit);
				break;

			case ADC_MODE_SCAN:
				ADC_InitScan(adc->adc_device, control->scanInit);
				break;

			case ADC_MODE_TAILGATE:
				ADC_InitSingle(adc->adc_device, control->singleInit);
				ADC_InitScan(adc->adc_device, control->scanInit);
				break;

			default:
				return -RT_ERROR;
			}

			adc->mode = control->mode;
		}
		break;
		
	case RT_DEVICE_CTRL_ADC_RESULT:
		switch (adc->mode)
		{
		case ADC_MODE_SINGLE:
			while (adc->adc_device->STATUS & ADC_STATUS_SINGLEACT);
			*((rt_uint32_t *)args) = ADC_DataSingleGet(adc->adc_device);
			break;

		case ADC_MODE_SCAN:
			while (adc->adc_device->STATUS & ADC_STATUS_SCANACT);
			*((rt_uint32_t *)args) = ADC_DataScanGet(adc->adc_device);
			break;

		case ADC_MODE_TAILGATE:
			while (adc->adc_device->STATUS & ADC_STATUS_SCANACT);
			*((rt_uint32_t *)args) = ADC_DataScanGet(adc->adc_device);
			
			while (adc->adc_device->STATUS & ADC_STATUS_SINGLEACT);
			*((rt_uint32_t *)args + 1) = ADC_DataSingleGet(adc->adc_device);
			break;

		default:
			return -RT_ERROR;
		}
		break;
	}

	return RT_EOK;
}
示例#18
0
/***************************************************************************//**
 * @brief
 *   Configure ADC usage for this application.
 *******************************************************************************/
static void preampADCConfig(void)
{
  DMA_CfgDescr_TypeDef descrCfg;
  DMA_CfgChannel_TypeDef chnlCfg;
  ADC_Init_TypeDef init = ADC_INIT_DEFAULT;
  ADC_InitSingle_TypeDef singleInit = ADC_INITSINGLE_DEFAULT;
  ADC_InitScan_TypeDef scanInit = ADC_INITSCAN_DEFAULT;

  /* Configure DMA usage by ADC */

  cbInData.cbFunc = preampDMAInCb;
  cbInData.userPtr = NULL;

  chnlCfg.highPri = true;
  chnlCfg.enableInt = true;
  chnlCfg.select = DMAREQ_ADC0_SCAN;
  chnlCfg.cb = &cbInData;
  DMA_CfgChannel(PREAMP_DMA_AUDIO_IN, &chnlCfg);

  descrCfg.dstInc = dmaDataInc2;
  descrCfg.srcInc = dmaDataIncNone;
  descrCfg.size = dmaDataSize2;
  descrCfg.arbRate = dmaArbitrate1;
  descrCfg.hprot = 0;
  DMA_CfgDescr(PREAMP_DMA_AUDIO_IN, true, &descrCfg);
  DMA_CfgDescr(PREAMP_DMA_AUDIO_IN, false, &descrCfg);

  DMA_ActivatePingPong(PREAMP_DMA_AUDIO_IN,
                       false,
                       preampAudioInBuffer1,
                       (void *)((uint32_t)&(ADC0->SCANDATA)),
                       (PREAMP_AUDIO_BUFFER_SIZE * 2) - 1,
                       preampAudioInBuffer2,
                       (void *)((uint32_t)&(ADC0->SCANDATA)),
                       (PREAMP_AUDIO_BUFFER_SIZE * 2) - 1);

  /* Indicate starting with primary in-buffer (according to above DMA setup) */
  preampProcessPrimary = true;

  /* Configure ADC */

  /* Keep warm due to "high" frequency sampling */
  init.warmUpMode = adcWarmupKeepADCWarm;
  /* Init common issues for both single conversion and scan mode */
  init.timebase = ADC_TimebaseCalc(0);
  init.prescale = ADC_PrescaleCalc(4000000, 0);
  /* Sample potentiometer by tailgating in order to not disturb fixed rate */
  /* audio sampling. */
  init.tailgate = true;
  ADC_Init(ADC0, &init);

  /* Init for single conversion use (potentiometer). */
  singleInit.reference = adcRefVDD;
  singleInit.input = adcSingleInpCh5; /* According to DVK HW design */
  singleInit.resolution = adcRes8Bit; /* Use at least 8 bit since unlinear voltage */
  ADC_InitSingle(ADC0, &singleInit);

  /* Init for scan sequence use (audio in right/left channels). */
  scanInit.prsSel = adcPRSSELCh0;
  scanInit.prsEnable = true;
  scanInit.reference = adcRefVDD;
  scanInit.input = ADC_SCANCTRL_INPUTMASK_CH0 | ADC_SCANCTRL_INPUTMASK_CH1;
  ADC_InitScan(ADC0, &scanInit);
}
示例#19
0
/***************************************************************************//**
 * @brief
 *	Interrupt handler is executed with frequency ~28Hz when panel is not pressed
 *	and with frequency ~140Hz when panel is pressed - this will give ~50 readings per second
 ******************************************************************************/
void ADC0_IRQHandler(void)
{
  switch (touch_state)
  {
  case TOUCH_INIT:   /* enter this state if touch panel is not pressed */
    GPIO_PinModeSet(TOUCH_Y1, gpioModePushPull, 1);
    GPIO_PinModeSet(TOUCH_Y2, gpioModePushPull, 1);
    GPIO_PinModeSet(TOUCH_X1, gpioModeInputPullFilter , 0);
    GPIO_PinModeSet(TOUCH_X2, gpioModeInput, 0);
    sInit.input      = ADC_Y;
    sInit.reference  = adcRefVDD;
    sInit.resolution = adcResOVS;
    sInit.acqTime    = adcAcqTime128;               /* used to slow down */
    if(GPIO_PinInGet(TOUCH_X2))
    {
      touch_state = TOUCH_MEASURE_Y;
      GPIO_PinModeSet(TOUCH_X1, gpioModePushPull, 1);
      GPIO_PinModeSet(TOUCH_X2, gpioModePushPull, 0);
      GPIO_PinModeSet(TOUCH_Y1, gpioModeInput, 0);
      GPIO_PinModeSet(TOUCH_Y2, gpioModeInput, 0);
      sInit.input   = ADC_X;
      sInit.acqTime = adcAcqTime16;                  /* pressed, so speed-up */
    }
    ADC_InitSingle(ADC0, &sInit);
    break;
  case TOUCH_CHECK_PRESS:   /* checks if touch panel is still pressed */
    if( GPIO_PinInGet(TOUCH_X2) )
    {
      touch_state = TOUCH_MEASURE_Y;
      GPIO_PinModeSet(TOUCH_X1, gpioModePushPull, 1);
      GPIO_PinModeSet(TOUCH_X2, gpioModePushPull, 0);
      GPIO_PinModeSet(TOUCH_Y1, gpioModeInput, 0);
      GPIO_PinModeSet(TOUCH_Y2, gpioModeInput, 0);
      sInit.input   = ADC_X;
      sInit.acqTime = adcAcqTime16;                  /* pressed, so speed-up */
      ADC_InitSingle(ADC0, &sInit);
      current_pos.pen = newpos.pen;
      TOUCH_RecalculatePosition(&newpos);
      if (newpos.pen)
      {
        int call_upcall = TOUCH_StateChanged();
        if (call_upcall)
        {
          current_pos.x = newpos.x;
          current_pos.y = newpos.y;
        }
        current_pos.adcx = newpos.adcx;
        current_pos.adcy = newpos.adcy;
        current_pos.pen  = 1;
        if (call_upcall) TOUCH_CallUpcall();
      }
      newpos.pen = 1;
    }
    else
    {
      touch_state     = TOUCH_INIT;
      newpos.pen      = 0;
      current_pos.pen = 0;
      TOUCH_CallUpcall();
    }
    break;
  case TOUCH_MEASURE_Y:                                             /* touch panel pressed, measure Y position */
    newpos.adcy = (ADC_DataSingleGet(ADC0) + 31) >> 6;              /* reduce ADC resolution to 10-bits */
    GPIO_PinModeSet(TOUCH_Y1, gpioModePushPull, 0);                 /* to avoid overflow in calibration routines */
    GPIO_PinModeSet(TOUCH_Y2, gpioModePushPull, 1);
    GPIO_PinModeSet(TOUCH_X1, gpioModeInput, 0);
    GPIO_PinModeSet(TOUCH_X2, gpioModeInput, 0);
    sInit.input = ADC_Y;
    ADC_InitSingle(ADC0, &sInit);
    touch_state = TOUCH_MEASURE_X;
    break;
  case TOUCH_MEASURE_X:   /* touch panel pressed, measure X position */
    newpos.adcx = (ADC_DataSingleGet(ADC0) + 31) >> 6;
    GPIO_PinModeSet(TOUCH_Y1, gpioModePushPull, 1);
    GPIO_PinModeSet(TOUCH_Y2, gpioModePushPull, 1);
    GPIO_PinModeSet(TOUCH_X1, gpioModeInputPullFilter , 0);
    GPIO_PinModeSet(TOUCH_X2, gpioModeInput, 0);
    sInit.input = ADC_Y;
    ADC_InitSingle(ADC0, &sInit);
    touch_state = TOUCH_CHECK_PRESS;
    break;
  default: touch_state = TOUCH_INIT;
  }
  ADC_IntClear(ADC0, ADC_IF_SINGLE);
  ADC_Start(ADC0, adcStartSingle);
}
/***************************************************************************//**
 * @brief
 *   Calibrate offset and gain for the specified reference.
 *   Supports currently only single ended gain calibration.
 *   Could easily be expanded to support differential gain calibration.
 *
 * @details
 *   The offset calibration routine measures 0 V with the ADC, and adjust
 *   the calibration register until the converted value equals 0.
 *   The gain calibration routine needs an external reference voltage equal
 *   to the top value for the selected reference. For example if the 2.5 V
 *   reference is to be calibrated, the external supply must also equal 2.5V.
 *
 * @param[in] adc
 *   Pointer to ADC peripheral register block.
 *
 * @param[in] ref
 *   Reference used during calibration. Can be both external and internal
 *   references.
 *
 * @return
 *   The final value of the calibration register, note that the calibration
 *   register gets updated with this value during the calibration.
 *   No need to load the calibration values after the function returns.
 ******************************************************************************/
uint32_t ADC_Calibration(ADC_TypeDef *adc, ADC_Ref_TypeDef ref)
{
  int32_t  sample;
  uint32_t cal;

  /* Binary search variables */
  uint8_t high;
  uint8_t mid;
  uint8_t low;

  /* Reset ADC to be sure we have default settings and wait for ongoing */
  /* conversions to be complete. */
  ADC_Reset(adc);

  ADC_Init_TypeDef       init       = ADC_INIT_DEFAULT;
  ADC_InitSingle_TypeDef singleInit = ADC_INITSINGLE_DEFAULT;

  /* Init common settings for both single conversion and scan mode */
  init.timebase = ADC_TimebaseCalc(0);
  /* Might as well finish conversion as quickly as possibly since polling */
  /* for completion. */
  /* Set ADC clock to 7 MHz, use default HFPERCLK */
  init.prescale = ADC_PrescaleCalc(7000000, 0);

  /* Set an oversampling rate for more accuracy */
  init.ovsRateSel = adcOvsRateSel4096;
  /* Leave other settings at default values */
  ADC_Init(adc, &init);

  /* Init for single conversion use, measure diff 0 with selected reference. */
  singleInit.reference = ref;
  singleInit.input     = adcSingleInpDiff0;
  singleInit.acqTime   = adcAcqTime16;
  singleInit.diff      = true;
  /* Enable oversampling rate */
  singleInit.resolution = adcResOVS;

  ADC_InitSingle(adc, &singleInit);

  /* ADC is now set up for offset calibration */
  /* Offset calibration register is a 7 bit signed 2's complement value. */
  /* Use unsigned indexes for binary search, and convert when calibration */
  /* register is written to. */
  high = 128;
  low  = 0;

  /* Do binary search for offset calibration*/
  while (low < high)
  {
    /* Calculate midpoint */
    mid = low + (high - low) / 2;

    /* Midpoint is converted to 2's complement and written to both scan and */
    /* single calibration registers */
    cal      = adc->CAL & ~(_ADC_CAL_SINGLEOFFSET_MASK | _ADC_CAL_SCANOFFSET_MASK);
    cal     |= (mid - 63) << _ADC_CAL_SINGLEOFFSET_SHIFT;
    cal     |= (mid - 63) << _ADC_CAL_SCANOFFSET_SHIFT;
    adc->CAL = cal;

    /* Do a conversion */
    ADC_Start(adc, adcStartSingle);

    /* Wait while conversion is active */
    while (adc->STATUS & ADC_STATUS_SINGLEACT) ;

    /* Get ADC result */
    sample = ADC_DataSingleGet(adc);

    /* Check result and decide in which part of to repeat search */
    /* Calibration register has negative effect on result */
    if (sample < 0)
    {
      /* Repeat search in bottom half. */
      high = mid;
    }
    else if (sample > 0)
    {
      /* Repeat search in top half. */
      low = mid + 1;
    }
    else
    {
      /* Found it, exit while loop */
      break;
    }
  }

  /* Now do gain calibration, only input and diff settings needs to be changed */
  adc->SINGLECTRL &= ~(_ADC_SINGLECTRL_INPUTSEL_MASK | _ADC_SINGLECTRL_DIFF_MASK);
  adc->SINGLECTRL |= (adcSingleInpCh4 << _ADC_SINGLECTRL_INPUTSEL_SHIFT);
  adc->SINGLECTRL |= (false << _ADC_SINGLECTRL_DIFF_SHIFT);

  /* ADC is now set up for gain calibration */
  /* Gain calibration register is a 7 bit unsigned value. */

  high = 128;
  low  = 0;

  /* Do binary search for gain calibration */
  while (low < high)
  {
    /* Calculate midpoint and write to calibration register */
    mid = low + (high - low) / 2;

    /* Midpoint is converted to 2's complement */
    cal      = adc->CAL & ~(_ADC_CAL_SINGLEGAIN_MASK | _ADC_CAL_SCANGAIN_MASK);
    cal     |= mid << _ADC_CAL_SINGLEGAIN_SHIFT;
    cal     |= mid << _ADC_CAL_SCANGAIN_SHIFT;
    adc->CAL = cal;

    /* Do a conversion */
    ADC_Start(adc, adcStartSingle);

    /* Wait while conversion is active */
    while (adc->STATUS & ADC_STATUS_SINGLEACT) ;

    /* Get ADC result */
    sample = ADC_DataSingleGet(adc);

    /* Check result and decide in which part to repeat search */
    /* Compare with a value atleast one LSB's less than top to avoid overshooting */
    /* Since oversampling is used, the result is 16 bits, but a couple of lsb's */
    /* applies to the 12 bit result value, if 0xffe is the top value in 12 bit, this */
    /* is in turn 0xffe0 in the 16 bit result. */
    /* Calibration register has positive effect on result */
    if (sample > 0xffd0)
    {
      /* Repeat search in bottom half. */
      high = mid;
    }
    else if (sample < 0xffd0)
    {
      /* Repeat search in top half. */
      low = mid + 1;
    }
    else
    {
      /* Found it, exit while loop */
      break;
    }
  }

  return adc->CAL;
}
void adc_init(ADC_Reference reference, ADC_Input input, uint32_t adc_frequency)
{
	// Initialises clocks
	CMU_ClockEnable(cmuClock_HFPER, true);
	CMU_ClockEnable(cmuClock_ADC0, true);

	/* Base the ADC configuration on the default setup. */
	ADC_Init_TypeDef init = ADC_INIT_DEFAULT;
	ADC_InitSingle_TypeDef sInit = ADC_INITSINGLE_DEFAULT;

	/* Initialize timebases */
	init.timebase = ADC_TimebaseCalc(0);
	init.prescale = ADC_PrescaleCalc(adc_frequency,0);
	ADC_Init(ADC0, &init);

	switch (reference)
	{
	/** Internal 1.25V reference. */
	case adcReference1V25:
		sInit.reference = adcRef1V25;
		break;

	/** Internal 2.5V reference. */
	case adcReference2V5:
		sInit.reference = adcRef2V5;
		break;

	/** Buffered VDD. */
	case adcReferenceVDD:
		sInit.reference = adcRefVDD;
		break;

	/** Internal differential 5V reference. */
	case adcReference5VDIFF:
		sInit.reference = adcRef5VDIFF;
		break;

	/** Single ended ext. ref. from 1 pin. */
	case adcReferenceExtSingle:
		sInit.reference = adcRefExtSingle;
		break;

	/** Differential ext. ref. from 2 pins */
	case adcReference2xExtDiff:
		sInit.reference = adcRef2xExtDiff;
		break;

	/** Unbuffered 2xVDD. */
	case adcReference2xVDD:
		sInit.reference = adcRef2xVDD;
		break;
	}

	switch (input)
		{
			/** Temperature reference. */
		case adcInputSingleTemp:
			sInit.input = adcSingleInpTemp;
			break;
		/** VDD / 3. */
		case adcInputSingleVDDDiv3:
			sInit.input = adcSingleInpVDDDiv3;
			break;
			/** Positive Ch4, negative Ch5. */
		case adcInputSingleCh4Ch5:
			sInit.input = adcSingleInpCh4Ch5;
			sInit.diff = true;
			break;
		}

	ADC_InitSingle(ADC0, &sInit);

	/* Setup interrupt generation on completed conversion. */
	ADC_IntEnable(ADC0, ADC_IF_SINGLE);
}