2024-01-17 11:51 AM
What am I doing wrong?
Why is PWM don't work on the STM32F767ZI?
RCC->APB2ENR |= 1; // Enable clock for TIM1 on APB2.
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN; // Enable clock for GPIOE port on AHB1.
GPIOE->MODER &= ~(1 << 18); // Clear/reset PE9 mode.
GPIOE->MODER |= (2 << 18); // Set PE9 mode.
// Enable alternative function AFIO. Connect TIM to the pin accordingly!
GPIOE->AFR[1] &= ~(0xF << 4); // Clear bits 4 to 7.
GPIOE->AFR[1] |= (1 << 4); // Set bit 9.
TIM1->PSC = 216 - 1; // Set prescaler for > 10KHz.
TIM1->ARR = 100 - 1; // Set auto-reload value for 1Hz.
TIM1->CCR1 = 50; // Set initial comparison value (PWM duty cycle).
TIM1->CNT = 0; // Reset the current count.
TIM1->CCMR1 |= (0x6UL << TIM_CCMR1_OC1M_Pos ); // Set PWM mode 1.
TIM1->CCMR1 |= (0x68 << 0);
TIM1->CCER = 1; // Enable PWM Channel 1.
TIM1->CR1 = 1; // Enable timer.
2024-01-18 4:22 AM
When I compare my code to yours:
- TIM: you have not set the ARPE bit in CR1, not sure though if that is really needed, check RM
RM:
You must enable the corresponding preload register by setting the
OCxPE bit in the TIMx_CCMRx register, and eventually the auto-reload preload register (in
upcounting or center-aligned modes) by setting the ARPE bit in the TIMx_CR1 register.
IDK if that applies to your stuff.
- clock enables and GPIO: that's where I am lazy and use the HAL stuff. Maybe just for checking, you use HAL stuff for that, then see if your PWM starts doing something.
2024-01-18 4:27 AM
Thank you, I will verify everything and I'll reply to you!
2024-01-18 5:14 AM - edited 2024-01-18 5:14 AM
I wrote an article on ARM Timers using registers, NOT HAL, that might be of some help.
https://jaxcoder.com/Post/Index?guid=456f6a89-1a93-4a72-bab9-4cf3a9e7f9b6
2024-01-18 5:27 AM - edited 2024-01-18 5:28 AM
Read out and check/post TIM and GPIO registers' content. That's always the first step in debugging software on mcu, as it works out of registers, not out of the source code.
JW
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.