I've posted in the MultiDAQ board but I think my question fits better in this board.
I'm working on image scan project, using NI 6211's AO to control galvo scanner, and use 6211's clock signal (routed to PFI4) to trigger line scan camera. My issue is whenever I start the image acquisition, the image acquisition start location is very inconsistent (sometime the image acquisition starts 50 points after scanner starts, sometimes 200, 500 points, etc). Here are my steps:
1. Put camera to free running mode
2. Generate a sawtooth signal with 1024 points, at 40KHz (camera is capable of 80KHz)
3. Put camera to edge trigger mode
4. Start the DAQ (I checked with scope, clock signal is generated with sawtooth so, they are synched)
5. Image acquisition starts
I tried swapping step 4 and 5 (start image acquisition, wait for trigger and then start the DAQ) but same result, inconsistent start location. There is little delay with actual scanner starts to move, but I think image acquisition start location has to be consistent if it's little off.
How can I make sure scanner and camera synchronized? Below is sample of my code (I take 10 images, make sure there are no lost buffer, then post-processed them).
Really appreciate the help.
Are you triggering on a rising or falling edge? If you are doing a ramp with a positive slope, you would need to trigger on the falling edge. In your case, it looks like you have 1024 rising edges and one falling edge. If you are triggering on a rising edge, it doesn't see a distinct edge.
The camera is set to start line acquisition, starts on the rising edge of a trigger signal and ends on the rising edge of the next trigger signal. So, if I understood correctly, the acquisition is supposedly between 2 AO clock signals.
You can't use the DAQ sample clock as the trigger, because that pulses for every data point. It will randomly trigger on any point.
It is hard to follow what is being triggered by each signal.
Perhaps generate a square wave for the trigger that is synchronized with the sawtooth wave. Use it for the frame trigger for the camera.
Or use the camera clock as the AO clock, and start the AO using the frame signal from the camera board, if it is available.
hm...maybe that's why my image acquisition start location is randomly spread out. But I don't understand why. I thought using clock pulse signal is the best to synchronize with AO data point (I generate 1024 sawtooth, and wants 1024 triggers at each point). So, if I use counter, would it be synchronized? Maybe I have to generate 4 times more of data points since counter requires minimum of 4 clock ticks.
Unfortunately, NI 6211 doesn't support external clock/external HW trigger.
You can use the AO clock for the line trigger for the camera, but that won't control which line the frame starts on. It can be any of the 1024 points since they are all triggers.
You probably want to add a frame trigger using an AO that is a square wave. If you do this, each frame will start at the exact same point every time.
Is this correct: You want to acquire multiple image frames with 1024 lines each. You want each line of the image to match a point in your 1024 point sawtooth waveform. You want each image frame to start at the same time as the sawtooth waveform.
If this is correct, you should use the AO clock as the line trigger, and the falling edge of the sawtooth waveform as the start or frame trigger. You really only need a start trigger (starts first frame of image acquisition), not a frame trigger (starts each frame of image acquisition). Alternately, generate another AO waveform to use as the start trigger.
One other thing you could try. Once you figure out how to set up a start trigger and line trigger, set up and start the vision acquisition first, and use the AO clock as both the start trigger and line trigger. Then set up the AO and start it. The camera will wait for the AO to start before acquiring anything, then it will be synchronized with the AO.
I'm not sure which trigger you are using right now, but you are only using one. You need to use both for this to work properly. EDIT: Actually, you wouldn't need the start trigger, because the clock wouldn't start until the AO starts, so you could start the acquisition immediately. It just wouldn't acquire anything until the clock starts.
Hmmm... Do you know that this only works if you are sending triggers to the camera itself? Triggering just the image acquisition doesn't necessarily trigger the camera, except for camera link boards, I think. USB cameras need trigger signals connected directly to the camera, I think.
so, currently I used AO clock as line trigger, send directly to the camera, have set the camera height (lines) of 1024 to match with sawtooth data point.
I have tried to start the acquisition (with timeout of 5 sec) and then start the AO 500 msec after image acquisition starts. But still get inconsistent start location...I can't figure out why it's doing it. I've tried using counter tick instead of AO clock, still the same result...
I'm not sure about frame trigger... I didn't see that option in the camera settings (I use Tornado Spectrometer).
Putting the AO start inside the loop makes the programming a little confusing. I would keep it before the loop for clarity.
Perhaps make the delay a little longer? How long does it take for the spectrometer to start acquiring? I have seen cameras that take a good part of a second to go through the configuration and startup process, and a spectrometer could take even longer.
This has gotten to the point where I would need the hardware to figure out the problem. I don't think I will be much more help.
Thank you so much for the advise. I'm also trying to see if there is anything wrong I did in the way I coded to do image acquisition but if the code looks correct, I will look into more of other options - different trigger options.