网上看到这样一段例子:
void BLDC_TIM3Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //基本结构体变量定义
TIM_ICInitTypeDef TIM_ICInitStructure; //定义结构体变量
TIM_OCInitTypeDef TIM_OCInitStructure; //输出结构体变量定义
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Prescaler = 71; //TIM基本初始化
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period =65535;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; //选择通道1
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //输入上升沿捕获
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_TRC; //配置通道为输入,并映射到哪里
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //输入捕获预分频值
TIM_ICInitStructure.TIM_ICFilter = 10; //输入滤波器带宽设置
TIM_ICInit(TIM3, &TIM_ICInitStructure); //输入通道配置
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //TIM输出通道初始化
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse =1023;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC2Init(TIM3,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing; //TIM输出通道初始化
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;
TIM_OCInitStructure.TIM_Pulse =65535;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC4Init(TIM3,&TIM_OCInitStructure);
TIM_SelectHallSensor(TIM3,ENABLE); //使能TIMx的霍尔传感器接口
TIM_SelectInputTrigger(TIM3, TIM_TS_TI1F_ED); //输入触发源选择
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset); //从模式选择
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);//主从模式选择
TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_OC2Ref); //选择输出触发模式(TRGO端)
TIM_ITConfig(TIM3, TIM_IT_Trigger|TIM_IT_CC4, ENABLE); //开定时器中断
//TIM_Cmd(TIM3,ENABLE);
}
疑问:霍尔有三个接口,分别是hallA,B,C.接到单片机上去,采用了TIM3的channel1,2,3三个通道。为什么不是配置三个通道都是输入?却要仅配置channel1为输入,其他两个为输出呢?如果这样的话,怎么异或呢?这个刚接触这个,请大家见谅。。。 |