How can I synchronize a trigger and an analog output on an NI USB-6259?

19 Views Asked by At

I want to use python to control an NI USB-6259 DAQ board. I want it to receive a TTL trigger (from a SpinCore Pulseblaster) so that it will put out a constant voltage for the trigger width duration. Eventually I want to be able to ramp down the voltage as well as configure other analog output channels to either ramp down or produce constant voltages. The main issue that I am encountering is that when I check the trigger and output voltage on an oscilloscope there is a delay close to 4 ms but even then the delay still fluctuates and in some cases it last longer than the trigger width. I'm hoping its a simple mistake I'm doing. Thanks

import nidaqmx

#Define your desired parameters
trigger_source = "/Dev4/port1/line0"  # Define the trigger source
output_voltage = 1.0  # Set the output voltage (in volts)

#Create tasks for analog output and digital input (for trigger)
with nidaqmx.Task() as ao_task, nidaqmx.Task() as trigger_task:
    # Configure the analog output channel
    ao_task.ao_channels.add_ao_voltage_chan("/Dev4/ao0", min_val=-10.0, max_val=10.0)

    # Configure the digital input channel for the trigger
    trigger_task.di_channels.add_di_chan(trigger_source,
    ine_grouping=nidaqmx.constants.LineGrouping.CHAN_PER_LINE)

    # Flag to indicate whether voltage is currently being output
    voltage_outputting = False

    # Use an infinite loop to continuously monitor the trigger
    while True:
        # Wait for rising edge
        rising_edge = trigger_task.read()

        # If rising edge detected and voltage is not currently outputting
        if rising_edge and not voltage_outputting:
            # Output the voltage
            ao_task.write(output_voltage)
            voltage_outputting = True

        # If falling edge detected and voltage is currently outputting
        elif not rising_edge and voltage_outputting:
            # Turn off the voltage
            ao_task.write(0.0)
            voltage_outputting = False
0

There are 0 best solutions below