Пример #1
0
/**
  * @brief  Configure ADC Configuration.
  * @param  None
  * @retval None
  */
void ADC_OVERConfiguration(void)
{
    /* Configure ADC ----------------------------------------------------------*/
    ADC_InitPara ADC_InitStructure;

    ADC_InitStructure.ADC_Mode_Scan = DISABLE ;
    ADC_InitStructure.ADC_Mode_Continuous = DISABLE;
    ADC_InitStructure.ADC_Trig_External = ADC_EXTERNAL_TRIGGER_MODE_NONE;
    ADC_InitStructure.ADC_Data_Align = ADC_DATAALIGN_RIGHT;
    ADC_InitStructure.ADC_Channel_Number = 1;
    ADC_Init(&ADC_InitStructure);

    /* ADC regular channels configuration */
    ADC_RegularChannel_Config(ADC_CHANNEL_10, 1,ADC_SAMPLETIME_55POINT5);

    ADC_OversamplingRatio_Config(ADC_OVERSAMPLING_RATIO_4X);
    ADC_OversamplingShift_Config(ADC_OVERSAMPLING_SHIFT_NONE);
    ADC_Oversampler_Enable(ENABLE);

    /* Enable ADC */
    ADC_Enable(ENABLE);
    ADC_Calibration();

    /* Start ADC Software Conversion */
    ADC_SoftwareStartConv_Enable(ENABLE);
}
Пример #2
0
void adc_init(void)
{	  
    DMA_InitPara DMA_InitStructure;
    ADC_InitPara ADC_InitStructure;
    
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_ADC1, ENABLE);	  

    RCC_ADCCLKConfig(RCC_ADCCLK_APB2_DIV6);

    RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_DMA1, ENABLE);		     

    DMA_InitStructure.DMA_PeripheralBaseAddr = 0x4001244C; 
    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)adcarray; 
    DMA_InitStructure.DMA_DIR = DMA_DIR_PERIPHERALSRC;  
    DMA_InitStructure.DMA_BufferSize = 4;	
    DMA_InitStructure.DMA_PeripheralInc = DMA_PERIPHERALINC_DISABLE;	
    DMA_InitStructure.DMA_MemoryInc = DMA_MEMORYINC_ENABLE;	
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PERIPHERALDATASIZE_HALFWORD; 
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MEMORYDATASIZE_HALFWORD; 
    DMA_InitStructure.DMA_Mode = DMA_MODE_CIRCULAR; 
    DMA_InitStructure.DMA_Priority = DMA_PRIORITY_HIGH;
    DMA_InitStructure.DMA_MTOM = DMA_MEMTOMEM_DISABLE; 
		
    DMA_Init(DMA1_CHANNEL1, &DMA_InitStructure);	 
  
    DMA_Enable(DMA1_CHANNEL1, ENABLE);  
    
  //  ADC_DeInit(&ADC_InitStructure);
		
    ADC_InitStructure.ADC_Mode_Scan = ENABLE;		 
    ADC_InitStructure.ADC_Mode_Continuous = ENABLE;  
    ADC_InitStructure.ADC_Trig_External = ADC_EXTERNAL_TRIGGER_MODE_NONE;  
    ADC_InitStructure.ADC_Data_Align = ADC_DATAALIGN_RIGHT;	
    ADC_InitStructure.ADC_Channel_Number = 4;  
		
    ADC_Init(&ADC_InitStructure);  
    // current?
    ADC_RegularChannel_Config(ADC_CHANNEL_7, 1, ADC_SAMPLETIME_239POINT5);
		// battery channel
    ADC_RegularChannel_Config(ADC_CHANNEL_5, 2, ADC_SAMPLETIME_239POINT5);

    ADC_RegularChannel_Config(ADC_CHANNEL_4, 3, ADC_SAMPLETIME_239POINT5);
    ADC_RegularChannel_Config(ADC_CHANNEL_1, 4, ADC_SAMPLETIME_239POINT5);

    ADC_DMA_Enable(ENABLE);	 
    
    ADC_Enable(ENABLE); 
		
    ADC_Calibration();
    
    ADC_SoftwareStartConv_Enable(ENABLE);  
}
Пример #3
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
    /* Configure System clocks -----------------------------------------------*/
    RCC_Configuration();
    
    /* Configure GPIO ports --------------------------------------------------*/
    GPIO_Configuration();
    
    /* Configure DMA1 channel1 -----------------------------------------------*/
    DMA_DeInit(DMA1_CHANNEL1);
    DMA_InitStructure.DMA_PeripheralBaseAddr = ADC_RDTR_Address;
    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PERIPHERALSRC;
    DMA_InitStructure.DMA_BufferSize = 1;
    DMA_InitStructure.DMA_PeripheralInc = DMA_PERIPHERALINC_DISABLE;
    DMA_InitStructure.DMA_MemoryInc = DMA_MEMORYINC_DISABLE;
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PERIPHERALDATASIZE_HALFWORD;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MEMORYDATASIZE_HALFWORD;
    DMA_InitStructure.DMA_Mode = DMA_MODE_CIRCULAR;
    DMA_InitStructure.DMA_Priority = DMA_PRIORITY_HIGH;
    DMA_InitStructure.DMA_MTOM = DMA_MEMTOMEM_DISABLE;
    DMA_Init(DMA1_CHANNEL1, &DMA_InitStructure);
    
    /* Enable DMA1 channel1 */
    DMA_Enable(DMA1_CHANNEL1, ENABLE);
    
    /* Configure ADC ---------------------------------------------------------*/
    ADC_InitStructure.ADC_Mode_Scan = DISABLE;
    ADC_InitStructure.ADC_Mode_Continuous = ENABLE;
    ADC_InitStructure.ADC_Trig_External = ADC_EXTERNAL_TRIGGER_MODE_NONE;
    ADC_InitStructure.ADC_Data_Align = ADC_DATAALIGN_RIGHT;
    ADC_InitStructure.ADC_Channel_Number = 1;
    ADC_Init(&ADC_InitStructure);
    
    /* Configure ADC regular channelx */ 
    ADC_RegularChannel_Config( BOARD_ADC_CHANNEL, 1, ADC_SAMPLETIME_239POINT5);
    
    /* Enable ADC DMA */
    ADC_DMA_Enable(ENABLE);
    
    /* Enable ADC */
    ADC_Enable(ENABLE);
    
    ADC_Calibration();
     
    /* Start ADC Software Conversion */ 
    ADC_SoftwareStartConv_Enable(ENABLE);
    
    while (1)
    {
    }
}
Пример #4
0
/**
  * @brief  Configure ADC_12B resolution.
  * @param  None
  * @retval None
  */
void ADC_12BConfiguration(void)
{
    /* Configure ADC ----------------------------------------------------------*/
    ADC_InitStructure.ADC_Mode_Scan = DISABLE;
    ADC_InitStructure.ADC_Mode_Continuous = DISABLE;
    ADC_InitStructure.ADC_Trig_External = ADC_EXTERNAL_TRIGGER_MODE_NONE;
    ADC_InitStructure.ADC_Data_Align = ADC_DATAALIGN_RIGHT;
    ADC_InitStructure.ADC_Channel_Number = 1;
    ADC_Init(&ADC_InitStructure);

    /* Configure ADC regular channel10 */
    ADC_RegularChannel_Config(ADC_CHANNEL_10, 1, ADC_SAMPLETIME_55POINT5);
    /* Enable ADC DMA */
    ADC_DMA_Enable(ENABLE);
    ADC_Resolution_Config(ADC_RESOLUTION_12B);
    /* Enable ADC */
    ADC_Enable(ENABLE);
    ADC_Calibration();
    /* Start ADC Software Conversion */
    ADC_SoftwareStartConv_Enable(ENABLE);
}