请问香主,定时器单脉冲模式中,定时器是不是必须通过TIx输入脚的边沿检测逻辑设置CEN位来启动计数器,手动设置CEN位能不能启动。配置代码是:
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_TimeBaseInitStruct.TIM_Period = 0x0BB8; //3000计数
TIM_TimeBaseInitStruct.TIM_Prescaler = 0x0001; //2分频
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseInitStruct);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0x7D0; //2000翻转
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_SelectOnePulseMode(TIM1, TIM_OPMode_Single); //选择单脉冲模式
TIM_CtrlPWMOutputs(TIM1, ENABLE);
TIM_Cmd(TIM1, ENABLE);
这样的话,在CH1的输出出现了7个脉冲。不知道这样的配置是否正确。
还有一个问题是:通过TIM1_CR2的MMS位选择将OC1REF信号被用于作为触发输出(TRGO)时, 在连接定时器1的TRGO1输出至定时器2时,在TIM2_SMCR的TS位中,应该内部触发的那个序号,才能将TIM1的输出连接到TIM2。
谢谢香主。 |