Commit 28244f46 authored by Hao-Ting Wang's avatar Hao-Ting Wang

VPixx initial update

parent b4d9d101
......@@ -71,6 +71,7 @@ def run_experiment(experiment_info, settings):
if settings['env'] == 'eeg':
print('load eeg modules')
sys.path.append('./src/pypixxlib-1.4.0')
# sys.path.append('./src/VPixx_Software_Tools/pypixxlib/pypixxlib-2.0.3917')
from pypixxlib.datapixx import DATAPixx
from src.util import convert_array
......
% DatapixxToolbox
% Version 1.0, Oct 2011
%
% The DatapixxToolbox is a set of MATLAB/Octave functions interfacing to
% the DATAPixx and VIEWPixx hardware toolbox from VPixx Technologies.
% (http://www.vpixx.com/datasheets/ds_datapixx.pdf)
% (http://www.vpixx.com/datasheets/ds_viewpixx.pdf)
% DATAPixx features:
% •Data acquisition and graphics system for the vision sciences
% •Receives DVI input from laptop or PC
% •Transmits dual synchronized VGA outputs with 16-bit video DACs
% •16 channels of 16-bit analog inputs simultaneously sampled at up to
% 200 kHz per channel.
% •4 channels of 16-bit analog outputs simultaneously updated at up to
% 1 MHz per channel.
% •Stereo audio inputs/outputs, sampled at up to 96 kHz.
% •24 TTL inputs with timetagged transitions.
% •24 TTL outputs
% •All digital/analog/audio output transitions can be initiated
% with microsecond-precision to video refresh
% •All digital/analog/audio input acquisition can be correlated
% with microsecond-precision to video refresh
%
% VIEWPixx features:
% •All data acquisition features of DATAPixx
% •Integrated LCD display
% •1920x1200 resolution
% •120Hz refresh rate
% •12-bit resolution on each of the red/green/blue channels
% •Deterministic pixel update timing
% •Scanning backlight for presentation of dynamic stimuli
%
% The DatapixxToolbox implements basic functionality in a single Mex file,
% and includes a set of demo m-files in the DatapixxDemos folder.
%
% For a complete list of available functions type "Datapixx" in the matlab
% command window.
% For an explanation of any particular Datapixx sub-function just add a
% question mark after a command, eg: Datapixx SetDacSchedule?
%
% Peter April
% email: papril@vpixx.com
%
% Copyright (c) 2011, VPixx Technologies
% DatapixxToolbox:DatapixxBasic
%
% This folder contains simple utility files.
%
% DatapixxInfo - Print summary of all Datapixx systems
% HitKeyToContinue - Show a prompt, then wait for a keypress
function DatapixxInfo()
% DatapixxInfo()
%
% Print summary of all Datapixx systems.
% If the Datapixx is closed, it will be opened then closed by this function.
% If the Datapixx is already open, it will be left open by this function.
%
% History:
%
% Oct 1, 2009 paa Written
AssertOpenGL; % We use PTB-3
% Before touching API, report any global errors
libraryError = Datapixx('GetError');
if (libraryError)
fprintf('Datapixx library error code = %d\n', libraryError);
end
datapixxWasOpen = Datapixx('IsReady');
if (datapixxWasOpen)
fprintf('\nDatapixx device is open\n');
else
fprintf('\nDatapixx device is not open\n');
Datapixx('Open');
end
%Take a register snapshot
Datapixx('RegWrRd');
% Print some general system info
fprintf('Datapixx has %dMB of RAM\n', Datapixx('GetRamSize')/2^20);
fprintf('Datapixx firmware revision = %d\n', Datapixx('GetFirmwareRev'));
fprintf('Datapixx time = %g seconds\n', Datapixx('GetTime'));
fprintf('Datapixx marker = %g seconds\n', Datapixx('GetMarker'));
fprintf('Datapixx power supply is providing %4.2fV at %4.2fA\n', Datapixx('GetSupplyVoltage'), Datapixx('GetSupplyCurrent'));
if (Datapixx('Is5VFault'))
fprintf('Datapixx is detecting a short circuit on Analog I/O or VESA 3D +5V pins\n');
end
fprintf('Datapixx internal temperature is %dC = %dF\n', Datapixx('GetTempCelcius'), Datapixx('GetTempFarenheit'));
% Print each of the subsystem status structures
fprintf('\nDatapixx DAC status:\n'); disp(Datapixx('GetDacStatus'));
fprintf('\nDatapixx ADC status:\n'); disp(Datapixx('GetAdcStatus'));
fprintf('\nDatapixx Digital Output status:\n'); disp(Datapixx('GetDoutStatus'));
fprintf('\nDatapixx Digital Input status:\n'); disp(Datapixx('GetDinStatus'));
fprintf('\nDatapixx Audio Output status:\n'); disp(Datapixx('GetAudioStatus'));
fprintf('\nDatapixx Audio Input status:\n'); disp(Datapixx('GetMicrophoneStatus'));
fprintf('\nDatapixx Video status:\n'); disp(Datapixx('GetVideoStatus'));
% Wrapup
if (datapixxWasOpen)
Datapixx('Close');
end
fprintf('\nReport complete\n\n');
function HitKeyToContinue(prompt)
% HitKeyToContinue([prompt='\nPress any key to continue...'])
%
% Print a prompt to the console, then wait for user to press a key
%
% Optional arguments:
%
% prompt = String to print to console before waiting for keypress.
%
% History:
%
% 8/1/09 paa Written
if nargin > 0
printf(prompt);
else
printf('\nPress any key to continue...');
end
fflush(stdout);
KbReleaseWait;
while ~KbCheck
WaitSecs(0.05); % Don't hog CPU
end
printf('\n');
% DatapixxToolbox:DatapixxDemos
%
% This folder contains demo files which can serve as simple starting points
% for your own development.
%
% DatapixxAdcAcquireDemo - Shows how to acquire ADC data synchronized with a video stimulus
% DatapixxAdcBasicDemo - Simple programming of the ADC input voltages
% DatapixxAdcStreamDemo - Demonstrates ADC streaming acquisition
% DatapixxAudioDemo - Shows how to play an audio waveform on the audio CODEC
% DatapixxAudioFeedbackDemo - Demonstrates low-latency feedback from microphone to audio outputs
% DatapixxAudioStreamDemo - Demonstrates audio CODEC output streaming
% DatapixxDacBasicDemo - Simple programming of the DAC output voltages
% DatapixxDacSyncDemo - Shows how to synchronize DAC updates to VSYNC or pixels
% DatapixxDacWaveDemo - Shows how to play an audio waveform on the DAC outputs
% DatapixxDacWaveStreamDemo - Demonstrates audio streaming on the DAC outputs
% DatapixxDinBasicDemo - Timetagged logging of the TTL digital inputs (button box)
% DatapixxDoutBasicDemo - Simple programming of the TTL digital outputs
% DatapixxDoutTriggerDemo - Generates a TTL trigger pulse train, synchronized with video
% DatapixxDualDisplayInfo - Describes implementation of dual synchronized displays using Datapixx
% DatapixxGazeContingentDemo - Shows how to use DATAPixx horizontal overlay for fast eyetracking GC displays
% DatapixxMicrophoneDemo - Shows how to record from microphone, then playback on audio outputs
% DatapixxSimonGame - A microsecond-accurate audio-visual reaction time game using RESPONSEPixx
% DatapixxStereoDemo - A port of PTB StereoDemo to drive shutter goggles from Datapixx
function DatapixxAdcAcquireDemo()
% DatapixxAdcAcquireDemo()
%
% Shows how to acquire ADC data synchronized with a video stimulus.
% For demonstration purposes we use the DAC0/1 outputs to simulate an evoked
% potential, which we then acquire on ADC0/1 using internal loopback between
% DACs and ADCs.
% We'll then plot the simulated evoked potential.
%
% Also see: DatapixxAdcBasicDemo, DatapixxAdcStreamDemo
%
% History:
%
% Oct 1, 2009 paa Written
% Oct 29, 2014 dml Revised
AssertOpenGL; % We use PTB-3
Datapixx('Open');
Datapixx('StopAllSchedules');
Datapixx('RegWrRd'); % Synchronize Datapixx registers to local register cache
% Fill up a DAC buffer with 2 channels of 1000 samples of simulated visual evoked potential data.
% I guess our 2 simulated neurons will just output sin/cos functions.
% We'll generate a single period of the waveforms, and play them repeatedly.
nDacSamples = 1000;
dacData = [sin([0:nDacSamples-1]/nDacSamples*2*pi) ; cos([0:nDacSamples-1]/nDacSamples*2*pi)];
Datapixx('WriteDacBuffer', dacData);
% Play the downloaded DAC waveform buffers continuously at 100 kSPS,
% resulting in 100 Hz sin/cos waves being output onto DAC0/1.
Datapixx('SetDacSchedule', 0, 1e5, 0, [0 1], 0, nDacSamples);
Datapixx('StartDacSchedule');
Datapixx('RegWrRd');
% Configure ADC to acquire 2 channels (ADC0 and ADC1) at 10 kSPS.
% How much data should we acquire? We'll say 1000 samples, which is 100 milliseconds.
% This will give 10 cycles of our 100 Hz sin/cos simulated evoked potentials.
nAdcSamples = 1000;
Datapixx('SetAdcSchedule', 0, 1e4, nAdcSamples, [0 1]);
Datapixx('EnableDacAdcLoopback'); % Replace this with DisableDacAdcLoopback to collect real data
Datapixx('DisableAdcFreeRunning'); % For microsecond-precise sample windows
Datapixx('RegWrRd');
% Our simulated neuron will be responding to a white flash,
% and we shall start acquisition precisely on the vertical sync preceeding the flash.
try
oldVerbosity = Screen('Preference', 'Verbosity', 1); % Don't log the GL stuff
screenNumber = max(Screen('Screens'));
window = Screen('OpenWindow', screenNumber, 0, []);
Screen('Preference', 'Verbosity', oldVerbosity);
HideCursor;
% Clear display to black, and wait about a second
Screen('FillRect',window, [0 0 0]); % Clear the display to black
for frame = 0:60
Screen('Flip', window);
end
% Start the analog acquisition on next vertical sync pulse,
% and show a white flash for one frame.
Datapixx('StartAdcSchedule');
Datapixx('RegWrVideoSync'); % ADC will start at onset of next video VSYNC pulse
Screen('FillRect',window, [255 255 255]); % Fill the display with white
Screen('Flip', window);
Screen('FillRect',window, [0 0 0]); % Return the display to black
Screen('Flip', window);
% Wait for the ADC to finish acquiring its scheduled dataset
while 1
Datapixx('RegWrRd'); % Update registers for GetAdcStatus
status = Datapixx('GetAdcStatus');
if (~status.scheduleRunning)
break;
end
end
% Show final status of ADC scheduler
fprintf('\nStatus information for ADC scheduler:\n');
disp(status);
% Upload our acquired data,
% and plot our evoked potential (10 periods of sin/cos) as a function of time.
[adcData, adcTimetags] = Datapixx('ReadAdcBuffer', nAdcSamples);
plot(adcTimetags, adcData');
% Job done
ShowCursor;
Screen('CloseAll');
Datapixx('StopAllSchedules'); % Stop the DAC waveform
Datapixx('RegWrRd');
Datapixx('Close');
catch
ShowCursor;
Screen('CloseAll');
Datapixx('StopAllSchedules'); % Stop the DAC waveform
Datapixx('RegWrRd');
Datapixx('Close');
psychrethrow(psychlasterror);
end;
fprintf('\n\nDemo completed\n\n');
function DatapixxAdcBasicDemo(internalLoopback)
% DatapixxAdcBasicDemo([internalLoopback=1])
%
% Demonstrates the basic functions of the Datapixx analog to digital converters.
% Prints the input voltage range, and current input voltage, for all channels.
%
% Optional argument:
%
% internalLoopback = 1 if DAC outputs should be internally looped back to ADC inputs
% Otherwise the ADC converts the actual voltages on the db-25 pins
%
% Also see: DatapixxAdcAcquireDemo, DatapixxAdcStreamDemo
%
% History:
%
% Oct 1, 2009 paa Written
% Oct 29, 2014 dml Revised
AssertOpenGL; % We use PTB-3
% Get internal loopback argument
if nargin < 1
internalLoopback = [];
end
if isempty(internalLoopback)
internalLoopback = 1;
end
% Open Datapixx, and stop any schedules which might already be running
Datapixx('Open');
Datapixx('StopAllSchedules');
Datapixx('RegWrRd'); % Synchronize Datapixx registers to local register cache
% DAC outputs can be looped back to ADC inputs inside the DATAPixx.
% There are 4 DAC channels, and 16 ADC channels, plus 2 ADC reference channels,
% so the internal loopback maps DAC outputs to multiple ADC inputs:
% DAC0 => ADC0/2/4/6/8/10/12/14
% DAC1 => ADC1/3/5/7/9/11/13/15
% DAC2 => REF0
% DAC3 => REF1
% Even if we are not doing an internal loopback, we'll still program the DAC outputs.
% This allows us to do an _external_ loopback;
% ie: wire the DAC outputs to the ADC inputs right on the db-25 connector.
% We'll arbitrarily program the 4 DAC channels to 5V, 2.5V, -2.5V, -5V
if (internalLoopback == 1)
Datapixx('EnableDacAdcLoopback'); % We'll read back what's on the DAC outputs
else
Datapixx('DisableDacAdcLoopback'); % We'll read what's really on the input db-25
end
Datapixx('SetDacVoltages', [0:3 ; 5 2.5 -2.5 -5]);
Datapixx('EnableAdcFreeRunning'); % ADC's convert continuously
Datapixx('RegWrRd'); % Write local register cache to hardware
Datapixx('RegWrRd'); % Give time for ADCs to convert, then read back data to local cache
% Show how many ADC channels are in the Datapixx
nChannels = Datapixx('GetAdcNumChannels');
fprintf('\nDatapixx has %d ADC channels\n\n', nChannels);
% Show the input voltage range, and current value, for each ADC channel