Available on crate feature
unstable
only.Expand description
§Motor Control Pulse Width Modulator (MCPWM)
§Overview
The MCPWM peripheral is a versatile PWM generator, which contains various submodules to make it a key element in power electronic applications like motor control, digital power, and so on. Typically, the MCPWM peripheral can be used in the following scenarios:
- Digital motor control, e.g., brushed/brushless DC motor, RC servo motor
- Switch mode-based digital power conversion
- Power DAC, where the duty cycle is equivalent to a DAC analog value
- Calculate external pulse width, and convert it into other analog values like speed, distance
- Generate Space Vector PWM (SVPWM) signals for Field Oriented Control (FOC)
§Configuration
- 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)
Clock source is PWM_CLOCK
§Examples
§Output a 20 kHz signal
This 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
.
// initialize peripheral
let clock_cfg = PeripheralClockConfig::with_frequency(32.MHz()).unwrap();
let mut mcpwm = McPwm::new(peripherals.MCPWM0, 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, 20.kHz())
.unwrap();
mcpwm.timer0.start(timer_clock_cfg);
// pin will be high 50% of the time
pwm_pin.set_timestamp(50);
Modules§
- MCPWM operators
- MCPWM timers
Structs§
- Target frequency could not be set. Check how the frequency is calculated in the corresponding method docs.
- The MCPWM peripheral
- Clock configuration of the MCPWM peripheral
Traits§
- A MCPWM peripheral