#include <AnalogModule.h>
Inherits Module.
Public Member Functions | |
void | SetSampleRate (float samplesPerSecond) |
float | GetSampleRate (void) |
void | SetAverageBits (unsigned channel, unsigned bits) |
unsigned | GetAverageBits (unsigned channel) |
void | SetOversampleBits (unsigned channel, unsigned bits) |
unsigned | GetOversampleBits (unsigned channel) |
signed short | GetValue (unsigned channel) |
signed int | GetAverageValue (unsigned channel) |
float | GetAverageVoltage (unsigned channel) |
float | GetVoltage (unsigned channel) |
unsigned int | GetLSBWeight (unsigned channel) |
signed int | GetOffset (unsigned channel) |
signed int | VoltsToValue (int channel, float voltage) |
void | InitAccumulator (void) |
void | SetAccumulatorInitialValue (long long value) |
void | ResetAccumulator (void) |
void | SetAccumulatorCenter (int center) |
signed long long | GetAccumulatorValue (void) |
unsigned int | GetAccumulatorCount (void) |
void | GetAccumulatorOutput (long long *value, unsigned *count) |
Static Public Member Functions | |
static unsigned | SlotToIndex (unsigned slot) |
static AnalogModule * | GetInstance (unsigned slot) |
Static Public Attributes | |
static const long | kTimebase = 40000000 |
40 MHz clock | |
Protected Member Functions | |
AnalogModule (unsigned slot) | |
virtual | ~AnalogModule () |
AnalogModule::AnalogModule | ( | unsigned | slot | ) | [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.
slot | The slot in the chassis that the module is plugged into. |
AnalogModule::~AnalogModule | ( | ) | [protected, virtual] |
Destructor for AnalogModule.
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. |
float AnalogModule::GetSampleRate | ( | void | ) |
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.
void AnalogModule::SetAverageBits | ( | unsigned | channel, | |
unsigned | 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. |
unsigned AnalogModule::GetAverageBits | ( | unsigned | 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. |
void AnalogModule::SetOversampleBits | ( | unsigned | channel, | |
unsigned | 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. |
unsigned AnalogModule::GetOversampleBits | ( | unsigned | 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. |
signed short AnalogModule::GetValue | ( | unsigned | 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.
signed int AnalogModule::GetAverageValue | ( | unsigned | 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 | ( | unsigned | 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. |
float AnalogModule::GetVoltage | ( | unsigned | 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. |
unsigned int AnalogModule::GetLSBWeight | ( | unsigned | 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. |
signed int AnalogModule::GetOffset | ( | unsigned | 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. |
signed int AnalogModule::VoltsToValue | ( | int | 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. |
void AnalogModule::InitAccumulator | ( | void | ) |
Initialize the accumulator.
void AnalogModule::SetAccumulatorInitialValue | ( | long long | initialValue | ) |
Set an inital value for the accumulator.
This will be added to all values returned to the user.
initialValue | The value that the accumulator should start from when reset. |
void AnalogModule::ResetAccumulator | ( | void | ) |
Resets the accumulator to the initial value.
void AnalogModule::SetAccumulatorCenter | ( | int | center | ) |
Set the center value of the accumulator.
The center value is subtracted from each A/D value before it is added to the accumulator. This is used for the center value of devices like gyros and accelerometers to make integration work and to take the device offset into account when integrating.
This center value is based on the output of the oversampled and averaged source from channel 1. Because of this, any non-zero oversample bits will affect the size of the value for this field.
signed long long AnalogModule::GetAccumulatorValue | ( | void | ) |
Read the accumulated value.
Read the value that has been accumulating on channel 1. The accumulator is attached after the oversample and average engine.
unsigned AnalogModule::GetAccumulatorCount | ( | void | ) |
Read the number of accumulated values.
Read the count of the accumulated values since the accumulator was last Reset().
void AnalogModule::GetAccumulatorOutput | ( | long long * | value, | |
unsigned * | count | |||
) |
Read the accumulated value and the number of accumulated values atomically.
This function reads the value and count from the FPGA atomically. This can be used for averaging.
value | Pointer to the 64-bit accumulated output. | |
count | Pointer to the number of accumulation cycles. |
unsigned AnalogModule::SlotToIndex | ( | unsigned | slot | ) | [static] |
Convert slot number to index.
slot | The slot in the chassis where the module is plugged in. |
AnalogModule * AnalogModule::GetInstance | ( | unsigned | slot | ) | [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.
slot | The physical slot in the cRIO chassis where this analog module is installed. |