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

AnalogChannel Class Reference

#include <AnalogChannel.h>

Inheritance diagram for AnalogChannel:
Collaboration diagram for AnalogChannel:

List of all members.

Public Member Functions

 AnalogChannel (UINT8 moduleNumber, UINT32 channel)
 AnalogChannel (UINT32 channel)
virtual ~AnalogChannel ()
AnalogModuleGetModule ()
INT16 GetValue ()
INT32 GetAverageValue ()
float GetVoltage ()
float GetAverageVoltage ()
UINT8 GetModuleNumber ()
UINT32 GetChannel ()
void SetAverageBits (UINT32 bits)
UINT32 GetAverageBits ()
void SetOversampleBits (UINT32 bits)
UINT32 GetOversampleBits ()
UINT32 GetLSBWeight ()
INT32 GetOffset ()
bool IsAccumulatorChannel ()
void InitAccumulator ()
void SetAccumulatorInitialValue (INT64 value)
void ResetAccumulator ()
void SetAccumulatorCenter (INT32 center)
void SetAccumulatorDeadband (INT32 deadband)
INT64 GetAccumulatorValue ()
UINT32 GetAccumulatorCount ()
void GetAccumulatorOutput (INT64 *value, UINT32 *count)
double PIDGet ()

Static Public Attributes

static const UINT8 kAccumulatorModuleNumber = 1
static const UINT32 kAccumulatorNumChannels = 2
static const UINT32 kAccumulatorChannels [kAccumulatorNumChannels] = {1, 2}

Detailed Description

Analog channel class.

Each analog channel is read from hardware as a 12-bit number representing -10V to 10V.

Connected to each analog channel is an averaging and oversampling engine. This engine accumulates the specified ( by SetAverageBits() and SetOversampleBits() ) number of samples before returning a new value. This is not a sliding window average. The only difference between the oversampled samples and the averaged samples is that the oversampled samples are simply accumulated effectively increasing the resolution, while the averaged samples are divided by the number of samples to retain the resolution, but get more stable values.

Definition at line 28 of file AnalogChannel.h.


Constructor & Destructor Documentation

AnalogChannel::AnalogChannel ( UINT8  moduleNumber,
UINT32  channel 
)

Construct an analog channel on a specified module.

Parameters:
moduleNumber The analog module (1 or 2).
channel The channel number to represent.

Definition at line 65 of file AnalogChannel.cpp.

AnalogChannel::AnalogChannel ( UINT32  channel  )  [explicit]

Construct an analog channel on the default module.

Parameters:
channel The channel number to represent.

Definition at line 75 of file AnalogChannel.cpp.

AnalogChannel::~AnalogChannel (  )  [virtual]

Channel destructor.

Definition at line 83 of file AnalogChannel.cpp.


Member Function Documentation

UINT32 AnalogChannel::GetAccumulatorCount (  ) 

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.

Definition at line 377 of file AnalogChannel.cpp.

void AnalogChannel::GetAccumulatorOutput ( INT64 *  value,
UINT32 *  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.

Definition at line 401 of file AnalogChannel.cpp.

INT64 AnalogChannel::GetAccumulatorValue (  ) 

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

Definition at line 356 of file AnalogChannel.cpp.

UINT32 AnalogChannel::GetAverageBits (  ) 

Get the number of averaging bits previously configured. 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.

Returns:
Number of bits of averaging previously configured.

Definition at line 220 of file AnalogChannel.cpp.

INT32 AnalogChannel::GetAverageValue (  ) 

Get a sample from the output of the oversample and average engine for this 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.

Returns:
A sample from the oversample and average engine for this channel.

Definition at line 119 of file AnalogChannel.cpp.

float AnalogChannel::GetAverageVoltage (  ) 

Get a scaled sample from the output of the oversample and average engine for this 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.

Returns:
A scaled sample from the output of the oversample and average engine for this channel.

Definition at line 143 of file AnalogChannel.cpp.

UINT32 AnalogChannel::GetChannel (  ) 

Get the channel number.

Returns:
The channel number.

Definition at line 183 of file AnalogChannel.cpp.

UINT32 AnalogChannel::GetLSBWeight (  ) 

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)

Returns:
Least significant bit weight.

Definition at line 158 of file AnalogChannel.cpp.

AnalogModule * AnalogChannel::GetModule (  ) 

Get the analog module that this channel is on.

Returns:
A pointer to the AnalogModule that this channel is on.

Definition at line 92 of file AnalogChannel.cpp.

UINT8 AnalogChannel::GetModuleNumber (  ) 

Get the module number.

Returns:
The module number.

Definition at line 193 of file AnalogChannel.cpp.

INT32 AnalogChannel::GetOffset (  ) 

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)

Returns:
Offset constant.

Definition at line 173 of file AnalogChannel.cpp.

UINT32 AnalogChannel::GetOversampleBits (  ) 

Get the number of oversample bits previously configured. 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.

Returns:
Number of bits of oversampling previously configured.

Definition at line 247 of file AnalogChannel.cpp.

INT16 AnalogChannel::GetValue (  ) 

Get a sample straight from this channel on the 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 this channel on the module.

Definition at line 104 of file AnalogChannel.cpp.

float AnalogChannel::GetVoltage (  ) 

Get a scaled sample straight from this channel on the module. The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() and GetOffset().

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

Definition at line 130 of file AnalogChannel.cpp.

void AnalogChannel::InitAccumulator (  ) 

Initialize the accumulator.

Definition at line 272 of file AnalogChannel.cpp.

bool AnalogChannel::IsAccumulatorChannel (  ) 

Is the channel attached to an accumulator.

Returns:
The analog channel is attached to an accumulator.

Definition at line 258 of file AnalogChannel.cpp.

double AnalogChannel::PIDGet (  )  [virtual]

Get the Average voltage for the PID Source base object.

Returns:
The average voltage.

Implements PIDSource.

Definition at line 427 of file AnalogChannel.cpp.

void AnalogChannel::ResetAccumulator (  ) 

Resets the accumulator to the initial value.

Definition at line 296 of file AnalogChannel.cpp.

void AnalogChannel::SetAccumulatorCenter ( INT32  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.

Definition at line 319 of file AnalogChannel.cpp.

void AnalogChannel::SetAccumulatorDeadband ( INT32  deadband  ) 

Set the accumulator's deadband.

Definition at line 335 of file AnalogChannel.cpp.

void AnalogChannel::SetAccumulatorInitialValue ( INT64  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.

Definition at line 287 of file AnalogChannel.cpp.

void AnalogChannel::SetAverageBits ( 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:
bits Number of bits of averaging.

Definition at line 207 of file AnalogChannel.cpp.

void AnalogChannel::SetOversampleBits ( 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:
bits Number of bits of oversampling.

Definition at line 234 of file AnalogChannel.cpp.


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

Generated on Thu Jan 12 2012 22:35:26 for WPILibC++ by doxygen 1.7.1