AnalogModule Class Reference

#include <AnalogModule.h>

Inherits Module.

List of all members.

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 AnalogModuleGetInstance (unsigned slot)

Static Public Attributes

static const long kTimebase = 40000000
 40 MHz clock

Protected Member Functions

 AnalogModule (unsigned slot)
virtual ~AnalogModule ()


Detailed Description

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.

Constructor & Destructor Documentation

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.

Parameters:
slot The slot in the chassis that the module is plugged into.

AnalogModule::~AnalogModule (  )  [protected, virtual]

Destructor for AnalogModule.


Member Function Documentation

void AnalogModule::SetSampleRate ( float  samplesPerSecond  ) 

Set the sample rate on the module.

This is a global setting for the module and effects all channels.

Parameters:
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.

Returns:
Sample rate.

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.

Parameters:
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.

Parameters:
channel Channel to address.
Returns:
Bits to average.

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.

Parameters:
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.

Parameters:
channel Channel to address.
Returns:
Bits to oversample.

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.

Returns:
A sample straight from the channel on this module.

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.

Parameters:
channel Channel number to read.
Returns:
A sample from the oversample and average engine for the channel.

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.

Parameters:
channel The channel to read.
Returns:
A scaled sample from the output of the oversample and average engine for the channel.

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().

Parameters:
channel The channel to read.
Returns:
A scaled sample straight from the channel on this module.

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)

Parameters:
channel The channel to get calibration data for.
Returns:
Least significant bit weight.

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)

Parameters:
channel The channel to get calibration data for.
Returns:
Offset constant.

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.

Todo:
This assumes raw values. Oversampling not supported as is.
Parameters:
channel The channel to convert for.
voltage The voltage to convert.
Returns:
The raw value for the channel.

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.

Parameters:
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.

Returns:
The 64-bit value accumulated since the last Reset().

unsigned AnalogModule::GetAccumulatorCount ( void   ) 

Read the number of accumulated values.

Read the count of the accumulated values since the accumulator was last Reset().

Returns:
The number of times samples from the channel were accumulated.

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.

Parameters:
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.

Parameters:
slot The slot in the chassis where the module is plugged in.
Returns:
An index to represent the module internally.

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.

Parameters:
slot The physical slot in the cRIO chassis where this analog module is installed.
Returns:
A pointer to the AnalogModule.


The documentation for this class was generated from the following files:

Generated on Thu Oct 2 14:01:22 2008 for WPI Robotics Library by  doxygen 1.5.5