11-29-2023 08:57 AM
I want to modulate 3 light emitting diodes at different frequencies. On the NI DAQ board (USB 6216) I have created 3 ports:
Next, in the while loop I create a waveform to provide input to the digital channels (one example)
I verified that inputs are plotted correctly
I wrote this arrays into the DAQmx write and put the probe (16 at the input to write)
However, light emitting diodes are not modulated (set to zero). When I run the program the probe shows :
The middle FALSE is rapidly switching between F and T, others are constantly set to FALSE. I modulate diodes are 1Hz, 2Hz etc so I expected to see F and T switch at this rate. What did I do wrong?
Thank you.
11-29-2023 09:16 AM
Since you didn't use DAQmx Configure Sample Clock Timing VI, you are using software timing. Did you use any Wait(ms) in the while loop?
Usually we use a counter to generate PWM. Since you need 3 PWM, you would need 3 counters but 6216 only has 2 counters. And unfortunately, 6216 does not support Correlated DIO
11-29-2023 11:03 AM
Square waveform function have the sampling info as the input. I select the same sampling rate and the number of samples in the waveform as the frequency and samples in the DAQms write. I assume every loop the code would generate and write the same number of samples but at different modulation frequencies as defined by the Square waveform function. The timing should be fixed by the common sampling rate.
11-29-2023 11:14 AM
The sampling info from the function generator is only for the data. You can still write the data at a different rate. You would need to implement your own timing for DAQmx Write VI.
I would recommend you post your code so that we can understand it better.
11-29-2023 01:40 PM
Sure, here is the file. The top while loop is probably irrelevant to the question, it reads 2 analogue input channels. The bottom while loop contains block diagrams to modulate digital channels, that I described above.
The timing might indeed be an issue (though a separate one), I do not think that is the reason I see no modulation on light emitting diodes. As, I described , if I place the probe before the "write function" to PFI, I do not see adequate modulation at the input. However, I see correct waveforms on the plot. It might be how data are merged or converted from the Dynamic data to array?
Thank you for looking into this!
11-29-2023 03:08 PM
When you convert the dynamic data into an array, the timestamp information is lost.
Since USB-6216 does not support hardware timing for digital and you need 3 channels, your best approach would be to use software-timed digital output. See the shipping example at Help >> Find Example... >> Hardware Input and Output >> DAQmx >> Digital Output >> Digital - SW-Timed Output.vi
Note that the software timing has an accuracy level of tenth to hundredth milliseconds.
If you need high timing accuracy, you can use the combination of 2 AO and 2 counters but it would be more complicated.
11-30-2023 02:55 PM
Thank you for your suggestions. So far, the problem with "no modulation on LEDs" was solved. After merging 3 waveforms to modulate light emitting diodes, the dynamic data format gave as input (3 chanels , samples per channel). However, when channels are defined as "Dev3/port0/line0:3" it is treated as a single channel. Therefore to write data I need to choose "Single channel-> multiple samples" and the input vector for 3 (chanels) should be reshaped matrix as (1, concatenated into one vector waveforms). Since I define on the DAQms Sample Clock function 200 samples per channel and 2k rate , the input to write vector is (1chanel, 3 x 200).
BUT two loops for acquisition of analgue inputs and generation of digital outputs run slowly. Analogue Input while loop has elapsed time130- 150ms, digital output while loop is even slower 300ms. However, in order to have acquisition rate of 2k and transfer packages of 200 samples I need each iteration of the loop to run at 100ms. I tried parallel/sequential structuring of channels, delays are similar. According to the suggestion of ZYOng I have also tried to do 2 AO instead of Digital. BUT elapsed times got even worse, you may see it next to saving data (below). Also, on the right hand-side of the figure you can see how much data are delayed/swallowed (space between white bars-recorded data) :
I have also attached the vi. Does anyone have an idea of how to improve timing?
Thank you!