Analog Entity¶
API Documentation: [cpp] [python] [.NET] [LabVIEW]
BrainStem modules may have the ability to read an analog voltage (ADC) and convert this into a discrete digitized value or output a voltage value based on a desired discrete value (DAC). Analog voltage capabilities will be dictated by the module hardware being used. Module specifics that include the quantity of analog entities and details for their capacities will be described in that module’s datasheet.
Value (Get/Set)¶
analog [ index ] . getValue <= (unsigned short) value
analog [ index ] . setValue => (unsigned short) value
Getting Values
A BrainStem’s A2D reading will always return a 16 bit value. If the module hardware does not have full 16 bit wide analog to digital conversion capabilities, the measurement will get propagated up to 16 bits wide.
For example, if a 12-bit A2D engine exists in the target module’s hardware, the reading will get promoted in the firmware layer by shifting up 4 bits to fill out the 16 bit value (0x0FFF =: 0x0FFF << 4 = 0xFFF0) in the module’s firmware. This approach allows more portable API code to be generated independent of the target hardware.
Setting Values
The reading resolution will return a 16 bit value. If the module hardware does not have full 16 bit wide analog to digital conversion capabilities, the value sent by the API will get propagated up to 16 bits wide.
For example, if a 10-bit DAC engine exists in the target module’s hardware, the reading will get down shifted 5 bits to derive the 10 bit value (0x8000 =: 0x8000 >> 5 = 0x0400) in the module’s firmware. This approach allows more portable API code to be generated independent of the target hardware.
Configuration (Get/Set)¶
analog [ index ] . getConfiguration <= (unsigned char) configuration
analog [ index ] . setConfiguration => (unsigned char) configuration
Getting Configuration
Some analog entities may be single purpose functionality or can be configured for multiple different behaviors depending on the hardware. Configuration information includes whether the entities is an input only, output only, or can be configured as either and input or output.
Setting Configuration
Analog entities that are capable of different operating configurations can be explicitly set to operate in a desired configuration mode when possible. Defaults for most analog entities are typically as inputs, but will vary by module hardware.
Code Examples¶
C++¶
// All commands return aErr values when errors are encountered and aErrNone on
// success.
stem.analog[0].getValue(value); // gets the value of A2D channel 0 into variable value
stem.analog[3].setValue(1234); // sets the DAC on channel 3 to a value of 1234
stem.analog[0].setConfiguration(analogConfigurationInput);
Reflex¶
stem.analog[0].getValue(value); // gets the value of A2D channel 0 into variable value
stem.analog[3].setValue(1234); // sets the DAC on channel 3 to a value of 1234
Python¶
result = stem.analog[2].getValue() # gets the value of A2D channel 2 into variable result.
print result.value
err = stem.analog[3].setValue(1234) # sets the DAC on channel 3 to a value of 1234
print err