Discussion:
Synchronize DI & DO of NI 9401
(too old to reply)
angelmcdoggie
2008-06-16 06:40:08 UTC
Permalink
:smileyhappy:Hello Everyone,
 
I have two NI 9401 modules and I want to configure an input and output in each module.  The output will generate a command while the input receives data from the user.  How do I achieve synchronization of the DI and DO modules?
 
Regards and thanks!!!!
:smileywink:
mallorim
2008-06-16 22:10:07 UTC
Permalink
Hi Angel,

There is a shipping example called "Multi-Function-Synch Dig Read write With Counter.vi" That has three parallel tasks.  There is a Counter Output Task, a Digital Input Task, and a Digital Output Task.  The counter generates the "Sample Clock" and you will notice that Dev1/Ctr0/InternalOutput is used as the timing source for the digital I/O tasks.  It sounds like this example would work for your customer with little modification. 

Just change your digital output channels to say: cDAQ1ModXXXXX/port0/line0:7  Where X is the slot of the 9401

And change your digital input channels to say: cDAQ1ModYYYYY/port0/line0:7  Where Y is the slot of the 9401

Then of course change your counter to say:cDAQ1/_ctr0 (you will need to enable internal channels in the "I/O Name Filtering")

The tutorial below also discusses how to do this with LabVIEW.

NI-DAQmx: Correlated Digital I/O with NI CompactDAQ and LabVIEW

http://zone.ni.com/devzone/cda/epd/p/id/5256

 

Regards,

          Mallori M.
angelmcdoggie
2008-06-17 01:40:05 UTC
Permalink
Hello M,
Thanks for sharing this information.  However I am using VC++ and it doesn't come with a shipping example of that title.
Is it possible to use two DIOs only for synchronization?  I don't want to use extra resource of NI 9401 to create a counter task.
 
Best regards,
A
 
mallorim
2008-06-17 21:40:10 UTC
Permalink
Hi A,
The problem is that, unlike analog input, when a digital input task is configured and started, a sample clock is not generated. This means that in order to synchronize the two tasks, in  order to even have hardware timed digital input or output, an external clock has to be provided. The most efficient and easiet way to do this is to use the chassis's counter to generate a sample clock.
The&nbsp;Solution's third paragraph in the&nbsp;<a href="http://digital.ni.com/public.nsf/allkb/79608CDF0C0D28AA862573400042D4F8?OpenDocument" target="_blank">Knowledge Base 4CM6E5T3 </a> <a href="http://digital.ni.com/public.nsf/allkb/79608CDF0C0D28AA862573400042D4F8?OpenDocument" target="_blank">Can I Use Different Sample Clocks for Correlated DI and DO?</a> and the related&nbsp;links User Guide do a great job of explaining the sources for this external clock and its necessity.
Is there a reason you don't want to use one of the chassis's onboard counters?
Regards,
Mallori
angelmcdoggie
2008-06-19 08:10:15 UTC
Permalink
Thanks again M,
&nbsp;
Yes I can use the onboard counter.&nbsp; I just didnt have a clear understanding that's why I didn't thought of that before.&nbsp;
&nbsp;
I'll keep you posted with my progress.&nbsp;
&nbsp;
Regards,
A
angelmcdoggie
2008-06-19 11:10:09 UTC
Permalink
HI again,
&nbsp;
I ran my clock source using "cDAQ1/_ctr0" for synchronization.&nbsp; However, there are items that are unclear to me&nbsp;and with that I have some follow-up questions.
&nbsp;
1.&nbsp; I wrote a timing for my digital input and output tasks.&nbsp; Do I need both timing or only a DI or DO timing will suffice?
2.&nbsp; When I used the "cDAQ1/_ctr0" clock source in this API called,
&nbsp;
angelmcdoggie
2008-06-19 11:10:09 UTC
Permalink
HI again,
&nbsp;
I ran my clock source using "cDAQ1/_ctr0" for synchronization.&nbsp; However, there are items that are unclear to me&nbsp;and with that I have some follow-up questions.
&nbsp;
1.&nbsp; I wrote a timing for my digital input and output tasks.&nbsp; Do I need both timing or only a DI or DO timing will suffice?
2.&nbsp; When I used the "cDAQ1/_ctr0" clock source in this API called,
&nbsp;&nbsp;&nbsp;&nbsp;
angelmcdoggie
2008-06-19 11:10:10 UTC
Permalink
.oooopsss sorry for the repeat post....
&nbsp;
&nbsp;
where clock = "cDAQ1/_ctr0"
&nbsp;
m_DITask-&gt;Timing.ConfigureSampleClock(clock, 1000, DAQmxSampleClockActiveEdgeRising, DAQmxSampleQuantityModeFiniteSamples, samples);

m_DOTask-&gt;Timing.ConfigureSampleClock(clock, 1000, DAQmxSampleClockActiveEdgeRising, DAQmxSampleQuantityModeFiniteSamples, samples);
If I use that API for both timings, I encounter this status error: -8190.&nbsp; See attachment please.&nbsp; However, if I use separate APIs for the parameters, I did not encounter any status error.
m_DITask-&gt;Timing. SampleClockSource = clock;
m_DITask-&gt;Timing. SampleClockActiveEdge = DAQmxSampleClockActiveEdgeRising;
m_DITask-&gt;Timing. SampleClockRate = 1000;
m_DITask-&gt;Timing. SampleQuantityMode = DAQmxSampleQuantityModeFiniteSamples;
m_DITask-&gt;Timing. SamplesPerChannel = samples;
m_DOTask-&gt;Timing. SampleClockSource = clock;
m_DOTask-&gt;Timing. SampleClockActiveEdge = DAQmxSampleClockActiveEdgeRising;
m_DOTask-&gt;Timing. SampleClockRate = 1000;
m_DOTask-&gt;Timing. SampleQuantityMode = DAQmxSampleQuantityModeFiniteSamples;
m_DOTask-&gt;Timing. SamplesPerChannel = samples;
&nbsp;
The 1st and 2nd timing snippets looks the same to me so I feel weird getting a status error in the 1st snippet.&nbsp;
&nbsp;
3.&nbsp; What is the difference between these two signals?&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; "cDAQ1/_ctrX"&nbsp;&nbsp; vs&nbsp; "/cDAQ1/CtrXInternalOutput"
&nbsp;&nbsp;&nbsp; I use them on a trial and error basis but I have no clear idea regarding their usage, pros and cons (if any).
&nbsp;
Thanks for being patient with my inquiries.&nbsp;
Best regards,
A
&nbsp;
&nbsp;
&nbsp;Message Edited by angelmcdoggie on 06-19-2008 07:00 PM


ctr0.JPG:
Loading Image...
mallorim
2008-06-20 23:10:07 UTC
Permalink
Hi A,
1. Yes, you will need to configure timing for both DI and DO since they are separate&nbsp;tasks and each will need a sample clock.
2. and 3. I apologize, the reference I had originally posted was a string that no longer works. "cDAQ1/_ctr0" is&nbsp;no longer a valid input option. You will need to use the "cDAQ1/Ctr0InternalOutput" in order to get the application to run. Thank you for posting the image of your error. This let me spot the problem right off because the text was available, where as just the number was meaningless. You will notice that the error text says that cDAQ1/_ctr0 is not a valid input.
In summary, I'm sorry for not catching the wrong string earlier. Use the cDAQ1/Ctr0InternalOutput option and you should be good to go.
Regards,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mallori M
angelmcdoggie
2008-06-23 08:10:08 UTC
Permalink
Hi there M,
&nbsp;

"cDAQx/_ctr0", "cDAQx/_ctr1" are in the Internal Channels for C Series topic of the NI-DAQmx Help.&nbsp;&nbsp;Is the "cDAQx/_freqout" signal also invalid?
&nbsp;
This time, I shifted to "cDAQ1/Ctr0InternalOutput" as my clock source.&nbsp;&nbsp;I encountered the same error when I used "cDAQ1/_ctr0".&nbsp; That&nbsp;status error was generated when I used the 1st API (based from above thread).&nbsp; However, if I used the 2nd API, no errors were generated.
&nbsp;
Super thanks again,
&nbsp;
&nbsp;


Ctr0IntOutput.JPG:
Loading Image...
mallorim
2008-06-24 19:10:09 UTC
Permalink
Hi A,

&nbsp;

Ok, so I have tested this in LabVIEW a number of different ways. LabVIEW is the only environment I have on my computer, and I can get both cDAQ1/_ctr0 and cDAQ1/crt0InternalOutput to work. So, that means that both names are correct and the DAQmx help is not, in fact, wrong. In order for the _ctr0 to work, you just have to go into the IO name filtering option and enable internal outputs, which was not done on my earlier test system.

&nbsp;

So now I guess the only question is why does configuring the sample clock in one function result in an error that is avoided by using separate lines to configure each sample clock setting? I am not sure as to the cause of this. It might be something similar to the fact that in LabVIEW you have to enable the I/O Name Filtering to make the internal connections visible. Maybe in this text based environment individually configuring each setting allows access to options that are not available when you try and configure it in one. Like I said, I am not sure though. You are able to get the program to run without errors by calling each setting separately though, correct?

&nbsp;

Regards,

Mallori M.
angelmcdoggie
2008-06-25 01:40:08 UTC
Permalink
Thanks for the info.&nbsp; Well, it is true that both clock sources works with using separate functions.&nbsp; With other clock sources, for example the 100KHz timebase did not have any problems similar to that.&nbsp;
Again, I would like to ask, the difference between the "../_ctr0" &amp; "../Ctr0InternalOutput" and when to use them.
&nbsp;
Regards,
mallorim
2008-06-25 23:10:19 UTC
Permalink
Aha!
Ok A,
&nbsp;
I have figured it out. So, when we are creating/configuring the counter task, we have to&nbsp;tell the task what physcial channels, or in this case counters, we want that task to use. Normally this would look like "Dev1/ctr0" or "cDAQ1Mod5/Ctr0". However, if we do not have a module in slot 5 or 6, then we need to be able to access the counter internal to the chassis and the "cDAQ1/_ctr0" string is what we do to point the task to the internal counters, in essence the name of the counter.
&nbsp;
In our case, the counter task is generating or outputing a pulse train that we use as a sample clock.&nbsp; Since there is not a module in slot 5, there is no external connection for the counter output. Instead the signal needs to be rounted internally so that the two DIO tasks can use the pulse train for there sample clock. The way we let the&nbsp;hardware know that we need to internally be connected to the counter's output is by making "cdaq1/Ctr0InternalOutput" the source for our DIO's sample clock.
&nbsp;
I hope this explanation helps,
Mallori M.

Loading...