Hello! I have a question: How to generate a PWM on STM32F103C8T6 in Keil uVision 5. I watched some tutorials but I couldn't make it work, I want to enable TIM1 on pin PA11 and PA12. PWM needs to run at 20kHz => period = 3600.
It will be used for motor control on a robot. This is what I managed to do:
RCC-> APB2ENR |= RCC_APB2ENR_TIM1EN;
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
GPIOA->ODR |= GPIO_ODR_ODR11;
GPIOA->CRH |= GPIO_CRH_MODE11_1;
GPIOA->CRH &= ~(GPIO_CRH_MODE11_0);
TIM1->PSC = 0;
TIM1->ARR = 3600;
TIM1->CCR4 = 1800;
TIM1->CCMR2 |= TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4PE;
TIM1->CCER |= TIM_CCER_CC4E;
TIM1->BDTR |= TIM_BDTR_MOE;
TIM1->CR1 |= TIM_CR1_CEN;
TIM1->EGR |= TIM_EGR_UG;
I watched this tutorials:
Maybe if you have some more tutorials on PWM and encoder readings with timers I would be very glad!
Thank you in advance!
Any help would be appreciated!