/* 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;
最近刚好弄这个,cube生成的代码里几个地方要操作一下,一个是 TIM_OC_InitStruct.OCState 和 OCNState 要enable 还有一个是刹车控制,默认是使能所有通道是关闭的,LL_TIM_EnableAllOutputs(TIM1);这句可以开启,如果CNT不计数用LL_TIM_EnableCounter(TIM1); 开启
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;
一周热门 更多>