I've been testing the T7 Stream-Out to FIO_STATE as a target, via Matlab and a USB connection. The purpose is to trigger a Digitimer DS8R device, which requires a positive edge TTL at 5V (connected to FIO0/GND), at irregular intervals but with precise timing. For testing purposes I'm starting with some low-frequency outputs. It works well for the following example, where I'm outputting alternating 5V and 0V outputs using eWriteNameArray at a scanRate of 1Hz:
[5 0 5 0 5 0 5 0 5 0]
In the above example, the DS8R device correctly triggers 5 times, once every 2s.
However, if I attempt the following output with a scanRate of 2Hz, which should have the same result as example 1 in terms of triggering the DS8R, the end device is only triggered on the first two positive edges:
[5 5 0 0 5 5 0 0 5 5 0 0 5 5 0 0 5 5 0 0]
I get the same problem with this waveform:
[5 0 0 0 5 0 0 0 5 0 0 0 5 0 0 0 5 0 0 0]
I was wondering if I had misunderstood anything about how Stream-Out should work with digital outputs (most of the examples I could find are for analogue outputs)?
Some additional questions I have are:
1. After testing for a while, the Stream-Out stopped working altogether, but then recovered with the following command: eWriteName(handle, 'FIO0', 0). Is there a reason for this, and would it be good practice to set the output channel to 0 before every stream-out?
2. As I read, for Stream-Out without any reading requirements, the scansPerRead parameter is ignored. However, it errors if I set this to zero. I have kept it as scanRate/2 as advised in the documentation - I presume this is ok if it is ignored?
3. Since I've set 'FIO_STATE' as target, will this set all FIO channels to 5V with the above examples? Is it better to specify FIO0 if I am only using this channel, and if so how do I do this?
For reference, a version of my Matlab code is below:
% seems to need zeroing
name = 'FIO0';
value = 0;
LabJack.LJM.eWriteName(h.ljHandle, name, value);
% Setup stream-out
numAddressesOut = 1;
aNamesOut = NET.createArray('System.String', numAddressesOut);
aNamesOut(1) = 'FIO_STATE';
aAddressesOut = NET.createArray('System.Int32', numAddressesOut);
aTypesOut = NET.createArray('System.Int32', numAddressesOut);
LabJack.LJM.NamesToAddresses(numAddressesOut, aNamesOut, ...
aAddressesOut, aTypesOut);
waveform = [5 0 5 0 5 0 5 0 5 0];
scanRate = 1;
% Allocate memory for the stream-out buffer
buffer_size = max(32,pow2(floor(log2(length(waveform))))*2);
LabJack.LJM.eWriteName(h.ljHandle, 'STREAM_OUT0_ENABLE', 0);
LabJack.LJM.eWriteName(h.ljHandle, 'STREAM_OUT0_TARGET', aAddressesOut(1));
LabJack.LJM.eWriteName(h.ljHandle, 'STREAM_OUT0_BUFFER_SIZE', buffer_size);
LabJack.LJM.eWriteName(h.ljHandle, 'STREAM_OUT0_ENABLE', 1);
LabJack.LJM.eWriteName(h.ljHandle, 'STREAM_OUT0_LOOP_NUM_VALUES', 0);
LabJack.LJM.eWriteName(h.ljHandle, 'STREAM_OUT0_SET_LOOP', 1);
% Load the waveform data points
LabJack.LJM.eWriteNameArray(h.ljHandle, 'STREAM_OUT0_BUFFER_U16', length(waveform), waveform, 0);
% Setup stream-out
numAddressesOut = 1;
aNamesOut = NET.createArray('System.String', numAddressesOut);
aNamesOut(1) = 'STREAM_OUT0';
aAddressesOut = NET.createArray('System.Int32', numAddressesOut);
aTypesOut = NET.createArray('System.Int32', numAddressesOut);
LabJack.LJM.NamesToAddresses(numAddressesOut, aNamesOut, ...
aAddressesOut, aTypesOut);
% Configure and start stream
aScanList = aAddressesOut(1);
scansPerRead = scanRate/2;
numAddresses = length(aScanList);
[~, scanRate] = LabJack.LJM.eStreamStart(h.ljHandle, scansPerRead, ...
numAddresses, aScanList, scanRate);
pause(length(h.mwav)/scanRate)
% stop stream
LabJack.LJM.eStreamStop(h.ljHandle);
Hello,
One thing to note about our DIO is that the high state is 3.3V, not 5V. I believe TTL recognizes 2.4V-5V as logic high, so this might not be the issue, but it is worth noting anyway. Beyond that, I am not sure where your problem is. I will try to reproduce the error tomorrow morning and see if I can figure something further out.
For your additional questions:
1. Setting FIO0 to 0 would change it to a output if it were an input. It would not hurt to write 0 to FIO0 before the stream for superstitious reasons, but I think it should be fine if you leave that code out. I am more concerned with the stream out not working and stopping. Were you seeing any error codes when this happened?
2. You can ignore scansPerRead if you are only doing stream-out, that is primarily for stream in.
3. Setting FIO_STATE to 5 (0000 0101) will set FIO0 and FIO2 high (3.3V). If you just want to set FIO0 high you would then set FIO_STATE to 1. Please checkout the FIO_STATE description here:
https://labjack.com/support/datasheets/t-series/digital-io#ports
Many thanks for your feedback.
I managed to pinpoint the problem to a coding error - I had a line to calculate the buffer size which underestimated the size needed - the "floor" function in the below should be a "ceil" function:
buffer_size = max(32,pow2(floor(log2(length(waveform))))*2);
However, I worked this out after switching to using analogue out instead of digital out. It has the same effect for my purposes so I'm proceding with DAC0 control instead of FIO_STATE, but I never got to the bottom of why I couldn't get it to work with digital out. Probably an issue with my code somewhere.
Cheers
Chris