Now you can download a copy of these docs so you can use them offline! Download now

#include <AnalogModule.h>

Inheritance diagram for AnalogModule:
Collaboration diagram for AnalogModule:

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)
- Public Member Functions inherited from Module
nLoadOut::tModuleType GetType ()
UINT8 GetNumber ()
- Public Member Functions inherited from SensorBase
 SensorBase ()
virtual ~SensorBase ()
- Public Member Functions inherited from ErrorBase
virtual ErrorGetError ()
 Retrieve the current error. Get the current error information associated with this sensor.
virtual const ErrorGetError () const
virtual void SetErrnoError (const char *contextMessage, const char *filename, const char *function, UINT32 lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable.
virtual void SetImaqError (int success, const char *contextMessage, const char *filename, const char *function, UINT32 lineNumber) const
 Set the current error information associated from the nivision Imaq API.
virtual void SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, UINT32 lineNumber) const
 Set the current error information associated with this sensor.
virtual void SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, UINT32 lineNumber) const
 Set the current error information associated with this sensor.
virtual void CloneError (ErrorBase *rhs) const
virtual void ClearError () const
 Clear the current error information associated with this sensor.
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error.

Static Public Member Functions

static AnalogModuleGetInstance (UINT8 moduleNumber)
- Static Public Member Functions inherited from Module
static ModuleGetModule (nLoadOut::tModuleType type, UINT8 number)
- Static Public Member Functions inherited from SensorBase
static void DeleteSingletons ()
static UINT32 GetDefaultAnalogModule ()
static UINT32 GetDefaultDigitalModule ()
static UINT32 GetDefaultSolenoidModule ()
static bool CheckAnalogModule (UINT8 moduleNumber)
static bool CheckDigitalModule (UINT8 moduleNumber)
static bool CheckPWMModule (UINT8 moduleNumber)
static bool CheckRelayModule (UINT8 moduleNumber)
static bool CheckSolenoidModule (UINT8 moduleNumber)
static bool CheckDigitalChannel (UINT32 channel)
static bool CheckRelayChannel (UINT32 channel)
static bool CheckPWMChannel (UINT32 channel)
static bool CheckAnalogChannel (UINT32 channel)
static bool CheckSolenoidChannel (UINT32 channel)
- Static Public Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, UINT32 lineNumber)
static void SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, UINT32 lineNumber)
static ErrorGetGlobalError ()

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 ()
- Protected Member Functions inherited from Module
 Module (nLoadOut::tModuleType type, UINT8 number)
virtual ~Module ()
- Protected Member Functions inherited from SensorBase
void AddToSingletonList ()
- Protected Member Functions inherited from ErrorBase
 ErrorBase ()
 Initialize the instance status to 0 for now.

Friends

class Module

Additional Inherited Members

- Protected Attributes inherited from Module
nLoadOut::tModuleType m_moduleType
 The type of module represented.
UINT8 m_moduleNumber
 The module index within the module type.
- Static Protected Attributes inherited from ErrorBase
static SEM_ID _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE)
static Error _globalError

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.

Definition at line 20 of file AnalogModule.h.

Constructor & Destructor Documentation

AnalogModule::AnalogModule ( UINT8  moduleNumber)
explicitprotected

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

Definition at line 54 of file AnalogModule.cpp.

AnalogModule::~AnalogModule ( )
protectedvirtual

Destructor for AnalogModule.

Definition at line 85 of file AnalogModule.cpp.

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.

Definition at line 214 of file AnalogModule.cpp.

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.

Definition at line 298 of file AnalogModule.cpp.

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.

Definition at line 377 of file AnalogModule.cpp.

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.

Definition at line 28 of file AnalogModule.cpp.

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.

Definition at line 397 of file AnalogModule.cpp.

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.

Definition at line 415 of file AnalogModule.cpp.

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.

Definition at line 248 of file AnalogModule.cpp.

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.

Definition at line 134 of file AnalogModule.cpp.

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.

Definition at line 264 of file AnalogModule.cpp.

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.

Definition at line 358 of file AnalogModule.cpp.

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.

Definition at line 198 of file AnalogModule.cpp.

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.

Definition at line 232 of file AnalogModule.cpp.

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.

Definition at line 97 of file AnalogModule.cpp.

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.

Definition at line 332 of file AnalogModule.cpp.


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

Generated on Tue Feb 5 2013 00:55:09 for WPILibC++ by doxygen 1.8.1.2