Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating DO continuous signal (using PFI channels?)

Solved!
Go to solution

Hi,

I am new to using NI and its interfaces. I am using the USB-6221, with its C API.

 

I need to create several Continuous Digital Output channels with frequency and duty cycle.

I first used DAQmxCreateCOPulseChanFreq for crt0 and crt1 channels and it works fine, but I need a few more DO lines.

 

Can I use the PFI channels (PFI0-4 for example) for this purpose?

Using the DAQmxCreateDOChan I can define the desired PFI channels as DO, but how can I create the desired signal on these channels?

 

Best Regards,

Danny.

0 Kudos
Message 1 of 7
(3,834 Views)
Solution
Accepted by DannyN

Howdy Danny!

 

If you are trying to generate a digital pulse train with a specified frequency and duty cycle then using the USB-6221's onboard counters is definitely the way to go.  Unfortunately, as you have discovered there are only two hardware counters available on the USB-6221 (Ctr0 and Ctr1).

 

Fortunately, you can also use the digital output lines to effectively create a pulse train with a specified frequency and duty cycle.  You will need to create an array of samples that, when output at the specified sampling rate, will resemble a period of your waveform.  For example, if my sampling rate is 1MHz and I want to create a 100KHz square wave with a duty cycle of 20% high/80% low I would generate the following samples:

 

{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

 

Please let me know if this description is clear or if there is anything I need to explain in more detail.

 

Regards,

 

 

Barron
Applications Engineering
National Instruments
Message 2 of 7
(3,810 Views)

Hi Barron,

 

Thank you very much for your help.

I will be able to check it in 2 days only, but meanwhile, let's see if I got it right:

 

To continue tour example, I assume I need to create a clock of 1 MHz first. To do so I need to create a seperate task, than use DAQmxCreateAIVoltageChan and DAQmxCfgSampClkTiming with a rate set to 1000000 and NULL as the source channel.

Now I create a second task for the 4 DO channels I need, and again use the DAQmxCfgSampClkTiming command, this time with the DO channels task, same rate (1MHz) and source field set to "ai/SampleClock".

Now I create the

 

A few questions:

  1. For the clock creation, I can use either AI or AO. Can I use one of the digital I/O as well? If yes, using which function?
  2. In your example, you used two ones and 10 zeros to generate a 20% duty cycle. I assume you ment to write only 8 zeros?
  3. Which function to use when writting the data to the channel - DAQmxWriteDigitalLines? It seems to be identical to DAQmxWriteDigitalU8.
  4. How did you come to the 100KHz? When you write the data to the channel, what value do I use for the numSampsPerChan parameter?

Best Regards,

Danny.

0 Kudos
Message 3 of 7
(3,799 Views)

OOppssss,

 

Ignore question number 4 ...

0 Kudos
Message 4 of 7
(3,797 Views)

Thanks. The output channels work perfectly.

0 Kudos
Message 5 of 7
(3,773 Views)

You should mark Red Barron's answer as the solution - not your thank you. You can click on 'Options' to change the marked solution.

0 Kudos
Message 6 of 7
(3,767 Views)

OK. I have corrected my mistake. Thanks.

0 Kudos
Message 7 of 7
(3,758 Views)