ADC通道的转换可以由外部事件触发,设置了 ADC_CTLR2 寄存器的 EXTTRIG 或 JEXTTRIG位,则可分别通过外部事件触发规则组或注入组通道的转换。注 : 当外部触发信号被选为ADC规则或注入转换时,只有它的上升沿可以启动转换。
/*ADC初始化部分代码*/
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO;//定时器3的TRGO事件
ADC_ExternalTrigConvCmd(ADC1, ENABLE);//开启外部事件触发ADC启动
/*定时器部分代码*/
void TIM3_TRGO(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure={0};
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE );
TIM_TimeBaseInitStructure.TIM_Period = 10-1;
TIM_TimeBaseInitStructure.TIM_Prescaler = 96-1; //10us触发一次
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit( TIM3, &TIM_TimeBaseInitStructure);
TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Update); //选择TRGO作为触发源为定时器更新时间
TIM_ARRPreloadConfig( TIM3, ENABLE );
TIM_Cmd(TIM3, ENABLE);
}
int main(void)
{
ADC_Function_Init();
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_71Cycles5 );//84/12=7us<10us(定时器触发转换时间),
TIM3_TRGO();
while(1)
{
}
标签:TimeBaseInitStructure,触发,TIM3,外部,TRGO,TIM,ADC From: https://www.cnblogs.com/wchmcu/p/17445959.html