예제 #1
0
void _Device_Start_ADC_Conversion(){
    adc_channel_init();
    //adc_second_scan_flag = 0;
    adc_scan_times_flag = 0;
    //adc_4_channel_scan_init();
    ADC1_StartConversion();
}
예제 #2
0
파일: AD.C 프로젝트: wantf/C
void ADSample(void)
{
		u8	i,tttemp;
    ADC1_DeInit();
    ADC1_ConversionConfig(ADC1_CONVERSIONMODE_SINGLE, ADC1_CHANNEL_3, ADC1_ALIGN_RIGHT);
    ADC1_SchmittTriggerConfig(ADC1_SCHMITTTRIG_CHANNEL4,ENABLE);
    ADC1_ITConfig(ADC1_IT_EOCIE,DISABLE);
		ADC1_Cmd(ENABLE);
		ADC1->CSR &= (u8)(~0x80);
		ADC1_StartConversion();		
    while((ADC1->CSR & 0x80)!=0x80) IWDG_ReloadCounter(); // µÈ´ýת»»½áÊø
    Conversion_Value += ADC1_GetConversionValue();
		ADC1->CSR &= (u8)(~0x80);
		u8ADChannelCnt++;
		if(u8ADChannelCnt>=SAMPLE_TIMES)
		{
				u8ADChannelCnt = 0;
				tttemp = (u8)((Conversion_Value>>2)/SAMPLE_TIMES);
				if((tttemp<20) || (tttemp>200) ) u8Temp = OFF_TMP_SET;
				else
				{
						for(i=0;T3580Tab[i]<tttemp;i++);
						u8Temp = (u8)(i+(40*2));
				}
				Conversion_Value = 0;
		}
예제 #3
0
void ADC1_Config()
{
  ADC1_DeInit();

#ifdef EN_SENSOR_MIC
  ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_1, ADC1_PRESSEL_FCPU_D4,
            ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL1, DISABLE);
  ADC1_ScanModeCmd(ENABLE);
#else  
  ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_0, ADC1_PRESSEL_FCPU_D4,
            ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL0, DISABLE);
  ADC1_Cmd(ENABLE);
#endif
  
  //ADC1_ITConfig(ADC1_IT_AWS0, ENABLE);
  
  ADC1_StartConversion();
}
예제 #4
0
// Convert to level: [0..100]
uint8_t als_read()
{
  uint8_t level;
  
  // Wait convert finished
  while(ADC1_GetFlagStatus(ADC1_FLAG_EOC) == RESET);
  // Get value
  uint16_t adc_value = ADC1_GetConversionValue();
  // Clear flag
  ADC1_ClearFlag(ADC1_FLAG_EOC);
  // Start next conversion
  ADC1_StartConversion();
  
  // [0..1023], reversed scale down to [100..0]
  if( adc_value >= 1000 ) {
    level = 0;
  } else {
    level = 100 - adc_value / 10;
  }
  return level;
}
예제 #5
0
파일: pot.c 프로젝트: ns96/InstrasPDC2
	/**
  * @brief  Initializes the ADC. 
	* ADC conversion mode: continious, EOC interrupt enabled
  * @retval : None
  */
	void pot_init(void){
		 /*  Init GPIO for ADC7 */
		GPIO_Init(GPIOB, GPIO_PIN_7, GPIO_MODE_IN_FL_NO_IT);
		
		/* De-Init ADC peripheral*/
		ADC1_DeInit();
	
		/* Init ADC1 peripheral */
		ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_7, ADC1_PRESSEL_FCPU_D18, \
							ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL7,\
							DISABLE);	
	
		/* Enable EOC interrupt */
		ADC1_ITConfig(ADC1_IT_EOCIE,ENABLE);
	
		/* Enable general interrupts */  
		enableInterrupts();
		
		/*Start Conversion */
		ADC1_StartConversion();
		
	}
예제 #6
0
파일: bsp_pm25.c 프로젝트: Roger-WY/tq
/*******************************************************************************
 * 名    称: Bsp_GetPm25AdVal
 * 功    能: 获取PM2.5传感器的AD值
 * 入口参数: 无
 * 出口参数: 无
 * 作  者: Roger-WY
 * 创建日期: 2015-07-20
 * 修    改:
 * 修改日期:
 * 备    注:
 *******************************************************************************/
void Bsp_GetPm25AdVal(u16 *pdata)
{
    u32 sum = 0;
    /***********************************************
    * 描述: 开PM2.5传感器内部LED
    */
    PM25LEDON();
    /***********************************************
    * 描述: 延时280uS
    */
    Bsp_DelayUs(28);
    /***********************************************
    * 描述: 采集PM2.5的数据
    */
    for(u8 i = 0; i < CollectionCnt ; i++ ) {
        sum += ADC1_GetConversionValue();
        ADC1_StartConversion();		/* 软件启动下次ADC转换 */
    }
    *pdata =  (u16)(sum/CollectionCnt);
    /***********************************************
    * 描述:关PM2.5传感器内部LED
    */
    PM25LEDOFF();
}
예제 #7
0
INTERRUPT void ADC1_IRQHandler(void)
{
#endif
        //GPIO_WriteHigh(LED1_PORT, LED1_PIN);
	    ADC1_ClearITPendingBit(ADC1_IT_EOC);  //clear end of conversion flag, for one signal channel
        
        switch(adc_scan_times_flag){
            case 0:
                ADC_Results[0] = ADC1_GetBufferValue(0);
                ADC1->CSR &= (uint8_t)(~ADC1_CSR_CH); /* Clear the ADC1 channels */
                ADC1->CSR |= (uint8_t)(ADC1_CHANNEL_1);/* Select the ADC1 channel */
                ADC1_StartConversion();
                break;
            case 1:
                ADC_Results[1] = ADC1_GetBufferValue(1);
                ADC1->CSR &= (uint8_t)(~ADC1_CSR_CH); /* Clear the ADC1 channels */
                ADC1->CSR |= (uint8_t)(ADC1_CHANNEL_2);/* Select the ADC1 channel */
                ADC1_StartConversion();
                break;
            case 2:
                ADC_Results[2] = ADC1_GetBufferValue(2);
                ADC1->CSR &= (uint8_t)(~ADC1_CSR_CH); /* Clear the ADC1 channels */
                ADC1->CSR |= (uint8_t)(ADC1_CHANNEL_3);/* Select the ADC1 channel */
                ADC1_StartConversion();
                break;
            case 3:
                ADC_Results[3] = ADC1_GetBufferValue(3);
                ADC1->CSR &= (uint8_t)(~ADC1_CSR_CH); /* Clear the ADC1 channels */
                ADC1->CSR |= (uint8_t)(ADC1_CHANNEL_4);/* Select the ADC1 channel */
                ADC1_StartConversion();
                break;
            case 4:
                ADC_Results[4] = ADC1_GetBufferValue(4);
                ADC1->CSR &= (uint8_t)(~ADC1_CSR_CH); /* Clear the ADC1 channels */
                ADC1->CSR |= (uint8_t)(ADC1_CHANNEL_5);/* Select the ADC1 channel */
                ADC1_StartConversion();
                break;
            case 5:
                ADC_Results[0] = ADC1_GetBufferValue(0);
                ADC_Results[1] = ADC1_GetBufferValue(1);
                ADC_Results[2] = ADC1_GetBufferValue(2);
                ADC_Results[3] = ADC1_GetBufferValue(3);
                ADC_Results[4] = ADC1_GetBufferValue(4);
                ADC_Results[5] = ADC1_GetBufferValue(5);
                ADC1->CSR &= (uint8_t)(~ADC1_CSR_CH); /* Clear the ADC1 channels */
                ADC1->CSR |= (uint8_t)(ADC1_CHANNEL_12);/* Select the ADC1 channel */
                    
                ADC1->CR2 &= (uint8_t)(~ADC1_CR2_SCAN); //ADC1_ScanMode   DISABLE
                
                ADC1_StartConversion();                
                break;
            case 6:
                ADC_Results[6] = ADC1_GetConversionValue();
                ADC1->CSR &= (uint8_t)(~ADC1_CSR_CH); /* Clear the ADC1 channels */
                ADC1->CSR |= (uint8_t)(ADC1_CHANNEL_0);/* Select the ADC1 channel */
                
                ADC1->CR2 |= ADC1_CR2_SCAN; //ADC1_ScanMode   ENABLE
                adc_scan_times_flag = 0;
                
                (*Intupt_ADC_Finish_ptr_fuc)();
                break;
            default:
                break;
        }
        
        adc_scan_times_flag++;
    
//    if(adc_second_scan_flag == 0){
//        ADC_Results[0] = ADC1_GetBufferValue(0);
//        ADC_Results[1] = ADC1_GetBufferValue(1);
//        ADC_Results[2] = ADC1_GetBufferValue(2);
//        ADC_Results[3] = ADC1_GetBufferValue(3);
//	    //ADC1_ClearITPendingBit(ADC1_IT_EOC);  //clear end of conversion flag, for one signal channel
//        
//        adc_second_scan_flag = 1;
//        adc_AIN12_channel_init();
//        ADC1_StartConversion();
//        //(*Intupt_ADC_Finish_ptr_fuc)();
//    }else{
//        //adc_second_scan_flag = 0;
//        ADC_Results[4] = ADC1_GetConversionValue(); // for AIN12 values
//	    //ADC1_ClearITPendingBit(ADC1_IT_EOC);  //clear end of conversion flag, for one signal channel
//        //adc_4_channel_scan_init();
//        (*Intupt_ADC_Finish_ptr_fuc)();
//
//    }
  
        //GPIO_WriteLow(LED1_PORT, LED1_PIN);
	return;
}