Control flow of converter for converting USB (universal serial bus) into 25-pin parallel portTechnical Field
The invention belongs to the technical field of measuring instruments, and particularly relates to a control flow of a USB-to-25-needle parallel port converter.
Background
Neuroscience research often requires marking stimulus presentation time with millisecond-scale precision, which is currently achieved by sending TTL signals to a data recording instrument through a 25-needle parallel port, but most desktop computers and almost all notebooks are not provided with parallel ports, which limits the convenience of experiment implementation. Almost all notebooks cannot be installed in an extended mode, and a desktop can be installed in an extended mode through a PCI-E extension card, but a drive version is old and sometimes cannot be installed on a new Linux system, and international mainstream stimulus presentation software PsychToolbox recommends running in a Linux environment. In addition, many instruments accept only 8-bit TTL signals representing integers within 0-255, which may not be sufficient in a small number of cases (e.g., the number of trials exceeds 255 or different experimental parameters need to be encoded with Trigger signals), but may represent integers of 0-65535 if extended to 16 bits, which may carry more information. At present, almost all computers are provided with USB interfaces, and although the time accuracy of the USB interfaces for receiving and transmitting signals is not high in some points of view, stimulus software such as PsychToolbox at present has provided serial port signal receiving and transmitting functions with good stability and high time accuracy. Therefore, if the 16-bit Trigger signal can be sent through the USB interface and is compatible with the existing mainstream experimental instrument, the flexibility of design experiments is improved to a great extent.
Disclosure of Invention
The invention aims to provide a control flow of a converter which can send 16-bit Trigger signals through a USB interface and is compatible with the existing mainstream experimental instrument and is converted into a 25-pin parallel port through a USB.
The invention provides a converter for converting USB into 25-pin parallel ports, which is characterized in that the core of the converter is a Teensy 3.6 singlechip, the singlechip is used as USB serial port equipment to receive a 16-bit Trigger value (uint 16) sent by a computer, the 16-bit Trigger value is split into two 8-bit integers, and then the preset 8-pin levels are sequentially set into 8 bits representing each integer and output to a 25-pin parallel port connector, so that the aim of transmitting the 16-bit integers through the 8 pins is fulfilled. The whole structure of the device is shown in fig. 1, and note that the connection mode from the singlechip to the parallel port is not fixed, and the pin of the parallel port needs to be adjusted according to the specific reading of the experimental device. Specifically, the USB-to-25 pin parallel port converter comprises a Teensy 3.6 single chip microcomputer and a 25 pin parallel port adapter, wherein the 25 pin parallel port adapter is a double-layer circuit board, one end of the 25 pin parallel port adapter can be connected with a 25 pin parallel port connector, and the other end of the 25 pin parallel port adapter is a pin led out from the 25 pin parallel port connector and can be inserted on a bread board.
The invention provides a converter for converting USB into a 25-pin parallel port, which comprises the following specific control flow:
(1) If the integer to be transmitted is between 0 and 255, the singlechip only transmits a signal once, and the duration of each pin set to be high level is 1.1 milliseconds, and then the pin is reset to be low level;
(2) If the integer to be transmitted is between 256-65535, then the single chip sends three signals, the first integer duration is 1.1 ms, then reset to low level 1.1 ms, then the second integer duration is 1.1 ms, then reset to low level 1.1 ms, and finally sends an integer "1" for 1.1 ms, then reset to low level.
Thus, the experimental instrument receiving the SCM signal receives 1 or 3 integers, if 3 integers are received, the last integer '1' indicates that the first two 8-bit integers are needed to be combined into a 16-bit integer in the subsequent data processing, and the situation that when the second integer is 0, most experimental instruments cannot record, and the reduction is problematic can be solved (for example '256' indicates '00000001 00000000', the second 8-bit indicates 0, the experimental instrument cannot record, if a mark is not added at the back, the result is a 16-bit integer, and when the data reduction Trigger value is acquired, the result becomes '00000001', namely the integer '1').
The program is realized through a C language and compiled to a singlechip by Arduino and Teensyduino for running. After compiling, the device can be normally used without manually additionally installing a driver or an Arduino environment on the computers of Windows 7, windows 10 and Ubuntu. The device is not bound with specific stimulus presentation software, and can be used by sending a single integer through a USB serial port.
The invention also supports changing the USB description name of the equipment, and writes a program to automatically search the serial number of the equipment, so that the manual searching of a user is not required.
Because the Teensy singlechip can be directly inserted on the bread board, the invention designs a parallel port adapter (figure 2) which can be inserted on the bread board, and the connection from the singlechip to the parallel port can be flexibly adjusted by plugging wires on the bread board so as to cope with the situation that different instruments read different pins of the parallel port.
Drawings
Fig. 1 is a diagram showing a structure of a converter for converting USB to 25 pin parallel port according to the present invention.
Fig. 2 shows a wiring diagram of a parallel port adapter circuit board which can be inserted on a bread board, wherein (a) is the front surface, and (b) is the back surface. The unit "mil" represents one thousandth of an inch.
Fig. 3 shows the time differences of the changes of the single chip microcomputer (channel 1), the PCI-E parallel port card (channel 2) and the screen brightness (channel 4). The trigger value of the oscilloscope is set at the rising phase of channel 1 and the waveform display duration is 20 seconds. To distinguish between the waveforms of channel 1 and channel 2, the channel 1 vertical position is shifted slightly downward. To more completely reveal the waveform of channel 4, the time zero (i.e., the trigger time) is shifted left by 10 milliseconds.
Fig. 4 shows the time difference between sending Trigger by the singlechip (channel 1) and the PCI-E parallel interface card (channel 2), the Trigger value of the oscilloscope is set in the rising phase of the channel 1, and the duration of waveform display is 20 seconds.
Fig. 5 shows the correlation between 16-bit Trigger signals sent and received by a single chip microcomputer on different computers. Wherein, (a) the processor is AMD Ryzen 7 5800X, the memory is 32GB DDR4 2666MHz, the operating system is a desktop of Windows10 20H2, (b) the processor is a notebook of Intel Core i7-8750H, the memory is 16GB DDR4 2666MHz, the operating system is Windows 10H 2, and (c) the processor is a desktop of Intel Core i7-10700F, the memory is 32GB DDR4 2666MHz, and the operating system is Ubuntu 20.04. Each picture is titled as the sum of absolute values of the difference between the sending and receiving Trigger values.
Fig. 6 is a distribution of time differences between front and rear triggerers counted from recorded data after 65535 16-bit Trigger signals are continuously transmitted at 10 ms intervals on different computers using a single chip microcomputer. Wherein, (a) the processor is AMD Ryzen 7 5800X, the memory is 32GB DDR4 2666MHz, the operating system is a desktop of Windows 10 20H2, (b) the processor is a notebook of Intel Core i7-8750H, the memory is 16GB DDR4 2666MHz, the operating system is Windows 10 20H2, and (c) the processor is a desktop of Intel Core i7-10700F, the memory is 32GB DDR4 2666MHz, and the operating system is Ubuntu 20.04.
In the figure, the reference numeral 1 is Teensy 3.6 singlechip, 2 is the connecting wire, 3 is the parallel port adapter circuit board that can insert on the bread board, and 4 is 25 needle parallel port connectors.
Detailed Description
The performance of the device is verified in two aspects by a specific example, namely (1) accuracy of sending Trigger time and (2) accuracy of transmitting 16-bit Trigger signals, and the accuracy is compared with that of a traditional PCI-E parallel port card.
In the test experiment, the computer processor for displaying stimulation is AMD Ryzen 7 5800X, the memory is 32GB DDR4 2666MHz, the display card is NVIDIA GeForce RTX 2080Super (the driving version is 516.94), the operating system is Windows 1022H2, the stimulation software adopts PsychToolbox.0.18, the MATLAB version is R2021b Update 4, and the display is BenQ XL2540 (resolution 1920x1080, refresh rate 240 Hz). The PCI-E parallel port card has a chip MosChip MCS to 9900, and the function interfaces for driving and calling are realized by inpout and parPulse.mexw64 (downloaded from https:// display-burner.epfl.ch/index.phptile= TachistoscopeSoftware).
In brain science research, it is often necessary to send a Trigger signal when the screen presentation content changes, and it is required that the time difference between Trigger signal transmission and screen content change is stable. Therefore, the time relation between sending Trigger through the singlechip, sending Trigger through the PCI-E parallel port and changing screen brightness is tested by the Utility UPO2104CS oscilloscope. The change in screen brightness was measured by a Thorlabs PDA36A2 silicon photodetector.
1 Of 8 output pins of the singlechip is connected to the first oscilloscope channel, 1 of 2-9 PCI-E parallel port pins is connected to the second oscilloscope channel, the silicon photodetector is tightly attached to the screen, and the output of the silicon photodetector is connected to the fourth oscilloscope channel. A USB to 25 pin parallel port converter test program 1 (see accessory 1) was run on MATLAB, screen brightness was reversed every 20 ms, and Trigger signals with a value of 255 were sent through the single chip and PCI-E parallel port card each time from black to white.
Setting the trigger value of the oscilloscope at the rising phase of the channel one, the duration of the waveform display is 20 seconds (i.e. the waveforms before and after the trigger value is displayed in a superimposed manner within 20 seconds), as shown in fig. 3, it can be seen that the channel one and the channel two rise at almost the same time, the time of maintaining the channel one at the high level is 1.1 ms in accordance with the preset value, and the time of maintaining the channel two at the high level is about 2 ms, which is longer than 0.5 ms (5 e-4 seconds) preset in the program. In addition, channel four was substantially coincident on a line within 20 seconds, indicating that the time difference from sending Trigger to the screen brightness change was substantially constant. Fig. 4 further shows the time difference between sending Trigger by the singlechip and sending Trigger by the PCI-E parallel port, and the time difference can be seen to be stabilized at about 40 microseconds. From the above results, it can be seen that, in terms of time precision of sending Trigger, the singlechip connected to the USB interface is equivalent to the conventional PCI-E parallel interface card, so as to meet the demands of neuroscience research.
In order to further verify the accuracy of the 16-bit Trigger signal transmitted by the singlechip, the 1-65535Trigger values are sequentially transmitted by the singlechip, signals are collected at 2000Hz by Datapixx3 of Vpixx company, and the tested MATLAB code is shown in an accessory 2.
Fig. 5 (a) shows the correlation between the recorded Trigger value and the Trigger value sent by the program (i.e., the last 7 lines of the above code are drawn), and it can be seen that all points fall on the diagonal line. The sum of the absolute values of the difference values of the recorded and transmitted Trigger values is further calculated to obtain an output of 0 (the heading of each graph in fig. 5), that is, the recorded and transmitted Trigger values are identical. We also performed the same test on a notebook (fig. 5 (b)) and a desktop (fig. 5 (c)) with Ubuntu 20.04 operating system installed, and the results were exactly the same as fig. 5 (a).
The above test can also verify the accuracy of the sending Trigger time from another aspect. Fig. 6 shows the distribution of time differences between the front and rear triggers in 65535 triggers, and can be seen that under different hardware and software platforms, most of time differences are just preset 10 milliseconds, and the maximum deviation is not more than 1 millisecond, so that the requirement of neuroscience research on the time precision of the triggers can be met.
In conclusion, the Teensy 3.6 singlechip is written into the converter with the USB to 25-pin parallel port, so that 16-bit Trigger signals can be sent with high time precision, and the computer can normally operate in desktop or notebook, windows or Ubuntu environments, the problem that modern computers do not have 25-pin parallel ports any more is solved, and the possibility of carrying out brain science experiments in a portable mode is improved.
The above-described embodiments are intended to illustrate the present invention, not to limit it, and any modifications and variations made thereto are within the spirit of the invention and the scope of the appended claims.
Accessory 1 USB-to-25 pin parallel port converter MATLAB test code 1
Accessory 2, USB-to-25 pin parallel port converter MATLAB test code 2