Solved! Go to Solution.
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.
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.
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.
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.
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:
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.
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.