Skip to main content
HPATH.1
Associate III
Aug 4, 2021 12:02 PM UTC
Solved

bug in example code STM32G0xx PWM output Example

the following line 56000000 is wrong.

#define PRESCALER_VALUE   (uint32_t)((SystemCoreClock / 56000000) - 1)

it should be 5600000 Right ?

SystemCoreclock is 16MHZ. but divided by 56MHZ ? 

This topic has been closed for replies.
TDK
TDKBest answer
Aug 4, 2021 1:43 PM UTC

4 replies

TDK
TDKBest answer
Aug 4, 2021 1:43 PM UTC
HPATH.1
HPATH.1Author
Associate III
Aug 5, 2021 8:48 AM UTC

Thanks for the reply.

this is declared in system_stm32g0xx.c

uint32_t SystemCoreClock = 16000000UL; I checked it while application is running it is same. not increased to 64MHZ.

with this setting it is not working for me. in this case

#define PRESCALER_VALUE   (uint32_t)((SystemCoreClock / 56000000) - 1) equals to -1 not zero.

I set PRESCALER_VALUE   = 0; then output is coming at 6.97khz

I need to increase SystemCoreClock to 64 MHz. how to do that ?

HPATH.1
HPATH.1Author
Associate III
Aug 5, 2021 9:12 AM UTC

sorry. I found void SystemClock_Config(void) is different in my application. copied it from Example and now SystemClock is set to 56 Mhz.

after this I am getting 24.4Khz. PWM output.

Thank you very for the help.

TDK
Aug 5, 2021 2:14 PM UTC

Glad you got it working.

As additional info, the chip boots up in 16 MHz, so this is the initial (and correct) value of SystemCoreClock.

https://github.com/STMicroelectronics/STM32CubeG0/blob/c6c0046d9278a7107261c6bf38327345df4c3efd/Projects/STM32G081B-EVAL/Examples/TIM/TIM_PWMOutput/Src/system_stm32g0xx.c#L142

When the clock changes, the SystemCoreClock variable is updated accordingly, at least if you're using HAL.

https://github.com/STMicroelectronics/STM32CubeG0/blob/master/Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_rcc.c#L948

"If you feel a post has answered your question, please click ""Accept as Solution""."