WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::PWM Class Reference

Class implements the PWM generation in the FPGA. More...

#include <wpi/hardware/discrete/PWM.hpp>

Inheritance diagram for wpi::PWM:
wpi::util::Sendable wpi::util::SendableHelper< PWM >

Public Types

enum  OutputPeriod { kOutputPeriod_5Ms = 1 , kOutputPeriod_10Ms = 2 , kOutputPeriod_20Ms = 4 }
 Represents the output period in microseconds. More...

Public Member Functions

 PWM (int channel, bool registerSendable=true)
 Allocate a PWM given a channel number.
 PWM (PWM &&)=default
PWMoperator= (PWM &&)=default
 ~PWM () override
 Free the PWM channel.
void SetPulseTime (wpi::units::microsecond_t time)
 Set the PWM pulse time directly to the hardware.
wpi::units::microsecond_t GetPulseTime () const
 Get the PWM pulse time directly from the hardware.
void SetDisabled ()
 Temporarily disables the PWM output.
void SetOutputPeriod (OutputPeriod mult)
 Sets the PWM output period.
int GetChannel () const
void SetSimDevice (HAL_SimDeviceHandle device)
 Indicates this input is used by a simulated device.
Public Member Functions inherited from wpi::util::Sendable
virtual constexpr ~Sendable ()=default
Public Member Functions inherited from wpi::util::SendableHelper< PWM >
constexpr SendableHelper (const SendableHelper &rhs)=default
constexpr SendableHelperoperator= (const SendableHelper &rhs)=default

Protected Member Functions

void InitSendable (wpi::util::SendableBuilder &builder) override
 Initializes this Sendable object.
Protected Member Functions inherited from wpi::util::SendableHelper< PWM >
constexpr ~SendableHelper ()

Friends

class AddressableLED

Detailed Description

Class implements the PWM generation in the FPGA.

The values supplied as arguments for PWM outputs range from -1.0 to 1.0. They are mapped to the microseconds to keep the pulse high, with a range of 0 (off) to 4096. Changes are immediately sent to the FPGA, and the update occurs at the next FPGA cycle (5.05ms). There is no delay.

Member Enumeration Documentation

◆ OutputPeriod

Represents the output period in microseconds.

Enumerator
kOutputPeriod_5Ms 

PWM pulses occur every 5 ms.

kOutputPeriod_10Ms 

PWM pulses occur every 10 ms.

kOutputPeriod_20Ms 

PWM pulses occur every 20 ms.

Constructor & Destructor Documentation

◆ PWM() [1/2]

wpi::PWM::PWM ( int channel,
bool registerSendable = true )
explicit

Allocate a PWM given a channel number.

Checks channel value range and allocates the appropriate channel. The allocation is only done to help users ensure that they don't double assign channels.

Parameters
channelThe PWM channel number. 0-9 are on-board, 10-19 are on the MXP port
registerSendableIf true, adds this instance to SendableRegistry

◆ PWM() [2/2]

wpi::PWM::PWM ( PWM && )
default

◆ ~PWM()

wpi::PWM::~PWM ( )
override

Free the PWM channel.

Free the resource associated with the PWM channel and set the value to 0.

Member Function Documentation

◆ GetChannel()

int wpi::PWM::GetChannel ( ) const

◆ GetPulseTime()

wpi::units::microsecond_t wpi::PWM::GetPulseTime ( ) const

Get the PWM pulse time directly from the hardware.

Read a microsecond value from a PWM channel.

Returns
Microsecond PWM control value.

◆ InitSendable()

void wpi::PWM::InitSendable ( wpi::util::SendableBuilder & builder)
overrideprotectedvirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements wpi::util::Sendable.

◆ operator=()

PWM & wpi::PWM::operator= ( PWM && )
default

◆ SetDisabled()

void wpi::PWM::SetDisabled ( )

Temporarily disables the PWM output.

The next set call will re-enable the output.

◆ SetOutputPeriod()

void wpi::PWM::SetOutputPeriod ( OutputPeriod mult)

Sets the PWM output period.

Parameters
multThe output period to apply to this channel

◆ SetPulseTime()

void wpi::PWM::SetPulseTime ( wpi::units::microsecond_t time)

Set the PWM pulse time directly to the hardware.

Write a microsecond value to a PWM channel.

Parameters
timeMicrosecond PWM value.

◆ SetSimDevice()

void wpi::PWM::SetSimDevice ( HAL_SimDeviceHandle device)

Indicates this input is used by a simulated device.

Parameters
devicesimulated device handle

◆ AddressableLED

friend class AddressableLED
friend

The documentation for this class was generated from the following file: