Zapit-Optostim / zapit

General purpose optostimulation system
GNU Lesser General Public License v2.1
6 stars 1 forks source link

Add delayed stop with a timer to stopOptoStim #98

Closed raacampbell closed 1 year ago

raacampbell commented 1 year ago

At the end of stopOptoStim we have:


    % TODO -- all the following loop achieves is a delay. We can do away with it simply
    % by adding a 200 ms pause between writing to the buffer and closing the task. So if we
    % can do this with a delayed stop with at timer that is better.
    % Zero everything. We might have to send the buffer more than once to get the laser to zero
    % depending on the number of passes through the above loop. This was determined by
    % trial an error on an NI USB-6363. A PCIe might be different (TODO).
    minBuffers = 6;
    writesToPerform = (1+minBuffers-numBuffers);
    if writesToPerform<3
        writesToPerform = 3;
    end
    t(:) = 0;
    for ii = 1:writesToPerform
        obj.DAQ.writeAnalogData(t);
    end

    obj.DAQ.stop

So let's resolve this by creating a one shot timer that waits 250 ms or so then issues a stop command to the DAQ. We can use this earlier in this file too, where we stop hard with no ramp down.

raacampbell commented 1 year ago

Test it! 833fb6635ea9e6891b4ad45fe0ddae8bd2091554 Confirm whether there is a relationship between the length of the delay that is needed and the duration of the offset ramp. There could be ...

OR!

I don't think we need the stop at all. It could well work just fine without. Then problem is solved with no timer. But then need to check what happens when we switch from this AO mode to something else.

Finally, update the minimal code sample with whatever we find here.

raacampbell commented 1 year ago

The timer works! 099d79a220b1df4c7f2eebbcf1ada0414c064275 The minimal stim presenter does not use the timer now (046e6616de547dcf60d1bf22b9854242e2e865e1, fd18eab76a8431b4278e7a4ea6877b61b1f66e50) it just has no Stop commands. This also works but for the main Zapit classes we leave with the stop commands in place.