Skip to main content

prescale_for_frequency

Function prescale_for_frequency 

Source
pub fn prescale_for_frequency(update_rate_hz: u32, osc_hz: u32) -> u8
Expand description

Computes the PRE_SCALE value for a desired PWM frequency.

This is the datasheet’s prescale formula round(osc_clock / (4096 * update_rate)) - 1, clamped to the hardware’s 3..=255 range (which bounds the frequency to roughly 24 Hz to 1.5 kHz at 25 MHz).

§Arguments

  • update_rate_hz - the desired output frequency in hertz.
  • osc_hz - the oscillator frequency, INTERNAL_OSC_HZ unless an external clock is used.

§Returns

The value to write to the PRE_SCALE register.