Multifunction DAQ

Showing results for 
Search instead for 
Did you mean: 

Creating a steady PWM of 100 KHz using NI-9402 and cDAQ-9178

Go to solution

Hey Emboar,

Thx for the tip about the trigger.

I tried this solution :


I got an error :



I can't see where the problem lies. I'll keep checking and update as soon as I found a solution,PWM.png


0 Kudos
Message 11 of 26

I guess I made some progress and i'm close to achieving what i want.
Though, when I try to use a digital input for my trigger. I keep getting errors. Now, I have an error telling me that each line of port 0 are used for input and I can't use them for output. But the FPIx I use are all used for input..

I tried to use the 80 MHz timebase for triggering; but there is no synchronization between all 4 counters. I'm a bit lost of what to do now



0 Kudos
Message 12 of 26

I read in the forum that the Ni 9401 is "nibble" configurable. It means that I can only configure I/O by team of 4 ports (0 to 3) and (4 to 7).

Does it mean, since I'm using all 4 counters in output, I can't use any input anymore?
In this case, how can I get a DI for trigger purpose?



0 Kudos
Message 13 of 26

Here's an idea about the triggering, I can't speak to the particular nybble-wise limitations of your cDAQ device(s).


Try configuring the CO tasks to be triggered by a terminal named something like "/cDAQ1Mod1/do/StartTrigger".   In your sequence frame, stop the DO task immediately after initializing the line to "False" and before starting the CO tasks.  Then explicitly restart the task after the CO tasks have been started.


[EDIT:  after giving this a quick trial run on a desktop X-series board, I need to amend the advice.  It looks like you may *also* need to configure the DO task to be hardware-timed by calling DAQmx Timing.  It appears that software-timed DO tasks don't assert the "/.../do/StartTrigger" signal when they are started, only hardware-timed tasks.  After this change, this tested out to work on a PCIe-6341.  I used 3 shipping examples to test -- 1 for hw-timed DO, 1 for continuous CO pulse generation, 1 for CI edge counting on those pulses.]



-Kevin P

Message 14 of 26

Thanks Kevin_Price for your kind effort.

Clément, NI 9401 is a bit difficult device to use. It is "nibble" as you understood.

Configuring an NI 9401 for Bidirectional DIO By Nibble with DAQmx


I "guess" sharing start trigger would achieve what you want to but I don't have a confidence.

Please try Kevin's suggestion.

Certified LabVIEW Developer
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Message 15 of 26

Thanks the both of you.
I'll try both suggestions and hope I'll make it works!


0 Kudos
Message 16 of 26


I tried your solution Kevin and I need some help. So far, I can't generate any DO from the hardware-based DO. I'm dropping the Vi further down below, could you check and tell me if what I did correspond to what you proposed? I used a sample clock.

If I'm good, I got buffer error after starting the task. I tried to write before starting but got other errors..


@Emboar : I truly didn't understand how the DI/O nibble configuration works, but I don't think that could match with what I'm doing (but not sure tho, since I didn't really get it..)




KP_solution.pngKevin's solution?bufferError.PNGbuffer error

0 Kudos
Message 17 of 26
Accepted by topic author ClementIRT

Yes, your code looks like what I was suggesting.  Unfortunately, my suggestion wasn't thorough enough.   Let me fill in some blanks.


1. Unlike sw-timed DO tasks, hw-timed DO require you to write data to the buffer *before* starting the task.  You mentioned having tried that, what error did you get?  (Note: you can look at the shipping example for Finite or Continuous DO to see how to set things up.)


2. You probably need to write more than 1 value to the DO task when it's set up with a hw clock.  Dunno the minimum, but the shipping example runs with only 8.

    Once you write data before the first Start, you don't need to re-write before (or after) the second Start.


3. If you keep having trouble with DO, it's possible you could use a DI task here instead.  After all, you're only creating the task for the sake of the its internal start trigger signal.  A hw-timed DI task ought to be an option too.



-Kevin P

Message 18 of 26

Kevin ! You're a wonderful Labview magician!


It is working now. My mistake was to write only 1 sample to the buffer before starting. So I had an error saying "Tu-Tu this is labvimpossible".


I am writing only 2 samples now and it's working good Smiley Very Happy. I am dropping the Vi below in case someone encounter the same problem. I need still need to work on a lot of things but this damn PWM was getting on my nerves.
Thanks Kevin and Emboar for your help.


4 synchronizable PWM with Ni-9401.png


 [EDIT] Mea culpa! There is a last error (always a last one).. still here.. You need to delete the 2nd if not, you gonna get an error 200288. good solution.PNG


0 Kudos
Message 19 of 26

Quick followup, not crucial as you have things working, just a couple FYIs.


You probably don't even need to do the 2nd write (the one found between the first stop and the 2nd start).  On boards I'm familiar with, restarting a task without changing the buffer contents will simply re-generate the same original buffer contents.


Further thought: in your app, the actual DO output *signal* is entirely arbitrary.  Thus the code can be simplified even further.  In the 1st sequence frame, write the data but do not start or stop the task.  There's no need to preset the DO *signal* prior to starting the counter tasks.  (And frankly, the write can happen before the frame and the 1st frame can be deleted.)   In the 3rd sequence frame, merely start the task without any writes.  (And frankly, the start can also move outside and after the sequence, then the 3rd frame can be deleted too.)


And again, because the DO output signal doesn't matter, you could probably substitute a DI task for the DO task.  Then there'd be no need to call DAQmx Write (or DAQmx Read either).


Just FYI, in case you want to try to simplify things further.



-Kevin P

Message 20 of 26