Hi,
I would like to trigger a piezo stimulator connected to a Nidaq system. Ideally I would like to trigger it from sma=AddState, so I tried creating a new OutputActions. It actually triggers the piezo but is not sync with the rest of the sma trial, it is just delivered at the beginning of every trial.
In the AddState function I only modified metaActions to have an extra one, which contains this code:
case 7
if value > 0
d=daq('ni');
d.addoutput('Dev4','ao0','Voltage');
outputsamplerate = 1000;
d.Rate = outputsamplerate;
dobject=d;
trial_number=1;
frequency=20;
ampli=4;
lengthofstim = 0.05;% in seconds
lengthofisi = 1.95; % in seconds
delay = linspace(0,0,outputsamplerate*(lengthofisi));
t1 = linspace(0,1,outputsamplerate*(lengthofstim));
noofstim = lengthofstim*frequency;
datastim = square(2*(pi-(pi/100))*noofstim*t1);
datastim=(datastim*ampli(1));
datapiezo = cat(2,datastim,delay);
write(dobject,datapiezo');
end
I guess is a problem of timing but no idea how to address it.
Hope you can help
Carlos