06-18-2018 11:37 AM
Only have time for brief thoughts now:
1. Treat each 0.25 second interval as a distinct run of a finite sampling task. There will be a small idle time between each of these intervals, but this will limit you to managing 25 kSamples at a time and will eliminate issues with very small increments in amplitude such as 0.01 V per run.
2. To do this, you should have DAQmx Write, DAQmx Start, DAQmx Read, and DAQmx Stop all inside the loop. Each iteration will be a single full 0.25 sec trial run with a specific amplitude.
3. Outside the loop, I would generate a single 25000 sample sine wave with amplitude = 1.0. I would pass this into the loop and then multiply by the desired amplitude inside the loop before passing along to DAQmx Write. There's no need to recalculate the sine wave pattern, it only needs to be scaled.
4. Syncing AO and AI via sample clock is typically most valuable when *not* also looping the AO signal back as an AI channel to be measured. You may end up finding that *sequencing* the AO and AI tasks (and perhaps capturing more AI samples than are generated by AO) does a better job of giving you all the data you want, especially if there's a noticeable response delay between AO signal and photodiode response.
-Kevin P
06-19-2018 07:10 AM
Hello Kevin,
Thank you very much for your suggestion. In point 4, you said AI is capturing more samples than AO, could you explain in more details?
In my experiment, please disregard the response delay between the AO signal and the photodiode response and assume the photodiode is fast enough, can your suggestion synchronize the AO and AI and capture the same number of samples?
I revised my VI according to your suggestion, please see attached file. The program can run without problem when delta=0.01V. However, I checked the AO waveform using CRO and found that the waveform is not continuous. Each 0.25s sine waves are separated by 30ms long -0.6 DC voltage. This DC voltage will affect my experiment and should be removed. Moreover, I do not know whether AI is capturing any data during that 30ms period. That data should also be removed. Any method to prevent this?
Jacob
06-19-2018 07:33 AM
This is the first time I've caught on clearly to the need for a seamless transition of the output AO signal when changing the amplitude. Thus, most of my advice in msg #21 is wrong. Instead, try the following:
1. Continue to compute a single 0.25 second duration sinusoid of amplitude 1.0 outside the main loop.
2. Now, DAQmx Start and Stop will be outside the main loop. Only DAQmx Write will be inside (for the AO task). You'll also have an earlier DAQmx Write that you call before DAQmx Start to pre-seed the buffer.
3. You'll now also be switching over to continuous sampling mode so that you can write samples to the buffer a little at a time. It'd be nice to do finite sampling, but your memory requirements grew too big to predefine the entire AO signal history in one data chunk. The main loop should now be a While loop too.
4. For my first DAQmx Write (prior to DAQmx Start), I'd probably multiply the sinusoid by 0.0 and write the values twice. So the experiment will start with 0.5 seconds worth of 0 V output (i.e., no stimulus).
5. Inside the loop, scale the sinusoid by the desired amplitude and send it to DAQmx Write. The samples will be go to the "end of the line" of the task buffer and won't become output signals until all the previously written values have been generated. If there isn't room for all the samples, the call to DAQmx Write will block and wait until there *is* room.
Keep the loop tight so you are sure to iterate fast enough to avoid a buffer underflow.
6. Once you've reached the last *real* amplitude, keep iterating while feeding DAQmx Write with 0 values. Wait until you know those 0 values are being generated as signals before you terminate the loop and call DAQmx Stop.
-Kevin P
06-19-2018 08:53 PM
Hello Kevin,
I modified the program as you suggested except point 6 which I did not perform since I need some time to figure out how to do it. Also, I need to delete the AI start digital edge in order for the program to work properly.
However, I found that AO is not synchronized with AI read. Please see PD input waveform of Panel4.pdf (AO is physically routed to AI 1). For the first 0.24s, it reads 0.9V and for the last 0.01s, it reads 1V. Panel4b shows the magnification view of the PD input waveform. This is what I have worried about the synchronization problem if the DAQmx write is put inside the while loop. I need to make sure AI is sampling the same AO data when AO is outputting a particular amplitude of sine wave during that 0.25s. Do you have any means to solve this problem?
Jacob
06-19-2018 11:04 PM
In the block diagram pic you attached, you are no longer being careful to sequence the task starts. With AO as the "master" and AI as the "slave" that uses the AO sample clock, it's *necessary* to make sure the AI task starts *before* the AO task. You've removed any such sequencing that was present in prior versions of code. You need to put it back.
Again, the keys to sync: Have a slave task use the sample clock from a master task and be sure to start the slave task before starting the master task. That's it. It isn't about whether you start outside or inside a loop, it's about whether you force the slave (AI) to start before the master (AO).
-Kevin P
06-20-2018 05:36 AM
Hello Kevin,
You are right, I overlooked what you have said at the very beginning. After putting back the AI start and AO start in correct sequence, synchronization works properly. I also performed point 6 of your suggestion, the program is now working perfectly. Thank you very much for your professional help.