LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modulation of 3 digital ports of the NI DAQ board

I want to modulate 3 light emitting diodes at different frequencies. On the NI DAQ board (USB 6216) I have created 3 ports:

Yaro42_0-1701269540527.png

Next, in the while loop I  create a waveform to provide input to the digital channels (one example)

Yaro42_1-1701269599358.png

I verified that inputs are plotted correctly

Yaro42_2-1701269623871.png

I wrote this arrays into the DAQmx write and put the probe (16 at the input to write)

Yaro42_5-1701269663640.png

 

However, light emitting diodes are not modulated (set to zero). When I run the program the probe shows :

Yaro42_6-1701269750073.png

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.

 

 

0 Kudos
Message 1 of 7
(880 Views)

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

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 2 of 7
(871 Views)

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.

0 Kudos
Message 3 of 7
(843 Views)

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.

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 4 of 7
(840 Views)

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!

0 Kudos
Message 5 of 7
(825 Views)

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.

 

-------------------------------------------------------
Control Lead | Intelline Inc
Message 6 of 7
(805 Views)

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) :

Yaro42_0-1701376801408.png

 

I have also attached the vi. Does anyone have an idea of how to improve timing?

 

Thank you!

0 Kudos
Message 7 of 7
(751 Views)