Module imxrt_hal::pwm [−][src]
Pulse Width Modulation (PWM)
Provides an implementation of embedded_hal::Pwm
for iMXRT PWM
submodules. The flow follows
- Enable clocks to the selected PWM peripheral by calling
clock()
on anUnclocked
struct. The return is aPWM
type that provides a register handle and PWM submodules - Turn submodules into
Pins
by supplying two processor pins tooutput
. The return is aPins
struct that wraps the two pins. ThePins
struct are inert; they’re simply a handle that can provide PWM control. Callcontrol()
and pass in aHandle
, to acquire aController
. Controller
implementsembedded_hal::Pwm
. It lets you set PWM duty cycles. Once you’re done setting duty cycles, drop theController
.
Example
use imxrt_hal; use imxrt_hal::pwm::Channel; use embedded_hal::Pwm; let mut p = imxrt_hal::Peripherals::take().unwrap(); let (_, ipg_hz) = p.ccm .pll1 .set_arm_clock(imxrt_hal::ccm::PLL1::ARM_HZ, &mut p.ccm.handle, &mut p.dcdc); let mut pwm2 = p.pwm2.clock(&mut p.ccm.handle); let mut sm2 = pwm2 .sm2 .outputs( &mut pwm2.handle, p.iomuxc.b0.p10, p.iomuxc.b0.p11, imxrt_hal::pwm::Timing { clock_select: imxrt_hal::ccm::pwm::ClockSelect::IPG(ipg_hz), prescalar: imxrt_hal::ccm::pwm::Prescalar::PRSC_5, switching_period: core::time::Duration::from_micros(1000), }, ) .unwrap(); let (duty1, duty2) = (core::u16::MAX / 4, core::u16::MAX / 2); let mut ctrl = sm2.control(&mut pwm2.handle); ctrl.enable(Channel::A); ctrl.enable(Channel::B); ctrl.set_duty(Channel::A, duty1); ctrl.set_duty(Channel::B, duty2);
Structs
Controller | A PWM controller, which implements |
Handle | PWM peripheral handle |
PWM | A PWM peripheral |
Pins | A pair of submodule PWM pins |
Submodule | A PWM submodule |
Timing | Specifies the timing-related parameters for a PWM submodule |
Unclocked | A PWM peripheral that is not receiving a clock input |
Enums
Channel | A PWM pin channel |