这里是Adc3
#include "adc3.h"
//3õê¼»ˉADC
//ÕaàïÎòÃǽöòÔ1æÔòí¨μàÎaày
void Adc3_Init(void)
{
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE); //ê1ÄüADC3ê±Öó
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3,ENABLE); //ADC3¸′λ
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3,DISABLE); //¸′λ½áêø
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;//¶àá¢Ä£ê½
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;//ὸö2éÑù½×¶ÎÖ®¼äμÄÑó3ù5¸öê±Öó
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; //DMAê§Äü
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;//Ô¤·ÖÆμ4·ÖÆμ¡£ADCCLK=PCLK2/4=84/4=21Mhz,ADCê±Öó×îoÃ2»òa3¬1y36Mhz
ADC_CommonInit(&ADC_CommonInitStructure);//3õê¼»ˉ
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//12λÄ£ê½
ADC_InitStructure.ADC_ScanConvMode = DISABLE;//·Çé¨ÃèÄ£ê½
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;//1رÕá¬Dø×a»»
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//½ûÖ1′¥·¢¼ì2a£¬ê1óÃèí¼t′¥·¢
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//óò¶ÔÆë
ADC_InitStructure.ADC_NbrOfConversion = 1;//1¸ö×a»»Ôú1æÔòDòáDÖD ò2¾íêÇÖ»×a»»1æÔòDòáD1
ADC_Init(ADC3, &ADC_InitStructure);//ADC3õê¼»ˉ
ADC_Cmd(ADC3, ENABLE);//¿aÆôAD×a»»Æ÷
}
//»ñμÃADCÖμ
//ch:í¨μàÖμ 0~16 ADC_Channel_0~ADC_Channel_16
//·μ»ØÖμ:×a»»½á1û
u16 Get_Adc3(u8 ch)
{
//éèÖÃÖ¸¶¨ADCμÄ1æÔò×éí¨μ࣬ò»¸öDòáD£¬2éÑùê±¼ä
ADC_RegularChannelConfig(ADC3, ch, 1, ADC_SampleTime_480Cycles ); //ADC3,ADCí¨μà,480¸öÖüÆú,ìá¸ß2éÑùê±¼ä¿éòÔìá¸ß¾«è·¶è
ADC_SoftwareStartConv(ADC3); //ê1ÄüÖ¸¶¨μÄADC3μÄèí¼t×a»»Æô¶ˉ1|Äü
while(!ADC_GetFlagStatus(ADC3, ADC_FLAG_EOC ));//μè′y×a»»½áêø
return ADC_GetConversionValue(ADC3); //·μ»Ø×î½üò»′ÎADC31æÔò×éμÄ×a»»½á1û
} |