Just a short description of what I am trying to achieve: I have a horizontally mounted lever with a potentiometer that is used to control a cursor on a computer screen. I use Matlab 2011a with Psychtoolbox and Data Acquisition Toolbox on a Windows XP machine for this. The DAQ is an Agilent U2300 A. After many different approaches I ended up with this (example code):
ai = analoginput('agilentu2300', 0); % creates the analog object with our card
ch = addchannel(ai,1); % adds the channel for the potentiometer
set(ai,'InputType','SingleEnded'); % generates absolute values
set(ai,'SampleRate',1000); % sampling rate
set(ai,'SamplesPerTrigger',Inf); % continuous recording
start(ai); % starts the analog object
running = 1;
while running == 1
mySample = getData(ai,1) % acquire one sample
drawThisOnTheScreenAtXCoordinate(mySample); % drawsample on screen
experimentEnded = isExperimentOver(); % check wether experiment is over
if experimentEnded == 1 % decide wether to quit the program
running = 0;
end
end
stop(ai) % stops the analog objects
experimentData = getData(ai); % acquires all written data
This is working. I also included a time check so this while loop isn't running as fast as the CPU allows. It is limited to around 200 loops per second and I get the same number of samples. But actually these are not distinct samples. If I check for distinct samples, I get around 15 different samples per second so 15 Hz, which is not sufficient enough for a smooth movement of the cursor on the screen. I also tried using the command getSample which ended up giving me the same results.
I hope that I am doing something wrong and someone knows how to do it differently. I would also be open to recommendations for different approaches with different languages (preferably Python) and maybe even different DAQ hardware.