WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
frc::PWM Class Reference

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

#include <frc/PWM.h>

Inheritance diagram for frc::PWM:
wpi::Sendable wpi::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 (units::microsecond_t time)
 Set the PWM pulse time directly to the hardware.
 
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::Sendable
virtual constexpr ~Sendable ()=default
 
- Public Member Functions inherited from wpi::SendableHelper< PWM >
constexpr SendableHelper (const SendableHelper &rhs)=default
 
constexpr SendableHelper (SendableHelper &&rhs)
 
constexpr SendableHelperoperator= (const SendableHelper &rhs)=default
 
constexpr SendableHelperoperator= (SendableHelper &&rhs)
 

Protected Member Functions

void InitSendable (wpi::SendableBuilder &builder) override
 Initializes this Sendable object.
 
- Protected Member Functions inherited from wpi::SendableHelper< PWM >
constexpr SendableHelper ()=default
 
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]

frc::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]

frc::PWM::PWM ( PWM && )
default

◆ ~PWM()

frc::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 frc::PWM::GetChannel ( ) const

◆ GetPulseTime()

units::microsecond_t frc::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 frc::PWM::InitSendable ( wpi::SendableBuilder & builder)
overrideprotectedvirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements wpi::Sendable.

◆ operator=()

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

◆ SetDisabled()

void frc::PWM::SetDisabled ( )

Temporarily disables the PWM output.

The next set call will re-enable the output.

◆ SetOutputPeriod()

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

Sets the PWM output period.

Parameters
multThe output period to apply to this channel

◆ SetPulseTime()

void frc::PWM::SetPulseTime ( 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 frc::PWM::SetSimDevice ( HAL_SimDeviceHandle device)

Indicates this input is used by a simulated device.

Parameters
devicesimulated device handle

Friends And Related Symbol Documentation

◆ AddressableLED

friend class AddressableLED
friend

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