From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generate two PWM signal at a DO using PCIe-6323, and control output of one PWM using the other.

Solved!
Go to solution

Hello,

I am using NI-DAQ PCIe 6323 for my PWM signal generation. I have implemented the attached code snippet to generate a single PWM at a DO using Labview. For my experiment, I have to drive LEDs using a DO at 10-15 Hz using a PWM. But I also have to control their brightness using another PWM varying between 5-100KHz. I was thinking of making two counter signals, one to generate a PWM of 5-100KHz continuously at the DO and another one to turn the DO on or off based on the 10-15Hz PWM. I don't know if this is possible. Please suggest me some way.

 

Thank you.

 

PWM.png

0 Kudos
Message 1 of 9
(1,386 Views)

I tried something like the attached code snippet, but I'm not sure if it will work and I don't want to damage the DAQ. I just implemented the same code for PWM and generate two PWM but output both of them at the same Digital Output pin. Could anyone please confirm if it looks ok?

 

2 PWM.png

0 Kudos
Message 2 of 9
(1,373 Views)

I don't think that you can specify the same output terminal from two different tasks. Most likely you are going to get an error stating that the terminal has been reserved. If you don't have an actual hardware yet, you can test your code with Simulated NI-DAQmx Devices

-------------------------------------------------------
Control Lead | Intelline Inc
Message 3 of 9
(1,339 Views)

You were right about the error ZYOng. I tried simulating and the code does throw the error that resources are currently in use by another route.

 

Do you know if I can trigger a counter based on another counter? Maybe I can output just one counter to the DO but control that counter using another counter!

 

Thank you.

0 Kudos
Message 4 of 9
(1,314 Views)

@yp96 wrote:

Do you know if I can trigger a counter based on another counter? Maybe I can output just one counter to the DO but control that counter using another counter!


You can create a re-triggerable counter output task in which the start trigger is routed from another counter. You can refer to the Generate Digital Pulse With Retriggerable Digital Start Trigger from Archived: Download Legacy NI-DAQmx Shipping Examples for LabVIEW 2011 and Earlier

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 5 of 9
(1,302 Views)

So I tried controlling the second counter by providing the Ctr0InternalOutput as the source for the second counter sample clock. I also set the task as Retriggerable. But I got the error as 'Generation cannot be started, because the selected buffer size is too small. Increase the buffer size.'

 

Please check the attached snippet and let me know what you think.

 

Thank you.

 

PWM 4.png

0 Kudos
Message 6 of 9
(1,287 Views)

For unknown reasons, I am not able to import your snippet hence I cannot modify your code directly. Here is my recommendation:

1. Use Implicit Timing for both tasks. You don't need to use the sample clock here.

2. On the second higher freq task with re-triggerable enabled, configure a Digital Start Trigger in which the source of the trigger is Ctr0InternalOutput. We are re-triggering the generation of the high freq pulse train on each incoming pulse from the lower freq counter.

3. Start the higher freq task first before you start the lower freq task. The higher freq task should be ready to receive the trigger before the lower freq task starts generating pulses.

-------------------------------------------------------
Control Lead | Intelline Inc
Message 7 of 9
(1,268 Views)

Thank you ZYOng. Your suggestions seem to be working.

 

I tried to confirm it using NI-MAX Test Panels for my simulated device. While my LabVIEW code is running, if I try to use those counters or the PFI pin in the test panel, it throws an error saying 'Resource requested by this task has already been reserved by a different task'. I think that means the code is actually using the resources. I have also attached the snippet for future reference. I hope it will work on the actual hardware now. 🙂

Thank you again.

 

 

PWM fin.png

Message 8 of 9
(1,239 Views)
Solution
Accepted by topic author yp96

Just a minor update. Instead of using a digital start, I had to use a digital pause. The digital start did start counter 2 with a rising edge of counter 1, but it will not pause counter 2 when counter 1 was low, so instead I added pause when low. There are still some issues with syncing at different frequencies, but for now, it serves the purpose of my main question of driving one counter using another.

 

PWM 1.png

0 Kudos
Message 9 of 9
(1,190 Views)