采用tim3的更新事件来触发ADC没有反应 仿真发现并没有转化 求大神帮忙看看
void Tim3Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
TIM_TimeBaseInitStruct.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_Prescaler=42-1;
TIM_TimeBaseInitStruct.TIM_Period=44;
TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStruct);
TIM_SelectOutputTrigger(TIM3,TIM_TRGOSource_Update);
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
NVIC_InitStruct.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
TIM_Cmd(TIM3,ENABLE);
}
void Adc_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_ADC1 , ENABLE );
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
//PA1 ×÷ÎaÄ£Äaí¨μàêäèëòy½Å
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
ADC_DeInit(ADC1); //¸′λADC1,½«íaéè ADC1 μÄè«2¿¼Ä′æÆ÷ÖØéèÎaè±ê¡Öμ
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC1¤×÷Ä£ê½:ADC1oíADC21¤×÷Ôú¶àá¢Ä£ê½
ADC_InitStructure.ADC_ScanConvMode = DISABLE; //Ä£êy×a»»1¤×÷Ôúμ¥í¨μàÄ£ê½
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //Ä£êy×a»»1¤×÷Ôúμ¥′Î×a»»Ä£ê½
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO; //×a»»óéèí¼t¶ø2»êÇía2¿′¥·¢Æô¶ˉ
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADCêy¾Yóò¶ÔÆë
ADC_InitStructure.ADC_NbrOfChannel = 1; //Ë3Dò½øDD1æÔò×a»»μÄADCí¨μàμÄêyÄ¿
ADC_Init(ADC1, &ADC_InitStructure); //¸ù¾YADC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèADCxμļÄ′æÆ÷
ADC_ExternalTrigConvCmd(ADC1,ENABLE);
ADC_Cmd(ADC1, ENABLE); //ê1ÄüÖ¸¶¨μÄADC1
ADC_ResetCalibration(ADC1); //ê1Äü¸′λD£×¼
while(ADC_GetResetCalibrationStatus(ADC1)); //μè′y¸′λD£×¼½áêø
ADC_StartCalibration(ADC1); //¿aÆôADD£×¼
while(ADC_GetCalibrationStatus(ADC1)); //μè′yD£×¼½áêø
// ADC_SoftwareStartConvCmd(ADC1, ENABLE); //ê1ÄüÖ¸¶¨μÄADC1μÄèí¼t×a»»Æô¶ˉ1|Äü
}
{
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_239Cycles5 ); //ADC1,ADCí¨μà,2éÑùê±¼äÎa239.5ÖüÆú
//ADC_SoftwareStartConvCmd(ADC1, ENABLE); //ê1ÄüÖ¸¶¨μÄADC1μÄèí¼t×a»»Æô¶ˉ1|Äü
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));//μè′y×a»»½áêø
return ADC_GetConversionValue(ADC1); //·μ»Ø×î½üò»′ÎADC11æÔò×éμÄ×a»»½á1û
}
u16 Get_Adc_Average(u8 ch,u8 times)
{
u32 temp_val=0;
u8 t;
for(t=0;t<times;t++)
{
temp_val+=Get_Adc(ch);
delay_ms(5);
}
return temp_val/times;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>