Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Properties of scanclock exported by Matlabs's addClockConnection() on a NI USB 6229 (BNC)

Solved!
Go to solution

With the Matlab DAQ toolbox it is possible to export a scanclock via addClockConnection() (See http://www.mathworks.de/de/help/daq/ref/daq.session.addclockconnection.html for a basic  code example).

 

However, I could not find any information on the properties of the exported signal on the NI USB 6229 (BNC) , for instance frequency, amplitude, duty cycle etc., neither in the documentation, nor in the web or in this forum.

 

I would be very happy if someone point me to some documentation concerning the properties of scanclock.

0 Kudos
Message 1 of 8
(3,940 Views)

Hi,

 

I may be able to help you, but I need to know more about what you're trying to do.

Can you please provide more details about your use case and what you are trying to do with the clock connection?

 

Regards,

   Wael Hemdan

   MathWorks

0 Kudos
Message 2 of 8
(3,899 Views)

Many thanks for your reply.

 

I intended to use the NI USB 6229 to export a clock to synchronize the device with an EEG amplifyer. The aquisition software of the amplifyer offers the possibility to import a clock, but asks to specify the frequency of the clock signal and prefers clock signals with a duty cycle of 0.5. My problem is (or better, it was; see below why) that the properties of a clock exported via addClockConnection() are not documented (at least I did not find any information).

 

Meanwhile I solved this problem by exporting a counter channel using addCounterOutputChannel(). Fortunately, the counter output allows for specifiying frequency and duty cycle of the counter output.

 

Nevertheless, I would be grateful if you could point me to resources commenting on the properties of the clock.exported via addClockConnection().

 

Best,

user2456

 

 

 

 

 

0 Kudos
Message 3 of 8
(3,886 Views)

Hi user2456,

 

I recommend you to post your question on the MathWorks forum (http://www.mathworks.de/support/),

thus it is a Toolbox supported by MathWorks that uses the National Instruments DAQmx driver.

 

This way you might get more information on this topic.

 

Best Regards,

Martin L.

National Instruments

 

0 Kudos
Message 4 of 8
(3,875 Views)
Solution
Accepted by topic author user2458

Hi,

 

All channels in a MATLAB session run at the same rate. So if you create a session 's', s.Rate would be the rate of your acquisition or generation. the 's.addClockConnection' method allows you to import or export a scan clock for synchronization purposes.The syntax below allows you to export the session clock from 'PFI0' to an external device. You can probably find documentation on the NI website for properties of the onboard clock signal, but it appears to be a 5 volt pulse running at the session rate - which is typical to synchronize devices together.

 

s.addClockConnection('dev2\pfi0', 'external', 'ScanClock');

 

If you need 50% duty cycle, you would create your own clock using a counter output channel as you did above. If you connect that clock to the EEG, it can use it; and if you need your NI device to run off the counter output clock (instead of the onboard clock), you would also import the counter output signal back into the session and make sure to set the session rate to match the counter output frequency. Assuming s.Channels(2) is your counter output channel, the code below imports the scan clock on the same terminal as the counter output channel, so no extra wiring is needed.

 

s.Rate = s.Channels(2).Frequency;

s.addClockConnection('external', ['dev2\' s.Channels(2).Terminal], 'ScanClock');

 

This allows both the NI device and your EEG to run on the same clock. You can also have your session export a start trigger using simillar syntax to the above to ensure both devices start on the same clock edge.

 

s.addTriggerConnection('dev2\pfi0', 'external', 'StartTrigger');

 

I hope this helps,

 

Regards,

   whemdan

   MathWorks

0 Kudos
Message 5 of 8
(3,865 Views)

Hi whemdan,

many thanks for your reply.

 


@whemdan wrote:

Hi,

 

All channels in a MATLAB session run at the same rate. So if you create a session 's', s.Rate would be the rate of your acquisition or generation. the 's.addClockConnection' method allows you to import or export a scan clock for synchronization purposes.The syntax below allows you to export the session clock from 'PFI0' to an external device. You can probably find documentation on the NI website for properties of the onboard clock signal, but it appears to be a 5 volt pulse running at the session rate - which is typical to synchronize devices together.

 

s.addClockConnection('dev2\pfi0', 'external', 'ScanClock');


Thank you, with these directions I was able to "find" the clock signal using an oscilloscope. It's frequency indeed matches the session rate, but the pulses are so short that they weren't recognizable in the oscilloscope unless you set the session rate quite low and at the same time zoom in the time axis of the oscilloscope.

 


 

If you need 50% duty cycle, you would create your own clock using a counter output channel as you did above. If you connect that clock to the EEG, it can use it; and if you need your NI device to run off the counter output clock (instead of the onboard clock), you would also import the counter output signal back into the session and make sure to set the session rate to match the counter output frequency. Assuming s.Channels(2) is your counter output channel, the code below imports the scan clock on the same terminal as the counter output channel, so no extra wiring is needed.

 

s.Rate = s.Channels(2).Frequency;

s.addClockConnection('external', ['dev2\' s.Channels(2).Terminal], 'ScanClock');

 

This allows both the NI device and your EEG to run on the same clock. You can also have your session export a start trigger using simillar syntax to the above to ensure both devices start on the same clock edge.

 

s.addTriggerConnection('dev2\pfi0', 'external', 'StartTrigger');

 


So far it did not occur to me that I need to feed the counter signal back into the NI device. I thought that, although session rate and counter frequency might differ, they still are in synchrony since they are both generated by the same onboard clock. To illustrate this thought by an abstract example, imagine the following:

  • I create a session with a rate of 1000 Hz and put out a 10 Hz square wave via an analog channel
  • in the same session, I export a counter channel with 10000 Hz and 0.5 duty cycle

After one second, the analog port has put out 10 square pulses and the counter channel 10000, that is, a ratio of 1:1000. Since both signals are created based on the same onboard clock, I would expect this ratio to be constant until eternity, that is, they are synchronized. This would not necessarily be the case if both signals are created based on different clocks (i.e., by two different devices).

 

If the logic of this example holds, there would be no need to feed the counter signal back into the NI device, right?

 

Best

user2458

 

 

0 Kudos
Message 6 of 8
(3,857 Views)

Hi,

 

The session does not know what you are usig the counter output channel for... so when you create a counter output channel with a certain frequency and duty cycle, the analog subsystems are still running off of the onboard clock. In our example, we happen to be using the counter output as a clock, but the session does not know that. We import an external clock (which happens to be the same one we created using the counter output), and tell the session the rate of this external clock (since it has no way of knowing that) and this way the analog subsystem and the EEG are both using the same clock that was generated using the counter output.

 

Regards,

   whemdan

   MathWorks

Message 7 of 8
(3,837 Views)

Many thanks for your explanations.

0 Kudos
Message 8 of 8
(3,835 Views)