Class AnalogInput
- All Implemented Interfaces:
Sendable
,AutoCloseable
Each analog channel is read from hardware as a 12-bit number representing 0V to 3.3V.
Connected to each analog channel is an averaging and oversampling engine. This engine accumulates the specified ( by setAverageBits() and setOversampleBits() ) number of samples before returning a new value. This is not a sliding window average. The only difference between the oversampled samples and the averaged samples is that the oversampled samples are simply accumulated effectively increasing the resolution, while the averaged samples are divided by the number of samples to retain the resolution, but get more stable values.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
int
Get the number of averaging bits.int
Get a sample from the output of the oversample and average engine for this channel.double
Get a scaled sample from the output of the oversample and average engine for this channel.int
Get the channel number.static double
Get the current sample rate.long
Get the factory scaling the least significant bit weight constant.int
Get the factory scaling offset constant.int
Get the number of oversample bits.int
getValue()
Get a sample straight from this channel.double
Get a scaled sample straight from this channel.void
initSendable
(SendableBuilder builder) Initializes thisSendable
object.void
setAverageBits
(int bits) Set the number of averaging bits.static void
setGlobalSampleRate
(double samplesPerSecond) Set the sample rate per channel.void
setOversampleBits
(int bits) Set the number of oversample bits.void
setSimDevice
(SimDevice device) Indicates this input is used by a simulated device.
-
Constructor Details
-
AnalogInput
Construct an analog channel.- Parameters:
channel
- The channel number to represent. 0-3 are on-board 4-7 are on the MXP port.
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
-
getValue
Get a sample straight from this channel. The sample is a 12-bit value representing the 0V to 3.3V range of the A/D converter. The units are in A/D converter codes. Use GetVoltage() to get the analog value in calibrated units.- Returns:
- A sample straight from this channel.
-
getAverageValue
Get a sample from the output of the oversample and average engine for this channel. The sample is 12-bit + the bits configured in SetOversampleBits(). The value configured in setAverageBits() will cause this value to be averaged 2^bits number of samples. This is not a sliding window. The sample will not change until 2^(OversampleBits + AverageBits) samples have been acquired from this channel. Use getAverageVoltage() to get the analog value in calibrated units.- Returns:
- A sample from the oversample and average engine for this channel.
-
getVoltage
Get a scaled sample straight from this channel. The value is scaled to units of Volts using the calibrated scaling data from getLSBWeight() and getOffset().- Returns:
- A scaled sample straight from this channel.
-
getAverageVoltage
Get a scaled sample from the output of the oversample and average engine for this channel. The value is scaled to units of Volts using the calibrated scaling data from getLSBWeight() and getOffset(). Using oversampling will cause this value to be higher resolution, but it will update more slowly. Using averaging will cause this value to be more stable, but it will update more slowly.- Returns:
- A scaled sample from the output of the oversample and average engine for this channel.
-
getLSBWeight
Get the factory scaling the least significant bit weight constant. The least significant bit weight constant for the channel that was calibrated in manufacturing and stored in an eeprom.Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
- Returns:
- Least significant bit weight.
-
getOffset
Get the factory scaling offset constant. The offset constant for the channel that was calibrated in manufacturing and stored in an eeprom.Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
- Returns:
- Offset constant.
-
getChannel
Get the channel number.- Returns:
- The channel number.
-
setAverageBits
Set the number of averaging bits. This sets the number of averaging bits. The actual number of averaged samples is 2^bits. The averaging is done automatically in the FPGA.- Parameters:
bits
- The number of averaging bits.
-
getAverageBits
Get the number of averaging bits. This gets the number of averaging bits from the FPGA. The actual number of averaged samples is 2^bits. The averaging is done automatically in the FPGA.- Returns:
- The number of averaging bits.
-
setOversampleBits
Set the number of oversample bits. This sets the number of oversample bits. The actual number of oversampled values is 2^bits. The oversampling is done automatically in the FPGA.- Parameters:
bits
- The number of oversample bits.
-
getOversampleBits
Get the number of oversample bits. This gets the number of oversample bits from the FPGA. The actual number of oversampled values is 2^bits. The oversampling is done automatically in the FPGA.- Returns:
- The number of oversample bits.
-
setGlobalSampleRate
Set the sample rate per channel.This is a global setting for all channels. The maximum rate is 500kS/s divided by the number of channels in use. This is 62500 samples/s per channel if all 8 channels are used.
- Parameters:
samplesPerSecond
- The number of samples per second.
-
getGlobalSampleRate
Get the current sample rate.This assumes one entry in the scan list. This is a global setting for all channels.
- Returns:
- Sample rate.
-
setSimDevice
Indicates this input is used by a simulated device.- Parameters:
device
- simulated device handle
-
initSendable
Description copied from interface:Sendable
Initializes thisSendable
object.- Specified by:
initSendable
in interfaceSendable
- Parameters:
builder
- sendable builder
-