Welcome! Log In Create A New Profile

Advanced

How should I set ttl() and stm() begin at same time and last same period

Posted by AmberX 
How should I set ttl() and stm() begin at same time and last same period
October 28, 2019 02:08AM
Hi,
I have two stimulations, one is a pulse generated by ttl(1), the other is a 2s 40hz wave generated by stm(1,laser), they need to begin at same time and last 2s period, I tried to put them together in one toggleobject function, but it failed to realize the function, the pulse didn't last two seconds even if I put it together with the 2s wave, could anyone tell me how I should fix it? Thanks in advance.

the code I used:
toggleobject([PULSE laser]);
toggleobject([PULSE laser]);
Re: How should I set ttl() and stm() begin at same time and last same period
October 28, 2019 02:14PM
toggleobject does not know how long the stimulations will last. If you call two toggleobjects in a row, you are just turning them off as soon as they are on.

Try inserting "idle(2000);" or "pause(2);" between them and see if it works for you. The latter is more precise in timing but it won't update the screens for 2 s. If they are not precise enough, we can make an adapter or manually control the DAQ board.
Re: How should I set ttl() and stm() begin at same time and last same period
October 30, 2019 11:35PM
I should mention that there is an option to send out the TTL as a second analog output, IF you have two analog output channels AND program with the scene framework. I thought we might need a new adapter but the Stimulator adapter is already doing it. In that way, two pulses can start and stop exactly at the same time.
Re: How should I set ttl() and stm() begin at same time and last same period
November 11, 2019 08:11AM
it works after I took your suggestion, adding an idle(2000). But I met another issue.


%%% part of the code
memory_time = 800;

toggleobject(laser_800ms); % laser_800ms is a 800ms pulse-width single pulse, stm(1, laser_800ms)
ontarget = eyejoytrack('holdfix', fixation_point, fix_radius, memory_time);
if ~ontarget
trialerror(3); % broke fixation
toggleobject([fixation_point laser_800ms,'status','off');
return
end
%%%

when the monkey broke fixation, the stimulation port, laser_800ms, was at high voltage, and this high voltage had been lasting until the next pulse. I thought it might go back to the low voltage automatedly, to reset the port. To deal with it, I tried to send a reset signal, an all 0s signal, to the same port after the trialerror was marked immediately. an error was popped out as the attached figure showed.

what's the correct way to reset the stimulation port?
Attachments:
open | download - Capture.PNG (37.9 KB)
Re: How should I set ttl() and stm() begin at same time and last same period
November 12, 2019 10:56PM
One easy fix is to send out the waveform to the end (assuming that the waveform has a trailing 0) whether the fixation is broken or not. Do you need to stop it in the middle? In some applications, the last value should stay there, so I need to think about how to accommodate this.
Re: How should I set ttl() and stm() begin at same time and last same period
November 13, 2019 03:00AM
Yes, stim(1, laser) controlled a laser generator, I'd like to realize stopping stimulation pulse immediately when the monkey breaks fixation. I did send an all 0s signal to the port, but it popped an error as I showed in the attached capture. Do you know how to fix the error? it seems caused by two stimulations sent to the same port.


laser = 1; % stm(1, laser)
reset_all0s = 2; % stm(1, all0s) these two stimulations share one port, reset signal is to turn down the lasting high voltage after the breaking.

toggleobject(laser)
ontarget = eyejoytrack('holdfix', fixation_point, fix_radius, memory_time);

if ~ontarget
trialerror(3); % broke fixation
toggleobject([fixation_point laser, 'status','off');
toggleobject(reset_all0s) % when I was adding this code, the error popped
return
end
%%%
Attachments:
open | download - Capture.PNG (37.9 KB)
Re: How should I set ttl() and stm() begin at same time and last same period
November 13, 2019 03:46AM
You can do this as a temporary solution. putsample has to be called after STM is turned off. If you are sending out a 5V flat pulse, I would use a TTL. It is fast and easier.

toggleobject(1);   % TaskObject#1: crc(0.2,[1 1 1],1,0,0)
ontarget = eyejoytrack('acquirefix',1,3,10000);

if ~ontarget
    trialerror(4);  % no fixation
    return
end

toggleobject(2);   % TaskObject#2: stm(1,laser_800ms)
ontarget = eyejoytrack('holdfix',1,3,800);
if ~ontarget
    toggleobject(2);
    putsample(DAQ.Stimulation{1},0);  % Stimulation 1
    trialerror(3);  % break fixation
    return
end

trialerror(0);
Re: How should I set ttl() and stm() begin at same time and last same period
November 14, 2019 03:22AM
When I called putsample after STM was turned off, the task stopped because of a popped error " Error using analogoutput/putsample" (the attached capture). I think I might misunderstand your meaning of "stop in the middle", I'd like to stop the laser STM when breaking fixation and jump to the next trial normally, not to stop the whole task. Do you know how to fix it? Thanks for your patience.
Attachments:
open | download - Capture.PNG (12.9 KB)
Re: How should I set ttl() and stm() begin at same time and last same period
November 14, 2019 03:26PM
I probably deleted it when I edited the previous comment. Analogoutput channels on the same device cannot be controlled individually, so there is no point of assigning two STM objects, unless you want to send out two waveforms simultaneously. Delete the other Stimulation channels, except Stimulation 1, or run putsample like the following.

putsample(DAQ.Stimulation{1},zeros(1,length(DAQ.Stimulation{1}.Channel));.

Or just wait for the next update, which I will upload soon.
Re: How should I set ttl() and stm() begin at same time and last same period
November 18, 2019 06:05PM
Please try the new version of NIMH ML that I just uploaded. There was initially a reason why STM was programmed in that way, but I think I sorted out and handled all possible cases this time.
Re: How should I set ttl() and stm() begin at same time and last same period
November 20, 2019 01:37AM
Thanks for your reminder! By the way, putsample function has fixed my issue successfully!

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.