CNT可以计数,就是没有脉冲输出。能否看看你的代码,只要有脉冲输出就可以。
/* Peripheral clock enable */
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
/* Configure the Time base :
+ Counter mode : UP Counter
+ Clock Division : 1
+ Period : 5000
+ Pulse : 2000
+ Prescaler : 7
+ Repetition counter : PULSE_NUMBER - 1
*/
/* Set the Timer prescaler to get 1MHz as counter clock */
Prescaler = (uint16_t) (SystemCoreClock / 1000000) - 1;
/* Select the up counter mode */
TIM1->CR1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
TIM1->CR1 |= TIM_COUNTERMODE_UP;
/* Set the clock division to 1*/
TIM1->CR1 &= ~TIM_CR1_CKD;
TIM1->CR1 |= TIM_CLOCKDIVISION_DIV1;
/* Set the Autoreload value */
TIM1->ARR = PERIOD;
/* Set the Pulse value */
TIM1->CCR1 = PULSE;
/* Set the Prescaler value */
TIM1->PSC = Prescaler;
/* Set the Repetition counter value */
TIM1->RCR = PULSE_NUMBER - 1;
/* Generate an update event to reload the Prescaler and the repetition counter
value immediately */
TIM1->EGR = TIM_EGR_UG;
/******** Configure the Internal Clock source *********************************/
/* Disable slave mode to clock the prescaler directly with the internal clock
if the TIM_SMCR is in the reset value, we can delete the following instruction*/
TIM1->SMCR = RESET;