02-24-2025 04:24 PM
I just want to output waves from the USB6421 ao0 and DIO0, but I find there is a delay between the analog and digital waves. I generated the analog and digital waves with same sampling rate.
Generated analog and digital waves:
Output analog and digital waves by USB6421 measure by Oscilloscope:
02-25-2025 07:10 AM
What's missing is that you need to sync the tasks to start at the same time. Right now there's an offset due to the execution time needed to get the tasks started under software timing control. You need to sync their start times via hardware instead.
Because both your tasks are on the same device, a "start trigger" will be sufficient. My recommendation: configure both tasks for a start trigger from one of the PFI terminals that serves double duty as a DIO line. Then even after the software calls to start the tasks, signals won't start generating your waveforms until the hardware trigger signal asserts.
You can control the trigger with a separate DO task that you'll start *after* starting the other two tasks. A quick toggle high and low will make your AO and your other DO get started in sync. The fact that they're on the same device means that they derive their sample clock from the same internal clock so they'll *stay* in sync. (This wouldn't be true if they were on different devices. Small tolerances in clock frequency would make them drift apart over time. A pretty common clock spec would allow an error of about 3 millisec per minute of acquisition.)
-Kevin P
02-26-2025 02:58 AM
Hello,
Some indication to port into python the solution explained in previous post:
I note that you are configuring "source" through cfg_samp_clk_timing. If you had 2 or more separate devices and a connection between the 2 through RTSI or PFI, the framework would share the clock from master device to slave device and they would stay in sync (I am doing clock sharing through RTSI). Here you are on same device so works without extra cable
To share the start trigger, I am doing:
for slave_task in all_slave_tasks:
slave_task.triggers.start_trigger.cfg_dig_edge_start_trig("/" + master_task.devices[0].name + "/ai/StartTrigger") # this will be /Dev1/ai/StartTrigger, you need to adapt to your terminal, like ao or do. Well, no do/StartTrigger in https://www.ni.com/docs/en-US/bundle/ni-daqmx/page/termnames.html so ao may need to be the trigger or here is some concept I don't know
Then:
for slave_task in all_slave_tasks:
slave_task.start()
master_task.start()
slave_task will start upon receiving master_task trigger