Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use NI9474 and cdaq9172 to generate variable duty cycle 1khz pulse

Solved!
Go to solution
Hello, I wish to use an NI9474 (in a cdaq9172 chassis) to send a square wave with a frequency of 1khz. The duty cycle will change roughly every second (based on voltage readings of NI9205 in separate while loop, by controlling local "duty" variable). It is important to have some decent output timing resolution; i.e. the difference between 50% and 51% duty cycle should be noticeable. The 9474 says it has a speed of 1us, so I would expect that to be possible. This is being used for a buck converter. The output is switching on and off a MOSFET, which only needs 5 volts, and less than a mA, when on. I tried a "simulate signal" with a square wave, using a frequency of 1khz, and 100kS/s, and fed it into a DAQ assist with a dynamic data to boolean converter in between (probably not the best approach I confess). I also tried setting it up using the DAQmx vis (no assist). In both cases, I got an error that said I need an external clock. I know the chassis has an internal counter. Could this be used for clocking? I looked at some of the counter pulse examples, but that seems to use a counter as an output, not a digital channel, so I'm a little confused. The digital examples don't seem to be what I want either. If I can't use the chassis for clocking, it's possible I could obtain an NI9401. Could I use this either for counting or for setting up a clock (I could attach a function generator using a 1Mhz square wave for example)? For example with a 1Mhz clock, then for a 50% duty cycle 1khz signal, after 500 clocks go from low to high, and then high to low after another 500, (or 510 and 490 for 51% duty). Is something like that possible? Thanks for any advice, Thomas I should confess to not understanding the counter stuff too well at this point. A lot of the examples I've seen, are seemingly complicated vis.
0 Kudos
Message 1 of 7
(6,797 Views)

Sorry for the format of the original post. I'm not sure how to edit it.

 

After working for a while, and modifying a vi someone else posted, I have the vi shown below (where the bottom block diagram is that of the subvi in the top block diagram). Using the internal clock of 100kHz, and 100 samples, I can output a 1kHz sample. I wanted to try the 20Mhz clock with 20,000 samples (and so still a 1kHz digital output), but apparently my computer can't handle that (or so says labview).

 

Anyhow, using the values shown in the image below, and hooking the output of 9474 to an oscilloscope, I did confirm a 1khz signal. Changes to the duty cycle are also reflected while running. I do have one problem. The waveform rises very quickly (i.e. very small rise time). However, even with a small duty cycle, the waveform never goes back down to zero. It falls pretty slowly. I did get around this a bit by hooking up a resistor to ground at the output, but I was curious if it should do it on its own. Also, it didn't work on line0, so I used line1. After trying again it didn't work on line1, so I had to use line0.

 

 

0 Kudos
Message 2 of 7
(6,791 Views)

Hello hope you are doing great!

 

Is this a DO 5v pulse you are trying to generate? I can think of PWM so you can contol the duty cycle.

 

There are several exaple codes  you can check at www.ni.com/code that involve PWM and variable duty cycle you can check and you can implement to your HW set-up.

 

Luis A. 

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

The 9474 uses an external voltage source to supply the DO high. So, it doesn't have to be 5V, but I do have it around there.


There were some examples of PWM using a counter, but if I recall (I don't have labview on hand right now), they used counters as outputs. I don't have an output counter (unless I can use the DO as that...?) So, I was trying to make use of the clock/counter thing internal to the cdaq chassis.
Using the counter as an input, I didn't see how to really use it, since it seems to be used to measure things like periods, frequencies, etc..

(Again, I may not fully understand all of this at present).


So, long story short, I wasn't really sure how to implement the counter for PWM. It seems somehow using a counter would be better. Then for a 50% duty cycle, 1khz signal. I could turn the output high, wait 500us (by counting somehow?) and then turn the output low, etc. Rather than putting it low multiple times, and high multiple times (as is done by my writing of the array) for one period. Perhaps it doesn't matter. I'm not sure. It seems there should be a slightly more efficient way though, but the examples didn't seem to address my situation exactly.

 

Now I am working on the next part of my program. A while loop running simultaneously will measure voltage values (at 1kHz). Based on these values, the duty cycle will changed every second. If I get it working, I may just move ahead with it. However, I'd still be interested in any suggestions to make my above posted program better.

 

Take care,

Thomas 

0 Kudos
Message 4 of 7
(6,774 Views)
Solution
Accepted by topic author untitledtrack

Hi Thomas,

 

You can definitely do pulse train generation with a counter using your 9474 in a cDAQ-9172 chassis.  Make sure the module is in slot 5 or 6 (newer chassis do not have this restriction).  The pulse train examples can be found in the example finder under Hardware Input and Output->DAQmx->Generating Digital Pulses.  The Gen Dig Pulse Train-Continuous.vi example is probably in the neighborhood of what you want.

 

To update the duty cycle on the fly, write the Co.Pulse.DutyCyc channel property after starting the task.

Message 5 of 7
(6,769 Views)

Thanks for your response! You are correct. I do recall seeing slots 5-6 as being special (though I also recall seeing 1-4 as special for something, which is what I was using). This is why I could never make sense of the Gen Dig Pulse Train example. 

Anyhow, after putting in slot 5 it works.

To change the duty cycle while running I did add the change property block, but it would never change. I then used the vi here:

https://decibel.ni.com/content/docs/DOC-2227

which was actually the same thing I tried, with the exception of also having the frequency change (CO.Pulse.Freq). After removing the Co.Pulse.Freq, it stopped working again. I am a bit puzzled by this, but I suppose it isn't too bad. I'll just wire a constant to the Co.Pulse.Freq. 

Thanks again! 

0 Kudos
Message 6 of 7
(6,765 Views)

The cDAQ-9172 chassis is a little restrictive on digital modules.  If you want correlated DIO, which is what you were doing initially, the modules need to be in slots 1-4.  Slots 5-6 are for counters and PFI routing.  All slots, including 7 and 8, can be used for software timed DIO. 

 

Glad you got it working.

0 Kudos
Message 7 of 7
(6,762 Views)