Analog

class brainstem.stem.Analog(module, index)[source]

The AnalogClass is the 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.

Useful constants:
  • CONFIGURATION_INPUT (0)
  • CONFIGURATION_OUTPUT (1)
  • HERTZ_MINIMUM (7,000)
  • HERTZ_MAXIMUM (200,000)
  • BULK_CAPTURE_IDLE (0)
  • BULK_CAPTURE_PENDING (1)
  • BULK_CAPTURE_FINISHED (2)
  • BULK_CAPTURE_ERROR (3)
getBulkCaptureNumberOfSamples()[source]

Get the current number of samples setting for this analog when bulk capturing.

Returns:
Result object, containing NO_ERROR and sample number
or a non zero Error code.
Return type:Result
getBulkCaptureSampleRate()[source]

Get the current sample rate setting for this analog when bulk capturing.

Sample rate is in samples per second (Hertz).

Returns:
Result object, containing NO_ERROR and sample rate
or a non zero Error code.
Return type:Result
getBulkCaptureState()[source]

Get the current bulk capture state for this analog.

Possible states of the bulk capture operation are; idle = 0 pending = 1 finished = 2 error = 3

Returns:
Result object, containing NO_ERROR and bulk capture state
or a non zero Error code.
Return type:Result
getConfiguration()[source]

Get the analog configuration.

If the configuraton is 1 the analog is configured as an output, if the configuration is 0, the analog is set as an input.

Returns:
Result object, containing NO_ERROR and analog configuration
or a non zero Error code.
Return type:Result
getEnable()[source]

Get the enable state an analog output

Get a boolean value corresponding to on/off

Returns:
Result object, containing NO_ERROR and enable state
or a non zero Error code.
Return type:Result
getRange()[source]

Get the range setting of an analog input

Get a value corresponding to a discrete range option.

Returns:
Result object, containing NO_ERROR and analog range
or a non zero Error code.
Return type:Result
getValue()[source]

Get the raw ADC value in bits.

Get a 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 provide 16 useful bits; the least significant bits are discarded. E.g. for a 10 bit ADC, 0xFFC0 to 0x0040 is the useful range. Refer to the module’s datasheet to determine analog bit depth and reference voltage.

Returns:
Result object, containing NO_ERROR and analog value
or a non zero Error code.
Return type:Result
getVoltage()[source]

Get the scaled micro volt value with reference to ground.

Get a 32 bit signed integer (in microVolts) based on the boards ground and reference voltages.

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:
Result object, containing NO_ERROR and microVolts value
or a non zero Error code.
Return type:Result
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.

Returns:Return NO_ERROR on success, or one of the common sets of return error codes on failure. When the bulk capture is complete getBulkCaptureState() will return either finished or error.
Return type:Result.error
setBulkCaptureNumberOfSamples(value)[source]

Set the number of samples to capture for this analog when bulk capturing.

Minimum # of Samples: 0 Maximum # of Samples: (BRAINSTEM_RAM_SLOT_SIZE / 2) = (3FFF / 2) = 1FFF = 8191

Returns:Return NO_ERROR on success, or one of the common sets of return error codes on failure.
Return type:Result.error
setBulkCaptureSampleRate(value)[source]

Set the sample rate for this analog when bulk capturing.

Sample rate is set in samples per second (Hertz).

Minimum Rate: 7,000 Hertz Maximum Rate: 200,000 Hertz

Returns:Return NO_ERROR on success, or one of the common sets of return error codes on failure.
Return type:Result.error
setConfiguration(value)[source]

Set the analog configuration.

Some analogs can be configured as DAC outputs. Please see your module datasheet to determine which analogs can be configured as DAC.

Param:
value (int): Set 1 for output 0 for input. Default configuration is input.
Returns:Return NO_ERROR on success, or one of the common sets of return error codes on failure.
Return type:Result.error
setEnable(enable)[source]

Set the enable state of an analog output.

Set a boolean value corresponding to on/off

Returns:Return NO_ERROR on success, or one of the common sets of return error codes on failure.
Return type:Result.error
setRange(value)[source]

Set the range of an analog input.

Set a value corresponding to a discrete range option.

Returns:Return NO_ERROR on success, or one of the common sets of return error codes on failure.
Return type:Result.error
setValue(value)[source]

Set the value of an analog output (DAC) in bits.

Set a 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:Return NO_ERROR on success, or one of the common sets of return error codes on failure.
Return type:Result.error
setVoltage(value)[source]

Set the voltage level of an analog output (DAC) in microVolts with reference to ground.

Set a 16 bit signed integer as voltage output (in microVolts).

Note

Voltage range is dependent on the specific DAC channel range. See datasheet and setRange for options.

Returns:Return NO_ERROR on success, or one of the common sets of return error codes on failure.
Return type:Result.error