stm32-rs / stm32l4xx-hal

A Hardware abstraction layer for the stm32l432xx series chips written in rust.
157 stars 104 forks source link

PWM timing off by 1 #343

Open snakehand opened 11 months ago

snakehand commented 11 months ago

I was trying to generate a 512kHz PWM signal from a 64MHz AHB clock, but when verifying the signal in the laboratory, I found that the frequency was off, in a way consistent with the the ARR being off by one.

https://github.com/stm32-rs/stm32l4xx-hal/blob/bf2ded1fcabe782168d132500d95f9bd1acf48c1/src/pwm.rs#L202

This situation is also alluded to in the linked comment.

Changing line 200 to :

let ticks = clk / freq - 1;

Gave me the correct output frequency. I intend to make a PR linked to this issue.