cancel
Showing results for 
Search instead for 
Did you mean: 

bug in example code STM32G0xx PWM output Example

HPATH.1
Associate II

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 ? 

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
TDK
Guru
HPATH.1
Associate II

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
Associate II

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
Guru

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".