Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronizing AO to AI for a fixed number of output voltages

Hello all,

 

I am a new user trying to set up my PCIe-6321 with BNC2110 breakout box using the Python package nidaqmx. I have two mirrors, one resonant and one galvo, which I need to synchronize to perform a 2D laser scanning operation. 

 

The resonant mirror outputs a square wave signal at 8 kHz to indicate its position; when the voltage is on a rising or falling edge, the mirror is changing directions. I need to synchronize the signal delivered to the galvo mirror to the resonant mirror input signal such that when the resonant mirror switches directions to begin a new line scan, the galvo mirror moves a step to scan a new line. The galvo mirror just has to maintain that voltage until the resonant mirror begins a new line scan. Once the galvo mirror has been moved to all its possible positions, I want to stop both tasks.

 

From my understanding, I need to set the the resonant mirror AI to be continuous, and galvo mirror AO to be retriggerable and to trigger off of the falling slope of the resonant mirror AI signal. What I think I'm having trouble with is actually figuring out how to actually tell the galvo mirror AO port to set itself to a new voltage every time it's triggered.

 

My code so far is below. Right now I'm getting an error that says the "ao_task.triggers.reference_trigger.cfg_anlg_edge_ref_trig() property is not supported by the device or is not applicable to the task." I'm really not sure where to start with that.

 

Thanks for any help in advance!

 

 

 

def bnc2110_aiao_sync_test():
    i=0
    galvo_voltages = get_galvo_voltages() # my function which produces the array of the voltages I must set the galvo to
    
    with nidaqmx.Task() as ai_task, nidaqmx.Task() as ao_task:
        ai_task.ai_channels.add_ai_voltage_chan("Dev1/ai0") # resonant mirror voltage to be read in
        ai_task.timing.cfg_samp_clk_timing(rate=8000.0, sample_mode=AcquisitionType.CONTINUOUS)
        terminal_name = get_terminal_name_with_dev_prefix(ai_task, "ai/StartTrigger")
        
        ao_task.ao_channels.add_ao_voltage_chan("Dev1/ao0",min_val=-9.5,max_val=9.5,units=VoltageUnits.VOLTS) # galvo mirror voltage to be written out
        ao_task.triggers.reference_trigger.cfg_anlg_edge_ref_trig(terminal_name,pretrigger_samples=8000,trigger_slope=Slope.FALLING)
        ao_task.triggers.reference_trigger.retriggerable=True
        
        ao_task.start()
        ai_task.start()
        
        # this while loop is supposed to step through the voltages I need to set the galvo AO port to.
        while (i<len(galvo_voltages)):
                def ao_callback(task_handle,signal_type,callback_data):
                    global i
                    ao_task.write(galvo_voltages[i])
                    i+=1
                
                ao_task.register_signal_event(Signal.REFERENCE_TRIGGER, ao_callback)

        ai_task.stop()
        ao_task.stop()

 

 

 

 

 

 

0 Kudos
Message 1 of 5
(174 Views)

Please share a timing diagram of the signals you would like to generate for easy understanding.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 5
(112 Views)

Your 6321 device does not support analog triggering.  You need to find another way to sync.

 

Is your resonant mirror's square wave output compatible with the digital logic of your 6321?  (Roughly, 0 V low, 3-5 V high?).  If so, you can use the 6321's digital change detection feature to issue a single internal pulse (the "change detection event") for each square wave transition, both L->H and H->L.   Then the galvo AO task can use that internal pulse as its sample clock.

 

If not compatible, some kind of simple external chip circuit can accomplish the same thing -- issue a very brief pulse for each digital transition.  And again, the galvo AO task can use that external pulse as its sample clock.  I'm not an EE however and don't have a specific recommendation for what to buy/build, hopefully someone else will...

 

 

-Kevin P

 

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 3 of 5
(99 Views)

Thank you for the reply, this is very helpful! I think I'm on the right track now. My resonant mirror output is delivered through a BNC cable, so I was hoping to use the PFI0/P1.0 connector on my BNC2110 to detect this signal. However, that port does not seem to support buffered tasks so I can't use do a continuous acquisition and use the "change detection event" function there. In that case, I think I'll have to use one of the Port 0 input channels on the terminal block. I can't see any other way to get a digital signal in a buffered task. Do I have that correct? Thanks for any further input!

0 Kudos
Message 4 of 5
(79 Views)

For any future readers, I ended up connecting my BNC cable to the "User 1" defined signal port on the BNC2110, and then connecting the User 1 port on the terminal block to the PFI1 port to use the digital input signal as the sample clock for the analog output timing. Thanks again for the help everyone!

0 Kudos
Message 5 of 5
(42 Views)