MCU是STM8S105S4,现在我在PWM定时器1中断里采集AD值,只有开关信号开了才采集和开启下一次转换,如果开关关了就不进行下次开启,AD中断里关AD清标志。结果开关关了后再开,结果AD就不会启动了,求高手指点下。以下是程序:
void init_AD(void)
{
ADC1_DeInit();
ADC1_ClearITPendingBit(ADC1_IT_EOC);
ADC1_Init(ADC1_CONVERSIONMODE_SINGLE, ADC1_CHANNEL_4, ADC1_PRESSEL_FCPU_D18, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL0, DISABLE);
//单次转换,通道4,18分频,右对齐,施密特关闭,外部触发关闭
ADC1_ScanModeCmd(DISABLE);
ADC1_DataBufferCmd(DISABLE);
ADC1_ITConfig(ADC1_IT_EOCIE, ENABLE); //转换完成中断
}
#pragma vector=0xD
__interrupt void TIM1_UPD_OVF_TRG_BRK_IRQHandler(void)
{
u8 k;
TIM1_ClearITPendingBit(TIM1_IT_UPDATE);
// GPIO_WriteHigh(PC_PORT,LED_RED_PIN);
if(powerflag==2)
{
get_AD();
accspeed_control();
speed_deal();
current_deal();
DUTY_change();
ADC1_StartConversion();
for(k=40;k>0;k--);
ADC1_StartConversion();
}
}
#pragma vector=0x18
__interrupt void ADC1_IRQHandler(void)
{
//GPIO_WriteHigh(PC_PORT,LED_RED_PIN);
ADC1_Cmd(DISABLE);
ADC1_ClearITPendingBit(ADC1_IT_EOC);
finishflag=1;
} |