pythonsynchronizationclocknidaqmx

Export sampling clock of PXI 6251 using python


I want to synchronize two PXI 6251 on a PXI 1000 chassis to acquire 32 analog inputs simultaneously. I am using python with the nidaqmx library. To do so, I want to export the sampling clock of one card on a digital output, route it to a digital input of the other and use it as an external clock. Is it a good strategy?

I have tried the following code. The analog input logging works, but I can't see the clock on the terminal 2.7 (PFI15)

import nidaqmx
import time

with nidaqmx.Task() as taskAI, nidaqmx.Task() as taskClkExport:
    acquisition_time = 10
    rateAI=50000
    t=time.localtime()
    file_path_2 = r'C:/Users/laboratorium/Documents/remi/{}_{}_{}_{}_{}_{}_slot2'.format(t.tm_year, t.tm_mon,t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec)

    # configure analog input task
    for i in range(16):
        taskAI.ai_channels.add_ai_voltage_chan("PXI1Slot2/ai{}".format(i))
    taskAI.in_stream.configure_logging(file_path_2,
                                  nidaqmx.constants.LoggingMode.LOG,
                                  'myGroupName',
                                  nidaqmx.constants.LoggingOperation.OPEN_OR_CREATE)
    taskAI.timing.cfg_samp_clk_timing(rate=rateAI,
                                 sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS,
                                 samps_per_chan=2048)

    # configure clock exporting task
    taskClkExport.do_channels.add_do_chan("PXI1Slot2/port2/line7")
    taskClkExport.export_signals.export_signal(signal_id=nidaqmx.constants.Signal.SAMPLE_CLOCK,
                                           output_terminal="PXI1Slot2/port2/line7")

    print('start')
    taskClkExport.start()
    taskAI.start()

    print('running...')
    time.sleep(10)

    print('stop')
    taskAI.stop()
    taskClkExport.stop()

I checked on MAX device routes, and any PFI is suited for direct routing of the sampling clock. I can invert the line from a DO task in MAX.

does someone knows the solution?


Solution

  • I could not export the sample clock on this gear, The solution I found is using the same master clock, and use the start trigger of the first card for the second one. I start the second one (waiting for the trigger) end then the first one.

            self.task2.timing.ref_clk_src = "PXI_Clk10"
            self.task2.timing.ref_clk_rate = 10000000
            self.task2.timing.cfg_samp_clk_timing(rate=rate2,
                sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS,
                samps_per_chan=2048)
            self.task3.timing.ref_clk_src = "PXI_Clk10"
            self.task3.timing.ref_clk_rate = 10000000
            self.task3.timing.cfg_samp_clk_timing(rate=rate3,
                sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS,
                samps_per_chan=2048)
    
            self.task2.control(TaskMode.TASK_COMMIT)
            self.task3.triggers.start_trigger.cfg_dig_edge_start_trig(
                "/PXI1Slot2/ai/StartTrigger")
    
            self.task3.start()
            self.task2.start()