Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

PWM with NI 9264

Solved!
Go to solution

Is it possible to generate a PWM signal at a certain duty cycle with the NI 9264 16 channel analog output module??

 

Thanks,

Robert

0 Kudos
Message 1 of 14
(6,097 Views)

Hi Robert, 

 

You might take a look at this example to see if it does what you are looking for, or if you can modify it to do what you want. I hope this helps. 

 

 

 

 

Best Regards,

Thomas B.
National Instruments
Applications Engineer
0 Kudos
Message 2 of 14
(6,084 Views)

Hi,

 

Just to condense this to one forum topic with all the relevant information, especially for those also interested in Pulse Width Modulation using an analog device, I have copied over TechnicRC's post discussing his application:


@TechnicRC wrote:

Good afternoon,

 

I have an experiment in the works that I was hoping you folks could assist me with!  I am attempting to derive the transfer function of a motor/propeller using the frequency response method.  I have already created a VI that reads all of the outputs of the sensors on the test stand (propeller RPM, Force, and Torque) using the NI 9205 module (attached VI). However now I am attempting to provide the input to the speed controller (takes a 50Hz PWM signal) by using the frequency response sinusoidal input

 

u(t) = A sin (2*pi*freq*time)

 

I am confused as to how I go from this frequency response input to a PWM input at different duty cycles for the ESC (speed controller) using an NI 9264 AO module?  Can anyone provide any assistance or point me in the right direction?

 

My attempt of beginning this input VI can be seen in the attached file (FR.vi)  I am creating this sinusoidal input but am not too sure where to go from here..

 

Your help is much appreciated,

Robert

 

Attachements provided by TechnicRC can be found here.

 

Another good example worth looking at for PWM using an analog output can be found here, has detailed steps on how the VI is actually setup to output the desired signal.

 

-Jake B.

0 Kudos
Message 3 of 14
(6,073 Views)

Both examples provided by you folks turned out to be very helpful, thank you!  I have been doing more reading into the topic of frequency response and have decided to implement a Swept Sine frequency response test with a PWM signal as my input into the system.  I have found a couple excellent Swept Sine vi's and was hoping to implement the one I attached with the PWM vi.  I am a little confused though with regards to one aspect.  I will be sweeping frequencies from 1-10Hz in my frequency reponse test but my PWM signal needs to be sent at 50Hz for it to control the motor.  How do I go from my frequency response input to my PWM output?  I am quite confused about this but I will keep looking into it

 

Thank you,

Robert

Download All
0 Kudos
Message 4 of 14
(6,065 Views)

Hi Robert, 

 

I am not sure I fully understand what you are trying to do. What is your end goal? Are you trying to make the output of your Swept Signal VI the input of your PWM vi?

 

I would be happy to help, but I need you to explain exaclty what you desire to do.

Best Regards,

Thomas B.
National Instruments
Applications Engineer
0 Kudos
Message 5 of 14
(6,031 Views)

Hello Thomas, 

 

Yes I am trying to make the output of my Swept Signal VI as the input of my PWM vi.  I am basically running a frequency response test on my motor/propeller (measuring torque and thrust) and then trying to derive the transfser function of this motor/prop combo.  The motor is controlled via an ESC which takes a regular PWM signal.  If you need any more information let me know.

 

Thanks,

Robert

0 Kudos
Message 6 of 14
(6,026 Views)

Hi Robert, 

 

From what it sounds like, you may not want to input a sine wave for your function. Based on your explanation of your goal, it sounds like you need to simply input a function that varies linearly from 0 to 1 into the duty cycle parameter of the PWM vi you already have. Does that make sense? That would allow you to analyze the motor's response as the duty cycle varies in a consistent manner. Also, it would not make sense to have your duty cycle be negative, as would be the case during half of the period of your sine function. Let me know if this makes sense, or if I am misunderstanding your goal.

 

 

 

 

Best Regards,

Thomas B.
National Instruments
Applications Engineer
0 Kudos
Message 7 of 14
(6,004 Views)

Hello Thomas,

 

Thank you for your response but I actually do not want the duty cycle to vary in a consistent manner, instead I would like to vary it with the swept sine wave frequency.  Neverthless I have figured out how to do this but now I have an issue with the while loop.  It is executing way too slow ( should be running every 20ms, 50Hz for a duration of 2 seconds ) but it is running way slower.  I believe that the DAQmx write block is delaying the entire loop.  Shouldn't it be able to execute faster?

 

Thanks,

Robert

0 Kudos
Message 8 of 14
(5,992 Views)

I found that changing the sample clock rate and samples input on the DAQmx timing has sped up my program considerably but am still unsure as to what these values should be to guarantee a 50Hz refresh rate of the while loop.  Any ideas?  For now I have the sample clock rate set to 2000 and the samples to 50 with faster results

 

Robert

0 Kudos
Message 9 of 14
(5,980 Views)

Hi Robert, 

 

Changing the Rate and Samples inputs will ensure that there are samples to write, but wil not necessarily ensure that the loop executes at consistent 20ms intervals. In fact, there is no way to ensure that it will write at 50Hz exactly without getting and RT system. What rate does it appear to write at now? The Wait.vi that you have in the loop should be the primary contributor to th execution rate of the loop, from what I can see in your program right now. Is the current rate unsatisfactory?

 

 

Best Regards,

Thomas B.
National Instruments
Applications Engineer
0 Kudos
Message 10 of 14
(5,947 Views)