Home Examples Digital Input/Output
Peripherals

Digital Input/Output

This example shows how to set up digital inputs and outputs. In this example, a digital input is used to provide additional control over when a task transitions from one state to the next, and a digital output is used to indicate when a subject’s hand is in or out of a target. The digital input could be from a push-button that the experimenter has and the digital output could go to a speaker to provide audio output.

10.19.1      Simulink Code for Digital I/O Example

The Simulink code for this example is based on the code in 6.7 Centre-out Reaching Task. The differences are the addition a Digital Input block (PCI-6229 DI) and a Digital Output block (PCI-6229 DO), as well as the associated inputs/outputs in Trial_Control.

Figure 10.29: Simulink Code for Digital I/O Example

10.19.2      Stateflow Chart for Digital Input and Output Example

The Stateflow Chart shown below is based upon 10.18.2 Stateflow Chart for Parallel State Execution (Independent State Machines) Example, with a few modifications:

  • A new transition from MoveTarget to EndOfTrial was added, based on the condition [Digital_Input==1]. Thus if the push button connected to digital input 1 is pressed when the task is in the MoveTarget state, then [Digital_Input==1] will become true and the transition will occur.
  • HandInTarget_Output is a newly defined output whose value depends on the HandInTarget If [HandInTarget==1], then the Task Program will set HandInTarget_Output=1, which in this example is connected to a digital output that goes to a speaker, thus providing audio feedback on when a subject’s hand is in the desired target.

Figure 10.30: Stateflow Chart for Digital I/O Example

10.19.3     Connecting to National Instruments I/O When Using a PCI-6229

Most Kinarm Labs come with a National Instruments PCI-6229 I/O card and a BNC 2090A to interface with it. The table below shows how the labels on the BNC 2090A relate to the I/O channels specified in Simulink for the PCI-6229.

Table 10.3: BNC 2090A to PCI-6229 interface

 

Analog input

Analog Output  

Digital I/O

PFI Digital I/O
Simulink Channel Name Ch 1-16 Ch 17-32 Ch 1-2 Ch 3,4 Ch 1-8 Ch 9-16 Ch 17 Ch 18-32 PFI 0 PFI 1-15
BNC 2090A

Labels

Upper AI

0-15

AO 0-1 PO 0-7 PFI 1-15
Lower (optional) AI

0-15

AO 0-1 PO 0-7 PFI 1-15

Related Tasks

Coding Tips
Persistent Variables
Persistent variables are ones that hold their value between calls to the embedded MATLAB code they are defined in.
Coding Tips
Custom Control of the Trial Protocol Order
Normally, Dexterit-E manages and controls the order in which Trial Protocols (TPs) execute based on what is defined in the block table of the Task Protocol (see the Dexterit-E User Guide for more details).