WPILib 2012
WPILibRoboticsLibraryforFRC
|
#include <AnalogModule.h>
Public Member Functions | |
void | SetSampleRate (float samplesPerSecond) |
float | GetSampleRate () |
void | SetAverageBits (UINT32 channel, UINT32 bits) |
UINT32 | GetAverageBits (UINT32 channel) |
void | SetOversampleBits (UINT32 channel, UINT32 bits) |
UINT32 | GetOversampleBits (UINT32 channel) |
INT16 | GetValue (UINT32 channel) |
INT32 | GetAverageValue (UINT32 channel) |
float | GetAverageVoltage (UINT32 channel) |
float | GetVoltage (UINT32 channel) |
UINT32 | GetLSBWeight (UINT32 channel) |
INT32 | GetOffset (UINT32 channel) |
INT32 | VoltsToValue (INT32 channel, float voltage) |
Static Public Member Functions | |
static AnalogModule * | GetInstance (UINT8 moduleNumber) |
Static Public Attributes | |
static const long | kTimebase = 40000000 |
40 MHz clock | |
static const long | kDefaultOversampleBits = 0 |
static const long | kDefaultAverageBits = 7 |
static const float | kDefaultSampleRate = 50000.0 |
Protected Member Functions | |
AnalogModule (UINT8 moduleNumber) | |
virtual | ~AnalogModule () |
Friends | |
class | Module |
Analog Module class. Each module can independently sample its channels at a configurable rate. There is a 64-bit hardware accumulator associated with channel 1 on each module. The accumulator is attached to the output of the oversample and average engine so that the center value can be specified in higher resolution resulting in less error.
AnalogModule::AnalogModule | ( | UINT8 | moduleNumber | ) | [explicit, protected] |
Create a new instance of an analog module.
Create an instance of the analog module object. Initialize all the parameters to reasonable values on start. Setting a global value on an analog module can be done only once unless subsequent values are set the previously set value. Analog modules are a singleton, so the constructor is never called outside of this class.
moduleNumber | The analog module to create (1 or 2). |
AnalogModule::~AnalogModule | ( | ) | [protected, virtual] |
Destructor for AnalogModule.
UINT32 AnalogModule::GetAverageBits | ( | UINT32 | channel | ) |
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.
channel | Channel to address. |
INT32 AnalogModule::GetAverageValue | ( | UINT32 | channel | ) |
Get a sample from the output of the oversample and average engine for the channel.
The sample is 12-bit + the value 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**(OversamplBits + AverageBits) samples have been acquired from the module on this channel. Use GetAverageVoltage() to get the analog value in calibrated units.
channel | Channel number to read. |
float AnalogModule::GetAverageVoltage | ( | UINT32 | channel | ) |
Get a scaled sample from the output of the oversample and average engine for the 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.
channel | The channel to read. |
AnalogModule * AnalogModule::GetInstance | ( | UINT8 | moduleNumber | ) | [static] |
Get an instance of an Analog Module.
Singleton analog module creation where a module is allocated on the first use and the same module is returned on subsequent uses.
moduleNumber | The analog module to get (1 or 2). |
UINT32 AnalogModule::GetLSBWeight | ( | UINT32 | channel | ) |
Get the factory scaling least significant bit weight constant. The least significant bit weight constant for the channel that was calibrated in manufacturing and stored in an eeprom in the module.
Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
channel | The channel to get calibration data for. |
INT32 AnalogModule::GetOffset | ( | UINT32 | channel | ) |
Get the factory scaling offset constant. The offset constant for the channel that was calibrated in manufacturing and stored in an eeprom in the module.
Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
channel | The channel to get calibration data for. |
UINT32 AnalogModule::GetOversampleBits | ( | UINT32 | channel | ) |
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.
channel | Channel to address. |
float AnalogModule::GetSampleRate | ( | ) |
Get the current sample rate on the module.
This assumes one entry in the scan list. This is a global setting for the module and effects all channels.
INT16 AnalogModule::GetValue | ( | UINT32 | channel | ) |
Get a sample straight from the channel on this module.
The sample is a 12-bit value representing the -10V to 10V range of the A/D converter in the module. The units are in A/D converter codes. Use GetVoltage() to get the analog value in calibrated units.
float AnalogModule::GetVoltage | ( | UINT32 | channel | ) |
Get a scaled sample straight from the channel on this module.
The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() and GetOffset().
channel | The channel to read. |
void AnalogModule::SetAverageBits | ( | UINT32 | channel, |
UINT32 | bits | ||
) |
Set the number of averaging bits.
This sets the number of averaging bits. The actual number of averaged samples is 2**bits. Use averaging to improve the stability of your measurement at the expense of sampling rate. The averaging is done automatically in the FPGA.
channel | Analog channel to configure. |
bits | Number of bits to average. |
void AnalogModule::SetOversampleBits | ( | UINT32 | channel, |
UINT32 | bits | ||
) |
Set the number of oversample bits.
This sets the number of oversample bits. The actual number of oversampled values is 2**bits. Use oversampling to improve the resolution of your measurements at the expense of sampling rate. The oversampling is done automatically in the FPGA.
channel | Analog channel to configure. |
bits | Number of bits to oversample. |
void AnalogModule::SetSampleRate | ( | float | samplesPerSecond | ) |
Set the sample rate on the module.
This is a global setting for the module and effects all channels.
samplesPerSecond | The number of samples per channel per second. |
INT32 AnalogModule::VoltsToValue | ( | INT32 | channel, |
float | voltage | ||
) |
Convert a voltage to a raw value for a specified channel.
This process depends on the calibration of each channel, so the channel must be specified.
channel | The channel to convert for. |
voltage | The voltage to convert. |