stm32/stm32l4 PWM: While attempting to output a 70 MHz square wave from the timer output of a STM32 clocked at 140 MHz (which works fine in baremetal C), I stumbled on what I believe to be an error in arch/arm/src/stm32/stm32_pwm.c. Line 1304 we are told that
reload = timclk / info->frequency; which I belive to be incorrect, it should be reload = timclk / info->frequency - 1; since starting to count from 0, if I want to output half of the TIM clock, I must count to 1 and not to 2. Surely enough, the original code did output 140/3=47 MHz, while this correction does allow the output up to 70 MHz. I am not sure this affects most users generating slow PWM (e.g. PX4) but for frequencies close to the PCLK, indeed the difference becomes significant.
This commit is contained in:
parent
af27e8e0a9
commit
7903a8a46c
@ -1300,7 +1300,7 @@ static int pwm_timer(FAR struct stm32_pwmtimer_s *priv,
|
|||||||
|
|
||||||
timclk = priv->pclk / prescaler;
|
timclk = priv->pclk / prescaler;
|
||||||
|
|
||||||
reload = timclk / info->frequency;
|
reload = timclk / info->frequency - 1;
|
||||||
if (reload < 1)
|
if (reload < 1)
|
||||||
{
|
{
|
||||||
reload = 1;
|
reload = 1;
|
||||||
|
@ -841,7 +841,7 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
|
|||||||
|
|
||||||
timclk = priv->pclk / prescaler;
|
timclk = priv->pclk / prescaler;
|
||||||
|
|
||||||
reload = timclk / info->frequency;
|
reload = timclk / info->frequency - 1;
|
||||||
if (reload < 1)
|
if (reload < 1)
|
||||||
{
|
{
|
||||||
reload = 1;
|
reload = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user