代码如下:
TIM_DeInit(TIM1);
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = Period;
TIM_TimeBaseStructure.TIM_Prescaler = 0; /* 计数频率 = 72000 000 / 18 = 4000 000 */
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* TIM1 channel1 configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = TIM_TimeBaseStructure.TIM_Period / 2;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE); ////////////标注1
/* TIM1 main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
情况如下:
TIM1全部DeInit后,执行到“标注1”,TIM1->CNT 的值每次都不一样,这是为何,能否设置CNT值在开启定时器TIM1后为一个固定值?
是不是把ARR和CNT寄存器搞混了啊?CNT不变定时器如何工作?