WPILib 2012
WPILibRoboticsLibraryforFRC
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Friends
AnalogModule Class Reference

#include <AnalogModule.h>

Inheritance diagram for AnalogModule:
Module SensorBase ErrorBase

List of all members.

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 AnalogModuleGetInstance (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

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

Parameters:
moduleNumberThe analog module to create (1 or 2).
AnalogModule::~AnalogModule ( ) [protected, virtual]

Destructor for AnalogModule.


Member Function Documentation

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.

Parameters:
channelChannel to address.
Returns:
Bits to average.
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.

Parameters:
channelChannel number to read.
Returns:
A sample from the oversample and average engine for the channel.
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.

Parameters:
channelThe channel to read.
Returns:
A scaled sample from the output of the oversample and average engine for the channel.
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.

Parameters:
moduleNumberThe analog module to get (1 or 2).
Returns:
A pointer to the AnalogModule.
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)

Parameters:
channelThe channel to get calibration data for.
Returns:
Least significant bit weight.
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)

Parameters:
channelThe channel to get calibration data for.
Returns:
Offset constant.
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.

Parameters:
channelChannel to address.
Returns:
Bits to oversample.
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.

Returns:
Sample rate.
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.

Returns:
A sample straight from the channel on this module.
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().

Parameters:
channelThe channel to read.
Returns:
A scaled sample straight from the channel on this module.
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.

Parameters:
channelAnalog channel to configure.
bitsNumber 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.

Parameters:
channelAnalog channel to configure.
bitsNumber 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.

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

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

The documentation for this class was generated from the following files:
 All Classes Functions Variables