CNI widgets

From CNI Wiki

Jump to: navigation, search

The firmware code for the devices is publicly available on GitHub. If you'd like to contribute to the code, please send us a note so that we can coordinate efforts.

Serial port scan trigger device

CNI trigger box that contains the serial port trigger device described here, the USB-1208 trigger box, and a 3v lithium cell attached to a big red pushbutton to allow manual triggering.
CNI serial port trigger device circuit diagram. Note that we've also added diodes on the signal lines to protect the microcontroller, but these aren't shown in the diagram. We've also connected a FTDI USB-to_serial cable to pins D2 and D3 (Rx and Tx).

We use a Teensy board programmed using a simple teensyduino sketch. The device generates TTL pulses through a serial port command ("[t]"). The trigger output is electronically ORed with any other trigger devices that might be connected on the same line through a signal diode (1N4148).

This device will also listen for input pulses and send out a serial port character ("p") whenever one is detected. It uses an external interrupt, so it can reliably detect very brief pulses. We use this to detect the GE 3.3v scope trigger pulses (~4 usec pulse duration).

Finally, the trigger device can stream data out through its serial port. This is useful for sending commands to a third machine. E.g., to start or stop recording digital video or to send stimulus tags to the EEG system. To allow the microcontroller to be connected to real RS232 serial ports you would need a level shifter (like the Sipex SP3232E) to convert the 5v signal lines to +/-12v RS232 signals. But we wanted to connect to the third machine via USB, so we just used a FTDI cable, which interfaces directly to the Teensy pins (just connect FTDI Rx to Teensy Tx and FTDI Tx to Teensy Rx).

See (a probably old copy) of the CNI trigger code for serial port. The latest code for this device and all our other widgets is always available on Github.

GE physiological data monitor

CNI PPG pulse detector device.
CNI PPG connection to the back of the STIF card in the GE PGR cabinet.
RS232 level-shifter circuit for physmon.

We also built a device to read serial data from the GE MR750 physiological monitoring port in the PGR cabinet. We need to detect the pulses in real-time for EEG balistocardiogram artifact removal. Unfortunately, the pulses are not available in the GE system, but they do provide the raw PPG data (along with respiration belt and ECG data).

The data come in 12-byte (96-bit) packets delivered at 115200 bps. A packet comes every 5ms, with silence between packets. This produces data bursts of 96bits / 115.2bits/ms = .8333ms with 5 - .8333 = 4.1667ms of silence. (This timing pattern was confirmed with a scope.) So we can detect the start of a data packet by waiting for the silent period before the data arrives. Here we only care about the PPG value. But the code could be easily modified to do something with the other physiological readings. (More details are available in the physmon firmware code.)

To detect a pulse, we compute a running mean and standard deviation and compute a z-score for each new data point. When several consecutive data point z-scores are above threshold, we signal that a pulse was detected. With a Teensy 2++ (which has 8k SRAM), we can maintain a buffer size of 1024, which is 1024 * 0.005 = 5.12 seconds. This seems to be enough to give a very stable pulse detection.

This video shows PhysMon in action, including the way-cool (i.e., I-wasted-too-much-time-on-this) splash screen.

Note that the EEG system also needs to get an MR clock signal. For our GE MR750, we got the 10MHz clock signal from the J9 BNC connector on the front of the exciter/ref clock in the Pen Cabinet.

Circuit tidbits

Optional RGB LED:

    • Common-cathode RGB LED such as this one. (A common-anode RGB LED can be used with a small change to the firmware code.)
    • 2x 100-Ohm resistors
    • 150 Ohm resistor
  • Outputs are protected from reverse voltages with a diode
  • We used a little monochrome OLED display to show what is happening. To drive the 3.3v OLED from the 5v Teensy, we needed a 5v/3.3v logic-level converter. We used the HEF4050BP hex buffer that Adafruit provides with the OLED. It was wired following their tutorial. The Teensy has no 3.3v source, so we also needed a 3.3v linear voltage regulator. UPDATE: Adafruit now offers a 5v-ready OLED display, so you can wire it directly to the Teensy and skip the hex buffer and 3.3v regulator.
  • We need a little circuit to take the scanner data stream (-12v to +12v) and allow it to be safely ready by our 5v microprocessor. We just took the Tx part of this simple RS232 level converter. We used a 2N3904 transistor with emitter to ground, collector to the UART Rx pin on the microcontroller with a 10k pull-up resistor to the 5v line, and the base connected to the Tx line coming from the scanner via a 4.7K resistor, with a 4.7k pull-down to ground.
  • For the firmware, we started with the Adafruit example code for driving the OLED, but their bit-banged SPI turned out to be too slow for our purposes (~40ms per screen refresh), so we modified it to use hardware SPI. This, as well as some other minor optimizations, got our screen refresh time down to ~2ms, which allowed our pulse detector to run at the native data physio rate of 200 Hertz. (See our firmware code for details.)

Unfortunately, I didn't take photos before putting it into the nice brushed aluminum box. It was a very tight squeeze with all the BNC connectors, so I probably won't take it apart. But I do plan to build another (as a back-up). Then I'll try to better document the construction.

Note: the above circuit could also be built around the much more powerful Teensy 3.1. The firmware would need to be updated, but we have yet to do this. So, for now, it would be easiest to stick with the Teensy 2++ design.

CNI Tablet

CNI touch-pad.

We designed and developed an MR-compatible touch-sensitive surface. It uses a KEYTEC 4-wire resistive touch glass connected to a Teensy 2.0 with custom firmware. This devices connects via USB and will show up as a Serial Port on your machine. It streams the absolute position using a simple serial protocol. Here is some sample code to get coordinates in Matlab. We built the case for the tablet out of clear acrylic using the laser cutter at the Stanford PRL Room 36 shop.

Bone-conduction Audio System

See CNI Bone Conduction Audio System.

Summary of connections to the scanner

Start scan trigger connection (PGR Cabinet, back of SRF/TRF board, port J7).
  • trigger in (used to start the scanner from a stimulus computer): PGR Cabinet, SRF/TRF board, J7 (in the back!)
  • trigger out (sends a pulse with every excitation): Pen cabinet exciter, BNC J11 (scope trigger)
  • MR clock (needed by the EGI EEG system): Pen cabinet exciter, BNC J9 (10MHz clock)
  • physio data stream (needed for EEG): PGR cabinet, DB9 physiological monitoring port (this in in the back of the big gray box just above the RF amp. You need to remove the cover on the side of the PGR cabinet to get to it.)
Personal tools