Class PWM

java.lang.Object
edu.wpi.first.wpilibj.PWM
All Implemented Interfaces:
Sendable, AutoCloseable

public class PWM extends Object implements Sendable, AutoCloseable
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.

  • Constructor Details

    • PWM

      public PWM(int channel)
      Allocate a PWM given a channel.

      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.

      By default, adds itself to SendableRegistry.

      Parameters:
      channel - The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port
    • PWM

      public PWM(int channel, boolean registerSendable)
      Allocate a PWM given a channel.
      Parameters:
      channel - The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port
      registerSendable - If true, adds this instance to SendableRegistry
  • Method Details

    • close

      public void close()
      Free the resource associated with the PWM channel and set the value to 0.
      Specified by:
      close in interface AutoCloseable
    • getChannel

      public int getChannel()
      Gets the channel number associated with the PWM Object.
      Returns:
      The channel number.
    • setPulseTimeMicroseconds

      public void setPulseTimeMicroseconds(int microsecondPulseTime)
      Set the PWM value directly to the hardware.

      Write a microsecond pulse value to a PWM channel.

      Parameters:
      microsecondPulseTime - Microsecond pulse PWM value. Range 0 - 4096.
    • getPulseTimeMicroseconds

      Get the PWM value directly from the hardware.

      Read a raw value from a PWM channel.

      Returns:
      Microsecond pulse PWM control value. Range: 0 - 4096.
    • setDisabled

      public final void setDisabled()
      Temporarily disables the PWM output. The next set call will re-enable the output.
    • setOutputPeriod

      public void setOutputPeriod(PWM.OutputPeriod mult)
      Sets the PWM output period.
      Parameters:
      mult - The output period to apply to this channel
    • getHandle

      public int getHandle()
      Get the underlying handle.
      Returns:
      Underlying PWM handle
    • setSimDevice

      public void setSimDevice(SimDevice device)
      Indicates this input is used by a simulated device.
      Parameters:
      device - simulated device handle
    • initSendable

      public void initSendable(SendableBuilder builder)
      Description copied from interface: Sendable
      Initializes this Sendable object.
      Specified by:
      initSendable in interface Sendable
      Parameters:
      builder - sendable builder