Struct esp32_hal::mcpwm::PeripheralClockConfig
source · pub struct PeripheralClockConfig<'a> { /* private fields */ }
Expand description
Clock configuration of the MCPWM peripheral
Implementations§
source§impl<'a> PeripheralClockConfig<'a>
impl<'a> PeripheralClockConfig<'a>
sourcepub fn with_prescaler(
clocks: &'a Clocks<'_>,
prescaler: u8
) -> PeripheralClockConfig<'a>
pub fn with_prescaler( clocks: &'a Clocks<'_>, prescaler: u8 ) -> PeripheralClockConfig<'a>
Get a clock configuration with the given prescaler.
With standard system clock configurations the input clock to the MCPWM
peripheral is 160 MHz
.
The peripheral clock frequency is calculated as:
peripheral_clock = input_clock / (prescaler + 1)
sourcepub fn with_frequency(
clocks: &'a Clocks<'_>,
target_freq: Rate<u32, 1, 1>
) -> Result<PeripheralClockConfig<'a>, FrequencyError>
pub fn with_frequency( clocks: &'a Clocks<'_>, target_freq: Rate<u32, 1, 1> ) -> Result<PeripheralClockConfig<'a>, FrequencyError>
Get a clock configuration with the given frequency.
§Note:
This will try to select an appropriate prescaler for the
PeripheralClockConfig::with_prescaler
method.
If the calculated prescaler is not in the range 0..u8::MAX
FrequencyError
will be returned.
With standard system clock configurations the input clock to the MCPWM
peripheral is 160 MHz
.
Only divisors of the input clock (160 Mhz / 1
, 160 Mhz / 2
, …,
160 Mhz / 256
) are representable exactly. Other target frequencies
will be rounded up to the next divisor.
sourcepub fn frequency(&self) -> Rate<u32, 1, 1>
pub fn frequency(&self) -> Rate<u32, 1, 1>
Get the peripheral clock frequency.
§Note:
The actual value is rounded down to the nearest u32
value
sourcepub fn timer_clock_with_prescaler(
&self,
period: u16,
mode: PwmWorkingMode,
prescaler: u8
) -> TimerClockConfig<'a>
pub fn timer_clock_with_prescaler( &self, period: u16, mode: PwmWorkingMode, prescaler: u8 ) -> TimerClockConfig<'a>
Get a timer clock configuration with the given prescaler.
The resulting timer frequency depends of the chosen
timer::PwmWorkingMode
.
§PwmWorkingMode::Increase
or PwmWorkingMode::Decrease
timer_frequency = peripheral_clock / (prescaler + 1) / (period + 1)
§PwmWorkingMode::UpDown
timer_frequency = peripheral_clock / (prescaler + 1) / (2 * period)
sourcepub fn timer_clock_with_frequency(
&self,
period: u16,
mode: PwmWorkingMode,
target_freq: Rate<u32, 1, 1>
) -> Result<TimerClockConfig<'a>, FrequencyError>
pub fn timer_clock_with_frequency( &self, period: u16, mode: PwmWorkingMode, target_freq: Rate<u32, 1, 1> ) -> Result<TimerClockConfig<'a>, FrequencyError>
Get a timer clock configuration with the given frequency.
§Note:
This will try to select an appropriate prescaler for the timer.
If the calculated prescaler is not in the range 0..u8::MAX
FrequencyError
will be returned.
See PeripheralClockConfig::timer_clock_with_prescaler
for how the
frequency is calculated.
Trait Implementations§
source§impl<'a> Clone for PeripheralClockConfig<'a>
impl<'a> Clone for PeripheralClockConfig<'a>
source§fn clone(&self) -> PeripheralClockConfig<'a>
fn clone(&self) -> PeripheralClockConfig<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more