Class PWM
java.lang.Object
org.wpilib.hardware.discrete.PWM
- All Implemented Interfaces:
AutoCloseable, TelemetryLoggable
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Free the resource associated with the PWM channel and set the value to 0.intGets the channel number associated with the PWM Object.intGet the underlying handle.final intGet the PWM value directly from the hardware.Gets the telemetry table type.voidlogTo(TelemetryTable table) Logs the object to aTelemetryTable.final voidTemporarily disables the PWM output.voidsetOutputPeriod(int millisecondPeriod) Sets the PWM output period.final voidsetPulseTimeMicroseconds(int microsecondPulseTime) Set the PWM value directly to the hardware.voidsetSimDevice(SimDevice device) Indicates this input is used by a simulated device.
-
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.
- Parameters:
channel- The SmartIO channel number.
-
-
Method Details
-
close
public void close()Free the resource associated with the PWM channel and set the value to 0.- Specified by:
closein interfaceAutoCloseable
-
getChannel
public int getChannel()Gets the channel number associated with the PWM Object.- Returns:
- The channel number.
-
setPulseTimeMicroseconds
public final 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
public final int 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(int millisecondPeriod) Sets the PWM output period.- Parameters:
millisecondPeriod- The output period to apply to this channel, in milliseconds. Valid values are 5ms, 10ms, and 20ms. Default is 20 ms.
-
getHandle
public int getHandle()Get the underlying handle.- Returns:
- Underlying PWM handle
-
setSimDevice
Indicates this input is used by a simulated device.- Parameters:
device- simulated device handle
-
logTo
Description copied from interface:TelemetryLoggableLogs the object to aTelemetryTable.- Specified by:
logToin interfaceTelemetryLoggable- Parameters:
table- telemetry table
-
getTelemetryType
Description copied from interface:TelemetryLoggableGets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.- Specified by:
getTelemetryTypein interfaceTelemetryLoggable- Returns:
- Table type
-