Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Generating a single channel digital waveform for NI9403 with configurable duty cycle and frequency.

Solved!
Go to solution
I am trying to generate a digital output with a user controlled duty cycle and (accurate) frequency.  I am using an NI9403 DIO module and DAQmx functions but have been unable to perform this seemingly trivial task.  Any help is much appreciated.
0 Kudos
Message 1 of 24
(9,860 Views)
Solution
Accepted by 5thGen

Hello 5thGen,

Thank you for posting on the NI Discussion Forums.  Unfortunately, the 9403 is a static DIO module, and so its updates are done through software.  This means that the card’s output can only be updated by writing to it through software.  This does not mean that you can’t create a waveform with a very accurate frequency, but it does mean that you will have to periodically update this waveform in software, if you wish to have the user control the frequency and duty cycle.  For instance, you can generate 100 samples at a time of the waveform in software, and continuously write a fresh set of 100 samples to the device to output.  See the attached VI (assuming you are using LabVIEW) for an example of what this may look like.  (If you want to run it, be sure to open the DAQ Assistant and change the physical channel to the device on your machine).

If you want to generate a more phase-continuous PWM signal (and not have a software-updated waveform) you will have to get a new piece of hardware.  As I mentioned at the beginning of this post, the 9403 is a static DIO module, which means that it cannot output a hardware-timed waveform (i.e. a  hardware-generated pulse train).  In order to have a hardware-generated pulse train, you must obtain a DIO module that has correlated DIO.  For a list of these CompactDAQ modules that can do this, check out KnowledgeBase 3UN91NB9: C Series Modules Supported in the NI cDAQ-9172 CompactDAQ.   Using one of the Correlated DIO modules, you can create a Counter Output » Pulse Generation » Frequency task.  One example of such a task is a shipping example for DAQmx, called “Gen Dig Pulse Train-Continuous.vi” (From LabVIEW, Help » Find Examples, and on the Browse tab, Hardware Input and Output » DAQmx » Digital Generation).   If you want the user to have the ability to change the Duty Cycle and Frequency of the waveform while the application is running, then you must use a DAQmx Chanel Property Node (In the functions palette under Measurement I/O » NI-DAQmx) to access the Duty Cycle and Frequency properties (Counter Output » Pulse » Frequency on the property node).  You can update this property within the while loop of the VI so that it gets updated on each iteration of the loop.  The modified example would look something like the attached image.

 

Sorry for the novel. Hopefully this will get you started with your PWM application!

 

Chris_G
Sr Test Engineer
Medtronic, Inc.
Download All
Message 2 of 24
(9,847 Views)

Thank you for your response Chris_G. I opened the code you provided but was unable to run it using the Express Blocks.  It gave me the following error:

        Measurements: Selected lines do not support buffered operations.

        Ensure only lines that support buffered operations are being used in

        the task. If using change detection, the task must be changed to

        non-buffered hardware timed single point to support these lines.

 

However, I was able to create a usable app with individual blocks (generate square wave, DAQmx write, etc) but my output is much, much slower than the frequency I am setting it to (using a control knob).  Would the code you provided give a more accurate output?  Do you have a suggestion as to how to fix the error?  I have researched the device (NI 9403) but have found nothing on buffered operations.   Again, thank you for your help and any future assistance you may be able to provide.

 

 

-Stephen

0 Kudos
Message 3 of 24
(9,822 Views)

Stephen,

 

I apologize for sending you a VI that you cannot use with your hardware.  Unfortunately, you cannot output a digital waveform with a device that does not have correlated DIO, and the only option you have is 1 Sample (On Demand) for your output.  The timing will be all random in this mode, since a Windows OS is non-deterministic.  Unfortunately, there is no good way to go about this with the hardware that you have.  I would recommend using a CDAQ module that has correlated DIO. 

 

If you want to just control the output of a signal in a loop, you can use the timing functions to control loop execution speed.  This will be innaccurate, but may suffice for what you are trying to do.

Chris_G
Sr Test Engineer
Medtronic, Inc.
0 Kudos
Message 4 of 24
(9,797 Views)

Chris this question is for you. 

 

I am a newbie to labview.  With that said I have been reading and trying to get some examples and I came across your example that I think might help me.  

 

I need to be able to control a stepper motor via digital output.

 

I am using the USB 6009 DAQ (I know it does not ahve a hardware counter) so I am looking for software timed programming. (I know this isnt the most reliable but this is the DAQ I have to work with, no choice).

 

I am using a pulsewidth modulated drive (1microstep = 1 pulse). If I send it 2kHz it will go one revolution per second at 10uSteps on a 200 step motor. 

 

I have 4 wires from the driver to the DAQ (Disable, Direction, Step, Common).  The step inputs max rated frequency is 300hz with a 50% duty cyclewaveform. 

 

Could your idea for frequency and duty cycle work with my example?

 

 

I want to be able to set speed and time and let it run.  

 

 

I started a little but may be you could point me in a proper direction.  

  

 

I have attached a possible start...perhaps you could advise me a little.  

 

 

Using the DAQ assistant means I do not have to use DAQmx (read, write, etc), correct?

 

 

Thank you for all your help and guidance.

 

Jerry

0 Kudos
Message 5 of 24
(9,377 Views)
sorry I forgot to attach the program
0 Kudos
Message 6 of 24
(9,376 Views)
sorry I forgot to attach the program
Download All
0 Kudos
Message 7 of 24
(9,375 Views)

Hi JSC81,

It looks like you definitely have a start to what may work for your application.  Some things to consider though:

1.       Most motors that are controlled by PWM actually vary their speed based on the duty cycle that they see from the PWM signal (0% duty cycle being the lowest speed, and 100% being the highest speed).  Your VI seems to suggest that the motor speed is determined by how fast the While Loop Runs

 

LoopSpeed.jpg

 

Maybe I am missing something with your particular motor, but from my experience, this will not change the behavior of the motor speed, since it has no effect on the duty cycle of the output signal.  The duty cycle is only effected by the Duty Cycle input to the Simulate Signal Express VI. 

 

2.       If for some reason the frequency of the output signal actually does have an effect on the motor speed, the rate of the While Loop will still not directly effect the frequency of the output signal.  The frequency of the output signal is completely determined by the Frequency input to your Simulate Signal Express VI.  Beware when changing this though, as you can end up outputting a signal that is not phase-continuous between loops.  What I mean by that is, during one iteration of the loop, you output a phase-continuous square wave, but it may not have a finite number of periods (say 1.75).  If that occurs, then the next iteration of the loop will begin a new square wave, and introduce a phase discontinuity in your PWM signal:

 

PhaseDis.jpg

 

3.       If you wish to control the frequency of the signal by the rate of the while loop, do not generate a waveform in your DO task, but rather just do an update every time by writing just a ‘1’ or a ‘0’ on every iteration of the loop.

The best way to confirm what I am saying is to just take a look at the signal you are outputting, and try different things out to see what results they produce.  You have analog input channels right on the 6009 that you can see what the signals look like with.  Try it out!

Chris_G
Sr Test Engineer
Medtronic, Inc.
0 Kudos
Message 8 of 24
(9,351 Views)

Chris,

Thanks for the reply...my computer wenta little crazy and posted the same reply a couple times.  Sorry about that.

 

If my driver has a max step output of 300hz at 50% duty cycle then I will not be able to go higher then that...correct?

 

Also,

 

I am still trying to learn how to properly code this so I could have to motor run as smoothly as possible.

 

 

Some questions for you and if you want you could just write the number next to your reply and I will understand what question you are replying to.

 

1. If I remove the waituntilnext clock then I will have a duty cycle and frequency input and output into the DAQ, correct?

 

2. So by changing the duty cycle and leaving the frequency constant I should be able to increase or decrease the speed of the motor and keep the phase continuous , correct?

 

3. If my driver has a max step output at 300hz and 50% duty cycle, I will not get any better output if I go higher...correct?

 

 

 

4. If I kepted my code in a while loop then I will continuously output the duty cycle and frequency to the DAQ until I hit STOP, correct?

 

5. To control the direction can I have a boolean switch connected to an array and this outputing into another DAQ assistant to a separate channel or is there a better way to accomplish this?

 

6. Is there a way for simplicity to easily convert duty cycle and frequency to speed control such as steps/sec?

 

Can I figure out how many pulses (or usteps) it moves at a given frequency and duty cycles and make a conversion to steps/sec and then have this be my controller?

 

 

Thanks so much for this guidance.  Hopefully, you understand my questions.

 

Jerry

   

0 Kudos
Message 9 of 24
(9,347 Views)

 Chris, this is a continuation from the last message. 

 

I tried to set up my DAQ assistant to output a digital signal.  I am using USB-6009 (no hardware timer).

 

When I choose Digital Out and then I select the physical channel it pops me up to the window where I choose my sampling/timing/etc.

 

In this application where I want to run the motor until I say stop I think I would want continuous sampling (sampling until I press stop), correct?  However, when I choose this feature and in Timing I choose external and select the device and choose okay I get an error. 

This is the error I received:

 

Error - 200077 occured at DAQ Assistant

Measurments requested value is not a supported value for this property.

 

Property : Samp Timing Type

You have requested : Sample Clock

You can select: On Demand.

 

I am not sure how to set up my DAQ to output the frequency and duty cycle to the driver.  

 

Any thoughts?

 

0 Kudos
Message 10 of 24
(9,325 Views)