cancel
Showing results for 
Search instead for 
Did you mean: 

ADC 1

greg_t
Associate II
Posted on July 30, 2010 at 12:17

ADC 1

4 REPLIES 4
raptorhal2
Lead
Posted on May 17, 2011 at 14:00

Post your code so we can see if everything is initialized properly.

Cheers, Hal

greg_t
Associate II
Posted on May 17, 2011 at 14:00

/* Enable ADC1 clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

// RC5 - analog input - ADC

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

  GPIO_Init (GPIOC, &GPIO_InitStructure);

  

ADC_InitTypeDef ADC_InitStructure;

  

  ADC_DeInit(ADC1);

  

// ADC Structure Initialization

  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

  ADC_InitStructure.ADC_ScanConvMode = DISABLE;

  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; 

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  ADC_InitStructure.ADC_NbrOfChannel = 2;

  // Enable Temperature channel

  ADC_TempSensorVrefintCmd ( ENABLE );

  // Init ADC1

  ADC_Init ( ADC1, &ADC_InitStructure );

ADC_RegularChannelConfig ( ADC1 , ADC_Channel_15 , 1 , ADC_SampleTime_41Cycles5 );

ADC_RegularChannelConfig ( ADC1 , ADC_Channel_16 , 2 , ADC_SampleTime_239Cycles5 );

  // Enable the ADC

  ADC_Cmd ( ADC1, ENABLE );

  // ADC calibration

  // Enable ADC1 reset calibaration register

  ADC_ResetCalibration(ADC1);

  // Check the end of ADC1 reset calibration register

  while(ADC_GetResetCalibrationStatus(ADC1) == SET);

  // Start ADC1 calibaration

  ADC_StartCalibration(ADC1);

  // Check the end of ADC1 calibration

  while(ADC_GetCalibrationStatus(ADC1) == SET);

  

/* Function for ADC1 read

int32_t GetADC1Channel(void)

{

  

  // Start the conversion

  ADC_SoftwareStartConvCmd(ADC1, ENABLE);

  // Wait until conversion completion

  while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);

  

  // Get the conversion value

  return (int32_t)((ADC_GetConversionValue(ADC1)*100)/4095);  // return percentage

}

raptorhal2
Lead
Posted on May 17, 2011 at 14:00

Each ADC has one conversion data register, not one register per channel, so you need to use DMA for two or more channels.

Cheers, Hal

greg_t
Associate II
Posted on May 17, 2011 at 14:00

Thanks