Module mcpwm

Source
Expand description

§MCPWM (Motor Control Pulse Width Modulator) peripheral

§Overview

§Peripheral capabilities
  • PWM Timers 0, 1 and 2
    • Every PWM timer has a dedicated 8-bit clock prescaler.
    • The 16-bit counter in the PWM timer can work in count-up mode, count-down mode or count-up-down mode.
    • A hardware sync or software sync can trigger a reload on the PWM timer with a phase register (Not yet implemented)
  • PWM Operators 0, 1 and 2
    • Every PWM operator has two PWM outputs: PWMxA and PWMxB. They can work independently, in symmetric and asymmetric configuration.
    • Software, asynchronously override control of PWM signals.
    • Configurable dead-time on rising and falling edges; each set up independently. (Not yet implemented)
    • All events can trigger CPU interrupts. (Not yet implemented)
    • Modulating of PWM output by high-frequency carrier signals, useful when gate drivers are insulated with a transformer. (Not yet implemented)
    • Period, time stamps and important control registers have shadow registers with flexible updating methods.
  • Fault Detection Module (Not yet implemented)
  • Capture Module (Not yet implemented)

§Example

Uses timer0 and operator0 of the MCPWM0 peripheral to output a 50% duty signal at 20 kHz. The signal will be output to the pin assigned to pin.

use mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, PeripheralClockConfig, MCPWM};

// initialize peripheral
let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40u32.MHz()).unwrap();
let mut mcpwm = MCPWM::new(peripherals.PWM0, clock_cfg);

// connect operator0 to timer0
mcpwm.operator0.set_timer(&mcpwm.timer0);
// connect operator0 to pin
let mut pwm_pin = mcpwm
    .operator0
    .with_pin_a(pin, PwmPinConfig::UP_ACTIVE_HIGH);

// start timer with timestamp values in the range of 0..=99 and a frequency of 20 kHz
let timer_clock_cfg = clock_cfg
    .timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20u32.kHz())
    .unwrap();
mcpwm.timer0.start(timer_clock_cfg);

// pin will be high 50% of the time
pwm_pin.set_timestamp(50);

Modules§

operator
MCPWM operators
timer
MCPWM timers

Structs§

FrequencyError
Target frequency could not be set. Check how the frequency is calculated in the corresponding method docs.
MCPWM
The MCPWM peripheral
PeripheralClockConfig
Clock configuration of the MCPWM peripheral

Traits§

PwmPeripheral
A MCPWM peripheral