Analog¶
See the Analog Entity for generic information.
- class brainstem.entity.Analog(module, index)[source]¶
Interface to analog entities on BrainStem modules. Analog entities may be configured as a input or output depending on hardware capabilities. Some modules are capable of providing actual voltage readings, while other simply return the raw analog-to-digital converter (ADC) output value. The resolution of the voltage or number of useful bits is also hardware dependent.
- getBulkCaptureNumberOfSamples()[source]¶
Get the current number of samples setting for this analog when bulk capturing.
- Returns:
- Object containing error code and returned value on success.
- errorunsigned byte
An error result from the list of defined error codes
- valueunsigned int
number of samples.
- Return type:
- getBulkCaptureSampleRate()[source]¶
Get the current sample rate setting for this analog when bulk capturing.
- Returns:
- Object containing error code and returned value on success.
- errorunsigned byte
An error result from the list of defined error codes
- valueunsigned int
upon success filled with current sample rate in samples per second (Hertz).
- Return type:
- getBulkCaptureState()[source]¶
Get the current bulk capture state for this analog.
- Returns:
- Object containing error code and returned value on success.
- errorunsigned byte
An error result from the list of defined error codes
- valueunsigned char
the state of bulk capture. - Idle: bulkCaptureIdle = 0 - Pending: bulkCapturePending = 1 - Finished: bulkCaptureFinished = 2 - Error: bulkCaptureError = 3
- Return type:
- getConfiguration()[source]¶
Get the analog configuration.
- Returns:
- Object containing error code and returned value on success.
- errorunsigned byte
An error result from the list of defined error codes
- valueunsigned char
Current configuration of the analog entity.
- Return type:
- getEnable()[source]¶
Get the analog output enable status.
- Returns:
- Object containing error code and returned value on success.
- errorunsigned byte
An error result from the list of defined error codes
- valuebool
0 if disabled 1 if enabled.
- Return type:
- getRange()[source]¶
Get the analog input range.
- Returns:
- Object containing error code and returned value on success.
- errorunsigned byte
An error result from the list of defined error codes
- valueunsigned char
8 bit value corresponding to a discrete range option
- Return type:
- getValue()[source]¶
Get the raw ADC output value in bits.
Note
Not all modules are provide 16 useful bits; this value’s least significant bits are zero-padded to 16 bits. Refer to the module’s datasheet to determine analog bit depth and reference voltage.
- Returns:
- Object containing error code and returned value on success.
- errorunsigned byte
An error result from the list of defined error codes
- valueunsigned short
16 bit analog reading with 0 corresponding to the negative analog voltage reference and 0xFFFF corresponding to the positive analog voltage reference.
- Return type:
- getVoltage()[source]¶
Get the scaled micro volt value with reference to ground.
Note
Not all modules provide 32 bits of accuracy. Refer to the module’s datasheet to determine the analog bit depth and reference voltage.
- Returns:
- Object containing error code and returned value on success.
- errorunsigned byte
An error result from the list of defined error codes
- valueint
32 bit signed integer (in microvolts) based on the board’s ground and reference voltages.
- Return type:
- initiateBulkCapture()[source]¶
Initiate a BulkCapture on this analog. Captured measurements are stored in the module’s RAM store (RAM_STORE) slot 0. Data is stored in a contiguous byte array with each sample stored in two consecutive bytes, LSB first.
Note
When the bulk capture is complete getBulkCaptureState() will return either bulkCaptureFinished or bulkCaptureError.
- Returns:
An error result from the list of defined error codes in brainstem.result.Result
- Return type:
unsigned byte
- setBulkCaptureNumberOfSamples(value)[source]¶
Set the number of samples to capture for this analog when bulk capturing.
- Parameters:
value (unsigned int) – number of samples. - Minimum # of Samples: 0 - Maximum # of Samples: (BRAINSTEM_RAM_SLOT_SIZE / 2) = (3FFF / 2) = 1FFF = 8191
- Returns:
An error result from the list of defined error codes in brainstem.result.Result
- Return type:
unsigned byte
- setBulkCaptureSampleRate(value)[source]¶
Set the sample rate for this analog when bulk capturing.
- Parameters:
value (unsigned int) – sample rate in samples per second (Hertz). - Minimum rate: 7,000 Hz - Maximum rate: 200,000 Hz
- Returns:
An error result from the list of defined error codes in brainstem.result.Result
- Return type:
unsigned byte
- setConfiguration(configuration)[source]¶
Set the analog configuration.
- Parameters:
configuration (unsigned char) – bitAnalogConfigurationOutput configures the analog entity as an output.
- Returns:
An error result from the list of defined error codes in brainstem.result.Result
- Return type:
unsigned byte
- setEnable(enable)[source]¶
Set the analog output enable state.
- Parameters:
enable (bool) – set 1 to enable or 0 to disable.
- Returns:
An error result from the list of defined error codes in brainstem.result.Result
- Return type:
unsigned byte
- setRange(range)[source]¶
Set the analog input range.
- Parameters:
range (unsigned char) – 8 bit value corresponding to a discrete range option
- Returns:
An error result from the list of defined error codes in brainstem.result.Result
- Return type:
unsigned byte
- setValue(value)[source]¶
Set the value of an analog output (DAC) in bits.
- Parameters:
value (unsigned short) – 16 bit analog set point with 0 corresponding to the negative analog voltage reference and 0xFFFF corresponding to the positive analog voltage reference.
Note
Not all modules are provide 16 useful bits; the least significant bits are discarded. E.g. for a 10 bit DAC, 0xFFC0 to 0x0040 is the useful range. Refer to the module’s datasheet to determine analog bit depth and reference voltage.
- Returns:
An error result from the list of defined error codes in brainstem.result.Result
- Return type:
unsigned byte
- setVoltage(microvolts)[source]¶
Set the voltage level of an analog output (DAC) in microvolts.
- Parameters:
microvolts (int) – 32 bit signed integer (in microvolts) based on the board’s ground and reference voltages.
Note
Voltage range is dependent on the specific DAC channel range.
- Returns:
An error result from the list of defined error codes in brainstem.result.Result
- Return type:
unsigned byte