08-27-2012 04:04 PM
I'm using a USB-6361 device, and I'm trying to sample a digital input and an analog input synchronously. I'm using the same external hardware trigger to start each acquisition, and the same external sampling clock for each. I'm testing it out with a simple square wave and sine wave input, but each time i do an acquisition, the phase between these samples changes, and is also not correct. The signals however are not changing (confirmed by looking at them on a scope just prior to being input into the NI device). Amplitude measurement & frequency seem to be fine, just phase relative to each other is off, and randomly changes with each acquisition.
Any ideas why this may be happening, and what i can do to correct it?
08-28-2012 10:38 AM
Can only guess without seeing the code, but here's my shot at playing Carnac:
The signal you're using as a trigger is repetitive. If both tasks use the same external signal for sampling, they must be getting triggered at different times.
To be sure of solving it, you need to trigger off something that only happens once. For example, just make this edge yourself directly with a DO line or counter pulse. If you need some kind of timing sync to a repetitive external signal, set your AI and DI to trigger off a new counter task you make, and set that counter task for single triggered pulse generation with minimal low/initial delay time. Start the AI and DI tasks before starting the counter task so they'll both be ready to trigger off the single pulse.
-Kevin P
08-28-2012 01:03 PM
Hi Kevin,
Thank for the help, I tried using a non-repeating trigger, and that seems to work! I'm still a little confused as to why a repeating trigger wouldn't work -- shouldn't both acquisitions trigger off the first rising edge they see? I'm having trouble understanding why they would trigger off of different edges of the same signal if the tasks start at the same time. Although I suppose the tasks may not start at the same time, since that is controlled by software -- would that be why?
08-28-2012 01:50 PM
Yeah, that's right. The task start is controlled by software. You can sequence the config carefully to make them start within a few msec or less of one another *usually*, but there's always a small chance for the OS to make that delay much larger.
Anyway, yes, both tasks will trigger off the first rising edge they see. But since the tasks don't start simultaneously, they may not each see the same rising edge.
Another way to sync AI and DI without *any* trigger at all is to config the DI to use a signal named similarly to "/Dev1/AISampleClock". Then make sure the DI task is started before the AI task so it'll be ready to take its first sample when the AI task starts and takes its first sample too.
-Kevin P
08-28-2012 02:25 PM
Another way to sync AI and DI without *any* trigger at all is to config the DI to use a signal named similarly to "/Dev1/AISampleClock". Then make sure the DI task is started before the AI task so it'll be ready to take its first sample when the AI task starts and takes its first sample too.
------------------------------------------------------------------------------------------------------------------------------------
Are you saying to 'trigger' the DI using the AI sample clock?
I'm using the same external sampling clock for both the DI and AI...i just want to be able to sync them up so that they start sampling on the exact same sample clock edge.
08-28-2012 05:15 PM
No, I'm saying to "clock" the DI task with the AI sample clock. This can be configured to use some internal routing on the board without any wiring work. You can still specify that the AI task uses the external clock for sampling. The difference is that by telling the DI task to use the AI task's sample clock, it'll *only* receive edges while the AI task is actually running.
Here's an example of what I mean:
-Kevin P