AnsweredAssumed Answered

K60 ADC's value read problem

Question asked by kk kk on May 27, 2014
Latest reply on Jul 9, 2014 by Hui_Ma

I enable ADC1_DP1 & ADC2_DP0. I get the ADC key value by my code successfully. But I don't know how to enable multi-ADC pins, such as ADC1_DP1,ADC1_DP3,ADC1_SE18,ADC1_SE23. How do I get each single ADC pin value? Here is my code. Thanks a lot.

 

void api_ADC_Init(void)

{

  SIM_SCGC3 |= SIM_SCGC3_ADC1_MASK;

  ADC1_SC3 |= 0x80;//ADC1 self-calibration

  while(ADC1_SC3&0x80)

  _time_delay(100);

  ADC1_CFG1 = ADC_CFG1_ADICLK(0) | ADC_CFG1_ADIV(1) | ADC_CFG1_MODE(2);

  ADC1_SC2 = 0x00;

  ADC1_SC1A = 0x41;//ADC1_DP1

  SIM_SCGC6 |= SIM_SCGC6_ADC2_MASK;

  ADC2_SC3 |= 0x80;//ADC2 self-calibration

  while(ADC2_SC3&0x80)

  _time_delay(100);

  ADC2_CFG1 = ADC_CFG1_ADICLK(0) | ADC_CFG1_ADIV(1) | ADC_CFG1_MODE(2);

  ADC2_SC2 = 0x00;

  ADC2_SC1A = 0x40;//ADC2_DP0

}

SystemStatus api_GetADCValue(api_ADCChannel_t B_ADCChennel, WORD *Wp_ADCValue)

{

SelectADCConvertChannel((api_ADCChannel_t) B_ADCChennel);

  cl_ForceDelay_us(15);

  if ((B_ADCChennel == api_ADC_CH1)&&(ADC1_SC1A&ADC_SC1_COCO_MASK ))

  {

  *Wp_ADCValue = ADC1_RA;

  ADC1_SC1A = 0x41;//initiate a new conversion

  return OK;

  }

  if ((B_ADCChennel == api_ADC_CH2)&&(ADC2_SC1A&ADC_SC2_COCO_MASK ))

  {

  *Wp_ADCValue = ADC2_RA;

  ADC2_SC1A = 0x40;//initiate a new conversion

  return OK;

  }

  cl_ForceDelay_us(1);

  return NO_DATA;

}

Outcomes