Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.



u3 bit port matlab eeg rise

  • Please log in to reply
3 replies to this topic

#1 juliankeil

  • Members
  • 2 posts

Posted 13 March 2014 - 09:41 AM



I have a question that is similar to the one by AdamPsych from Jan. 22nd.

Similar to his setup, I use the U3 to control 8 parallel lines to set flags for my EEG-System.

Unlike him, I use the FIO-lines, i.e. I have 8 wires that go from FIO0 - FIO7 to pin 2-9 of a DB25 connector, with each pin signalling a different flag (e.g. FIO0 goes to pin 2 and signals "S 1"), and a combination of pins signalling the sum of flags (e.g. FIO0 and FIO1 go to pins 2 and 3 and signal "S 3", a combination of "S 1"  from pin 2 and "S 2" from pin 3).


The problem now is, that FIO7 appers to have a faster onset time. When I use all FIO, I not only end up with a flag "S255", but also a Flag "S128" just prior to "S255". Also, FIO0 needs to stay activated longer than the other FIO to be detected by the EEG-System, i.e. appears to have a slower onset time.

When hhoking the U3 to an Oscilloscope, it looks like the FIO7 is faster to reach the output voltage than the other lines.


The code I use looks like this (see attachment for the entire matlab function Attached File  sendLJ.m   2.28KB   1590 downloads)


%%  Add Values to Lines

ljudObj.AddRequest (ljhandle, LabJack.LabJackUD.IO.PUT_DIGITAL_BIT, 0,1, 0, 0); % Set FIO0 to "on"

%% Execute the requests.

%% Wait Duration

%%  Set Lines back to 0
ljudObj.AddRequest (ljhandle, LabJack.LabJackUD.IO.PUT_DIGITAL_BIT, 0, 0, 0, 0); % Set FIO0 to "off"


I also tried to use "PUT_DIGITAL_PORT" instead of BIT, as this seems to have worked for AdamPsych, but I still have the same problem:

ljudObj.AddRequest (ljhandle, LabJack.LabJackUD.IO.PUT_DIGITAL_PORT, 0,1, 8, 0); % Set FIO0 to "on" with an 8bit-Signal.


Is there any way to change this, i.e. have the same timing for all lines? What exactly is the difference between PORT and BIT? And finally, is there a more elegant solution to send signals over multiple lines at the same time?


Thanks a lot!



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 14 March 2014 - 11:30 AM

If you think about the low-level packet sent to the U3, when you do an add-go-get block with 8 bit writes that results in a Feedback packets with 8 BitStateWrite commands:




If each BitStateWrite command takes 1us for the U3 to execute (an educated guess), then there will be 7us between the first and the 8th.


If you use 1 port write that results in a Feedback packet with 1 PortStateWrite command:




PortStateWrite takes about the same time as one BitStateWrite command.


The actual firmware code during that 1us has to step through and update different I/O in different blocks, so there are slight differenences.  Section tells you the actual order, so you can see that FIO4-5 are updated first and then FIO6-7.

#3 juliankeil

  • Members
  • 2 posts

Posted 24 March 2014 - 02:50 AM



thanks a lot for your reply.

If I understand you correctly, using PortStateWrite to set my 8 lines will be faster than using BitStateWrite, as the latter will be executed line by line, whereas the former will work on all lines in one step.


My (very naive) follow-up question then is: How do I use the low-level PortStateWrite command in Matlab. As far as I understand the manual (http://labjack.com/s...-guide/, I have to pass a "State" and a "WriteMask" to the function, written either as d... or something in brackets.

Could you tell me how I can come up with the input to "State" and "WriteMask"?





#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 24 March 2014 - 05:59 PM

Using MATLAB and the UD driver, you only need to use the AddRequest call with the PUT_DIGITAL_PORT IOType. Internally the driver will handle the Feedback low-level command/responses. From the AddRequest's parameters the PortStateWrite's State and WriteMask will be set accordingly.


Our previous response was explaining the driver's internal low-level side of things, where using 8 AddRequests with the PUT_DIGITAL_BIT IOType will internally make the driver create a Feedback command with 8 BitStateWrites to set your 8 lines. Using 1 AddRequest with the PUT_DIGITAL_PORT IOType will make the driver create a Feedback command with 1 PortStateWrite to set your 8 lines.


For PUT_DIGITIAL_PORT/LJ_ioPUT_DIGITAL_PORT documentation and pseudocode example take a look at the UD digital I/O section in the User's Guide:



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users