BpodSystem.FlexIOConfig

Description

FlexIOConfig is a struct used to configure Flex I/O channels. Flex I/O channels can each be configured as:

  • Digital Input

  • Digital Output

  • Analog Input (12-bit, 0-5V)

  • Analog Output (12-bit, 0-5V)

  • High Impedance (channel disabled)

Other configuration settings in FlexIOConfig concern channel(s) configured as analog input:

  • Sampling Rate

  • ADC measurements per sample

  • Threshold configuration

FlexIOconfig is attached to a callback function. Any changes to the struct are automatically sent to the state machine.

Properties

  • channelTypes: An array containing the Flex I/O configuration. The array must specify a configuration for each Flex I/O channel. Configuration values are:

      • 0: Digital Input

      • 1: Digital Output

      • 2: Analog Input

      • 3: Analog Output

      • 4: Disabled (High Impedance)

    • On calling FlexIOConfig.channelTypes(), the composition of valid state machine events and output actions will be updated to match the requested channel types.

    • Note: a GUI is provided to set the Flex I/O configuration manually, from the settings menu on the Bpod Console. If set from the GUI, the configuration will be loaded automatically to the device each time Bpod is started. FlexIOconfig.channelTypes is useful for reconfiguring the Flex I/O channels when launching an experimental protocol.

  • analogSamplingRate: The rate of sample acquisition for all Flex I/O channels configured as analog input

    • Units: Hz

    • Range: [1, 1000]

  • nReadsPerSample: The number of ADC reads to average for each sample acquired. ADC reads are measured consecutively, and each read takes ~2 microseconds. Increasing reads per sample reduces the effect of high-frequency noise.

    • Range: [1, 4]

  • threshold1, threshold2: A 1x4 array specifying an event threshold for each channel. Each Flex I/O channel has two configurable thresholds, contained in threshold1 and threshold2 respectively.

    • Units: Volts

  • polarity1, polarity2: A 1x4 array specifying the polarity of each channel's threshold.

    • 0: An event is generated when voltage is above the threshold

    • 1: An event is generated when voltage is below the threshold

  • thresholdMode: A 1x4 array specifying the mode of each threshold. All thresholds are disabled when reached.

    • 0: Thresholds must be manually re-enabled using the 'AnalogThreshEnable' output action.

    • 1: For a single Flex I/O channel, crossing threshold 1 enables threshold 2. Crossing threshold 2 enables threshold 1.

Examples

% 1. This code configures channel 1 as an analog input and channel 2 as an analog output.

% All other channels are configured as high impedance.

BpodSystem.FlexIOConfig.channelTypes = [2 3 4 4];


% 2. This code configures channel 1's two thresholds to 4V (threshold 1) and 2V (threshold 2).

% Threshold 2 is set to detect voltage below 2V. Thresholds are set to enable each other when

% crossed. This setup can be used to generate an event on the rising and falling phases of a cyclic % signal.

Chan = 1;

BpodSystem.FlexIOConfig.channelTypes(Chan) = 2; % Set Flex I/O Ch1 as analog input

BpodSystem.FlexIOConfig.threshold1(Chan) = 4;

BpodSystem.FlexIOConfig.threshold2(Chan) = 2;

BpodSystem.FlexIOConfig.polarity1(Chan) = 0;

BpodSystem.FlexIOConfig.polarity2(Chan) = 1;

BpodSystem.FlexIOConfig.thresholdMode(Chan) = 1;


% 3. This code configures the sampling rate and number of ADC reads per sample for all analog inputs.

BpodSystem.FlexIOConfig.analogSamplingRate = 100; % Set Flex I/O analog input sampling rate to 100Hz

BpodSystem.FlexIOConfig.nReadsPerSample = 2; % Set Flex I/O analog input to 2 averaged ADC reads per sample