#include <rb8905_adc12.h>
Inherits RulbusDevice.
Measure a voltage trace.
Module RB8905 is a 1 Mega-sample per second 12-bit analog to digital converter with a 32 kByte on-board data buffer.
The module has a single analog input and a clock input to do a series of data acquisitions. The number of samples to store on-board is programmable. Also, the ADC can be programmed for bipolar or unipolar use.
Module RB8905 contains the following parts:
The analog to digital converter IC is an ADC601 manufactured by Burr-Brown. This 12-bit ADC normally converts samples at a rate of 1 Ms/s (900 ns), but it also can convert at a rate of 2 Ms/s (400 ns). In the latter case, only eight bits are determined and this mode of operation is called short-cycle mode (fast mode, 8-bit result).
When the fast conversion mode (8-bit result) is used, the data bytes are put in the on-board buffer at consecutive addresses. With the normal conversion mode (12-bit result), the order is low order byte, high order byte.
The number of samples to store on-board can be specified in one of two ways (normal conversion mode assumed):
The number of samples is a power of two: 256, 512, 1024, etc.
At production time, the input voltage span of the ADC is configured for 10 V or 20 V.
The module cannot be queried about this setting, so the voltage span must be specified through the constructor when an ADC object is created. An ADC is created with the following defaults:
.*) via constructor default argument
The following table shows the volt-per-bit values for the various input voltage spans.
Voltage span | volt-per-bit bipolar ---------------+-------------------------- 0 .. 10 V | 2.442002 mV no -5 .. 5 V | 2.442002 mV yes -10 .. 10 V | 4.884004 mV yes
Note that when the ADC's fast conversion mode (8-bit result) is used, the input voltage span is reduced with a factor of 16 (2^4). See minInputVoltage() and maxInputVoltage().
Among other methods, the class provides methods to set the conversion mode, to set the input voltage polarity, to set the number of samples to acquire and to read the input as ADC-value or as voltage at the ADC's input.
const int N = 512; Rulbus::Volt32 trace[ N ]; Rulbus::RB8905_Adc12 adc( "adc" ); adc.setBufferCapacity( N ); adc.arm(); while ( !adc.isReady() ) wait(); int n = adc.readVoltage( trace, N );
The key parts of module RB8905 are the sample and hold, ADC, address counter and memory IC. The table below shows how these parts can be controlled and how information can be obtained from them.
Register Offset Rd/Wr Description ------------------------------------------------------------------------------ Data 0 read ADC data from buffer Status 1 read Status register 76543210 7 : end of data acquisition / end of read-out 1: ready 0: busy 6543210 : not used Control 0 write Control register 76543210 7 : ADC polarity 1: unipolar 0: bipolar 6 : Rulbus interrupt enable 1: enable 0: disable 5 : clear address counter 1: clear 0: count 4 : ADC data size 1: 8-bit short-cyle, fast mode 0: 12-bit 3 : read/write memory 1: read 0: write 210 : buffer size [byte] 0 2..256 (size selected with JMP3) 1 512 2 1024 3 2048 4 4096 5 8192 6 16384 7 32768
The Burr-Brown ADC601 analog to digital converter presents the conversion data as follows:
Scale | Offset Binary 1's Complement ------------+-------------------------------- +full scale | 1111...1111 0111...1111 +zero | 1000...0000 0000...0000 -zero | --- 1111...1111 -full scale | 0000...0000 1000...0000 Information from Intersil Application Note AN9657.1, may 1997.
Please note that method getValue() returns the unipolar samples as (unsigned) binary magnitude codes and that it returns bipolar samples as offset binary codes.
Public Types | |
typedef Int | Value |
conversion sample value type | |
Public Member Functions | |
Construction | |
RB8905_Adc12 (NameCref aName, Addr aAddr=DEF_ADDR, Rack aRack=DEF_RACK, Real aVoltPerBit=DEF_VPB) | |
constructor. | |
~RB8905_Adc12 () | |
destructor. | |
Data acquisition | |
void | arm () |
arm ADC for data-acquisition; a sample is taken each clock-pulse. | |
bool | isReady () const |
true if all samples have been measured or if all samples have been read-out. | |
int | readVoltage (Volt32 *pVoltage, int nelem) |
read nelem elements as voltage from the on-board data buffer, return number of elements actually read; note the voltage type Rulbus::Volt32. | |
int | readValue (Int16 *pValue, int nelem) |
read nelem elements as value from the on-board data buffer, return number of elements actually read; note the value type Rulbus::Int16; see also getValue(). | |
Value | getValue () |
the next 8-bit/12-bit unipolar/bipolar sample from the on-board buffer; unipolar samples are presented as (unsigned) magnitude codes, bipolar values are presented as offset binary codes. | |
Value | getRawValue () |
the next raw 8-bit or 12-bit sample from the on-board buffer. | |
Accessors | |
bool | isFastMode () const |
true if fast (short-cycle) mode is selected (8-bit data). | |
bool | isUnipolarMode () const |
true if unipolar mode is selected. | |
bool | isEnabledInterrupt () const |
true if Rulbus interrupt is enabled. | |
int | bufferCapacity () const |
the number of samples to acquire in the on-board buffer. | |
int | jmp3BufferCapacity () const |
the JMP3 setting for the number of samples to store on-board. | |
Real | voltperbit () const |
the ADC's input sensitivity configuration. | |
Volt | voltageSpan () const |
the ADC input voltage span. | |
Volt | offsetVoltage () const |
the ADC offset voltage. | |
Volt | minInputVoltage () const |
the lowest acceptable ADC input voltage; takes mode settings into account. | |
Volt | maxInputVoltage () const |
the highest acceptable ADC input voltage; takes mode settings into account. | |
Mutators | |
void | setFastMode () |
set converter to fast or short-cycle mode (8-bit data). | |
void | setNormalMode () |
set converter to normal mode (12-bit data). | |
void | setBipolarMode () |
set converter to bipolar mode. | |
void | setUnipolarMode () |
set converter to unipolar mode. | |
bool | enableInterrupt (bool enable=true) |
enable (disable) Rulbus interrupt, return true if interrupt was enabled. | |
void | setBufferCapacity (int nelem=CON_JMP3) |
set the number of samples to acquire in the buffer; use JMP3 setting when no length (or zero) is specified; value cached here, used in arm(). | |
Static Public Attributes | |
Defaults | |
const Addr | DEF_ADDR = 0xBC |
default address | |
const float | DEF_VPB = 10.0 / 4095.0 |
the default ADC input sensitivity (10.0 V full scale). | |
const int | DEF_SAMPLES = 256 |
default number of samples | |
Constants | |
const int | CON_JMP3 = 0 |
JMP3 selector for number of samples to store in on-board buffer. | |
const int | CON_TRELAIS = 20 |
ms to wait for polarity reed-relais to statbilize | |
Protected Member Functions | |
Construction and assignment | |
RB8905_Adc12 () | |
prevent default construction | |
RB8905_Adc12 (RB8905_Adc12Cref rhs) | |
prevent copying | |
RB8905_Adc12Ref | operator= (RB8905_Adc12Cref rhs) |
prevent copying | |
Read & write mode | |
void | setReadMode () |
select data read mode and clear address counter. | |
void | setWriteMode () |
select data write mode and clear address counter. | |
Tools | |
void | clearAddress () |
clear on-board buffer address counter. | |
int | elemSize () const |
the number of bytes per sample. | |
int | bufferSize () const |
the number of bytes to acquire in the on-board buffer. | |
void | setBufferSize (int aSize=CON_JMP3) |
set the number of bytes to acquire in the on-board buffer; use Jmp3 setting when no size (or zero) specified. | |
void | setBufferCode (int aCode) |
set buffer size selector to specifieed value. | |
int | jmp3BufferSize () const |
the JMP3 setting for the number of bytes to store on-board. | |
int | detectJmp3BufferSize () |
detect the JMP3 determined number of bytes setting. | |
void | checkRead (int nelem) |
throw RulbusContextError if requested number of elements is smaller than one or if it exceeds number available. | |
void | waitRelais () |
enable unipolar/bipolar mode reed-relais to stabilize. | |
Private Attributes | |
Data | |
Byte | theControlRegister |
control-register contents | |
Real | theVoltPerBit |
ADC input sensitivity. | |
int | theJmp3BufferSize |
number of bytes to buffer for JMP3 setting (cached), obtained in constructor with detectJmp3BufferSize() | |
int | theBufferCapacity |
number of samples as requested via setBufferCapacity(); used in arm() | |
Static Private Attributes | |
Register offsets | |
const int | OFF_CTL = 0 |
control-register | |
const int | OFF_ADC = 0 |
ADC data. | |
const int | OFF_STS = 1 |
status-register | |
const int | ADR_WIDTH = OFF_STS + 1 |
address width | |
Limits | |
const Value | LIM_MINVAL8 = 0x000 |
minimum value | |
const Value | LIM_MAXVAL8 = 0x0FF |
maximum value | |
const Value | LIM_MINVAL12 = 0x000 |
minimum value | |
const Value | LIM_MAXVAL12 = 0xFFF |
maximum value | |
const int | LIM_MINJMP3SIZE = 2 |
lowest valid JMP3 buffer size | |
const int | LIM_MAXJMP3SIZE = 256 |
highest valid JMP3 buffer size | |
const int | LIM_MINBUFSIZE = 512 |
lowest valid non-JMP3 buffer size | |
const int | LIM_MAXBUFSIZE = 32768 |
highest valid non-JMP3 buffer size | |
Signal masks and shifts | |
const int | MSK_CTLBSIZE = 0x07 |
mask for number of bytes to buffer | |
const int | MSK_CTLREAD = 0x08 |
mask for read/write | |
const int | MSK_CTLFAST = 0x10 |
mask for fast (short-cycle) mode (8-bit data) | |
const int | MSK_CTLCLEAR = 0x20 |
mask for clear address counter | |
const int | MSK_CTLINTR = 0x40 |
mask for interrupt enable | |
const int | MSK_CTLUNIP = 0x80 |
mask for unipolar mode | |
const int | MSK_STSREADY = 0x80 |
mask for status:ready | |
const int | MSK_ADCALL12 = 0x0FFF |
mask for significant bits in ADC code (12-bit) | |
const int | MSK_ADCALL8 = 0x00FF |
mask for significant bits in ADC code (8-bit) | |
const int | MSK_ADCMSB12 = 0x0800 |
mask for most significant bit in ADC code (12-bit) | |
const int | MSK_ADCMSB8 = 0x0080 |
mask for most significant bit in ADC code (8-bit) |