How to initialize and use TIM2 for output compare?
I am using the STM32F303CB controller.
System Clock - 72MHz
APB1ENR - 72MHz for Timer
I followed the below steps as per the reference manual.
Timer2 Initialization:
RCC->APB1ENR|= RCC_APB1ENR_TIM2EN;
TIM2->ARR = 72000-1;
TIM2->CCR1= 4000;
TIM2->PSC = 1000-1;
TIM2->DIER = TIM_DIER_CC1IE;
TIM2->CCMR1 = TIM_CCMR1_OC1M_0|TIM_CCMR1_OC1M_1;
TIM2->CCMR1 &= ~(TIM_CCMR1_OC1PE);
TIM2->CCER |= TIM_CCER_CC1E;
TIM2->CR1 |= TIM_CR1_CEN;
while (!(TIM2->SR & (1<<0)));
NVIC_EnableIRQ(TIM2_IRQn);
I have initialized the timer for 1 sec.
My application wants the output compare feature for a timer period.
For Example:
When the counter matches with CCR1(4000) interrupt should raise and CCR1 is updated with new value CCR1(15000) vice versa.
Did I made any mistake or need to do more steps.
Please guide me.
