Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Mixing analog and digital channels

Hi

M Series card Programming with VS.NET

I have a system with 11 analog channels and 1 (or more later) digital input channels. I want to scan the analog channels and the digital channel continously at 1000 Hz

I have set up 2 tasks, analogTask and digitalTask, and configured the analog channels and digital channel in those tasks.

I have setup an analog reader and digital reader and 2 callbacks one for analog and the other for digital. After verifying the tasks I call the begin read functions:

analogInReader.BeginReadMultiSample(bufferScans, analogCallback, null);
digitalInReader.BeginReadMultiSamplePortUInt32(bufferScans,digitalCallback, null);

Thetiming for both tasks has been configured with SampleQuantityMode.C
ontinuousSamples

The analog part works as expected but I am having trouble with the digital part. When I run the application I get a puzzling error message:

"External sample clock source must be specified for this application".

If I comment out the line
digitalTask.Timing.ConfigureSampleClock("",scanRate,SampleClockActiveEdge.Rising,SampleQuantityMode.ContinuousSamples);

then the error message goes (so it presumably refers to this function call)and the application thenruns, with the analog values being read correctly at the proper interval. The digital callback still gets called and values are read but the samples are not as frequent as they should be.

I must be missing something simple here. Whilst there is an analog continous sample example, there is only a digital single sample one to consult.

Can anyone help me out on this

Ray
0 Kudos
Message 1 of 15
(7,018 Views)
The digital subsystem on your M Series card has no onboard clock. This is why you are receiving the error stating you need an external sample clock when you enter "" as your sample clock source. If you want to sample your AI and digital channels simultaneously, you should use a line similar to the following:

digitalTask.Timing.ConfigureSampleClock("ai/SampleClock",scanRate,SampleClockActiveEdge.Rising,SampleQuanti tyMode.ContinuousSamples);

This will ensure your digital task acquires data at the same rate as your analog task. Finally, start your digital task before the analog task to ensure both tasks start acquiring data at the same instant in time.
Message 2 of 15
(7,017 Views)
Many thanks to you my friend. This has been puzzling me for days and at last my application is now up and running properly.

I had searched through all the help files but could not find this particular piece of information. As a matter of interest can you tell me where it is documented?

Once again many thanks

Ray
0 Kudos
Message 3 of 15
(7,016 Views)
I think the closest thing to what you're asking for is the M Series User Manual. Although admittedly, it's not completely clear from the user manual that this is a limitation.

I would also recommend looking at the Device Routes tab in MAX to see what routes are possible on your device. The driver supports "" or "OnboardClock" as the source of a clock for certain signals as a convenience for the user. However, these are really just aliases for other signals available through dedicated circuitry on your device that act as an onboard clock. For instance, the "OnboardClock" for the ai/SampleClock is really the ai/SampleClockTime
base.
0 Kudos
Message 4 of 15
(7,016 Views)
I'm doing something similar (continuous waveform genertion with
similtaneous analog and hardware clocked digital out with a 6259 M
Series board). I do find that starting the digital task before the
analog causes them to start together once the analog StartTask is
called. However, if I stop them both, then attempt to restart them
again with the same sequence of StartTask calls, they no longer are at
the same point in their waveforms. It appears they start off from
where ever they were when they were stopped.

Is there a way to reset the waveform array index back to the first
point or do something else (reset the task, etc) so they will both
start again at the beginning of the wavefrm ? or at least both start
from the same waveform index point ?

Ste
ve

On Sun, 7 Nov 2004 22:30:45 -0600 (CST), reddog wrote:

>If you
>want to sample your AI and digital channels simultaneously, you should
>use a line similar to the following:
>
>digitalTask.Timing.ConfigureSampleClock("ai/SampleClock",scanRate,SampleClockActiveEdge.Rising,SampleQuanti
>tyMode.ContinuousSamples);
>
>This will ensure your digital task acquires data at the same rate as
>your analog task. Finally, start your digital task before the analog
>task to ensure both tasks start acquiring data at the same instant in
>time.
0 Kudos
Message 5 of 15
(7,016 Views)
Can you point me to an example of how to do continuous and simultaneous AIN and CTR sampling under MX? Basically, I'm trying to sample AIN and CTRs. I'm having trouble routing the /Dev1/ai/SampleClock to CTR0's gate. I understand that CTR0 requires an external sample clock, so I tried exporting the 'ai/SampleClock' signal to RTSI0, and then tried to connect RTSI0 to CTR0's gate... no luck. What am I missing here? Is there any way to simultaneously sample CTR0 and AIN, without resorting to using CTR1 to create an external clock?
Thanks,
-bill
0 Kudos
Message 6 of 15
(6,998 Views)
Hi Bill,

I created a quick example to demonstrate how to synchronize AI and Counter input. I set the counter sample clock to be the ai/sampleclock. Check out how I had to enable the "Duplicate Count Prevention." This is a feature of the new M-series boards. If you using an E-series board, you do not need enable this.
0 Kudos
Message 7 of 15
(6,964 Views)
Thank you Salvador.

Actually, the missing piece was the "duplicate count" property (under M-series/TIO-based cards only!), that I'd finally discovered. Somebody had posted this info in another thread. I was finally able to get the AINs and CTRs to synch correctly. I apologize - I should have posted this fact earlier. Thank you for taking the time out to help me!
0 Kudos
Message 8 of 15
(6,960 Views)
I am having a problem doing a similar thing. My goal is to sample analog channels around 1500 Hz and also a correlated digital line - maintaining the proper alignment between the data is important in this case.

As instructed, I have created 2 tasks and using DAQmxCfgSampClkTiming (DI task) have caused it to sample on the Dev1/ai/SampleClock. Also, I am starting the DI task first to maintain alignment. When I read the AI values using DAQmx_Val_Auto with a wait of 0 and then the DI values using DAQmx_Val_Auto with a wait of 0 I do not read the same number of points. In fact, if I slow it down to 1 Hz I get a pattern where I will read 1 AI point 4 times then 4 DI points at once and this repeats over and over. I am reading DI with DAQmxReadDigitalLines and they are uInt8 data types.

Ed
0 Kudos
Message 9 of 15
(6,899 Views)
Hi Ed,

I am almost certain that what you are seeing is due to teh different buffer sizes you have set for each task. If you do not specify "number of samples to read" for your analog read, the DAQmxRead function will return however many data points are available in the buffer when it is executed. If you specify a number of points, DAQmxRead will always return with the same amount of points.

The same thing goes true for the digital input task. I would suggest specifying the exact same number of "samples to be read" in the DAQmxRead of both tasks. This should fix the problem.

If you still have questions, please post your code and I can look at it.

-Sal
0 Kudos
Message 10 of 15
(6,885 Views)