Exemplo n.º 1
0
/**
  * @brief Initializes the ADC1 peripheral according to the specified parameters
  * @param[in] ADC1_ConversionMode: specifies the conversion mode
  * can be one of the values of @ref ADC1_ConvMode_TypeDef.
  * @param[in] ADC1_Channel: specifies the channel to convert
  * can be one of the values of @ref ADC1_Channel_TypeDef.
  * @param[in] ADC1_PrescalerSelection: specifies the ADC1 prescaler
  * can be one of the values of @ref ADC1_PresSel_TypeDef.
  * @param[in] ADC1_ExtTrigger: specifies the external trigger
  * can be one of the values of @ref ADC1_ExtTrig_TypeDef.
  * @param[in] ADC1_ExtTriggerState: specifies the external trigger new state
  * can be one of the values of @ref FunctionalState.
  * @param[in] ADC1_Align: specifies the converted data alignement
  * can be one of the values of @ref ADC1_Align_TypeDef.
  * @param[in] ADC1_SchmittTriggerChannel: specifies the schmitt trigger channel
  * can be one of the values of @ref ADC1_SchmittTrigg_TypeDef.
  * @param[in] ADC1_SchmittTriggerState: specifies the schmitt trigger state
  * can be one of the values of @ref FunctionalState.
  * @retval None
  */
void ADC1_Init(ADC1_ConvMode_TypeDef ADC1_ConversionMode, ADC1_Channel_TypeDef ADC1_Channel, ADC1_PresSel_TypeDef ADC1_PrescalerSelection, ADC1_ExtTrig_TypeDef ADC1_ExtTrigger, FunctionalState ADC1_ExtTriggerState, ADC1_Align_TypeDef ADC1_Align, ADC1_SchmittTrigg_TypeDef ADC1_SchmittTriggerChannel, FunctionalState ADC1_SchmittTriggerState)
{

    /* Check the parameters */
    assert_param(IS_ADC1_CONVERSIONMODE_OK(ADC1_ConversionMode));
    assert_param(IS_ADC1_CHANNEL_OK(ADC1_Channel));
    assert_param(IS_ADC1_PRESSEL_OK(ADC1_PrescalerSelection));
    assert_param(IS_ADC1_EXTTRIG_OK(ADC1_ExtTrigger));
    assert_param(IS_FUNCTIONALSTATE_OK(((ADC1_ExtTriggerState))));
    assert_param(IS_ADC1_ALIGN_OK(ADC1_Align));
    assert_param(IS_ADC1_SCHMITTTRIG_OK(ADC1_SchmittTriggerChannel));
    assert_param(IS_FUNCTIONALSTATE_OK(ADC1_SchmittTriggerState));

    /*-----------------CR1 & CSR configuration --------------------*/
    /* Configure the conversion mode and the channel to convert
    respectively according to ADC1_ConversionMode & ADC1_Channel values  &  ADC1_Align values */
    ADC1_ConversionConfig(ADC1_ConversionMode, ADC1_Channel, ADC1_Align);
    /* Select the prescaler division factor according to ADC1_PrescalerSelection values */
    ADC1_PrescalerConfig(ADC1_PrescalerSelection);

    /*-----------------CR2 configuration --------------------*/
    /* Configure the external trigger state and event respectively
    according to NewState, ADC1_ExtTrigger */
    ADC1_ExternalTriggerConfig(ADC1_ExtTrigger, ADC1_ExtTriggerState);

    /*------------------TDR configuration ---------------------------*/
    /* Configure the schmitt trigger channel and state respectively
    according to ADC1_SchmittTriggerChannel & ADC1_SchmittTriggerNewState  values */
    ADC1_SchmittTriggerConfig(ADC1_SchmittTriggerChannel, ADC1_SchmittTriggerState);

    /* Enable the ADC1 peripheral */
    ADC1->CR1 |= ADC1_CR1_ADON;

}
Exemplo n.º 2
0
Arquivo: AD.C Projeto: 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;
		}