LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

create pwm signal with mcc usb 2408

Solved!
Go to solution

Dear all,

 

I would like to generate a PWM square wave with modulable frequency and duty cycle out of my usb module MCC usb 2408-2ao.

 

I know thatI could a use while loop with a flat sequence inside to continuosly put on and off a digital output and by changing the duration of the frames of the flat sequence and the time between one and other iteration of the while loop I can vary duty cycles and frequency...but it seems to me a little bit tedious to do.

 

Is there an automatic way to generate customized a PWM signal and send it  to the output of the USB module in Labview?

 

Thanks to all for your help!

0 Kudos
Message 1 of 14
(4,914 Views)

Hi fabbro,

 

does your USB DAQ device support PWM generation?

If so: use it.

If not: generate the PWM signal as you already described it. (You might use DATAFLOW to get rid of the sequence structure…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 14
(4,899 Views)

My USB device does not have PWM generator, it onyl allows you to change digital outputs.

 

I tried to use timed flat sequence structures, but the thing seems to me not working as I analyze the signal with an oscilloscope and the frequency of the square wave generated does not change and not event the duty cycle.

 

Here is the VI attached. Anybody can help me please? I am wondering if it is not a hardware problem...

 

Thanks in advance,

Fabrizio

0 Kudos
Message 3 of 14
(4,877 Views)

Hi fabbro,

 

WTF are you doing with all those local variables? Don't you have wire left? 😄

 

- Do you notice all those coercion dots? They have a purpose - read the LabVIEW help on that topic!

- What values are you using for PWM frequency and duty? Did you check the calculation results? Did you use probes for debugging?

- You know the limitations of the WAIT function? (That's why you have coercion dots in your VI!)

- Why is ther no stop button? Why don't you check the error cluster wire?

 

Your VI could look like this:

check.png

You could use the CompoundMath nicely…

And you also notice the reason why many LabVIEW programmers use a simple subVI for the Wait function with additonal error IO connectors!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 14
(4,865 Views)
Thanks a lot gerd. Your vi surely look more professional, i'try it tomorrow morning.

I use local variables because i want the user to be able to chamge frequency and duty cycle instantaneiusly while the vi is running! I like local variable, i use them often despite all specialists do not advise them.

Btw i checked the probes and the values were ok, this is emwhy i think the problem may be hardware.

As for the coercion dots, i don ´ t lnow what they are and i ´ ll check tomorrow the limitations of the emwaits function!

Thanks for the help. I ´ l' let you know the result
0 Kudos
Message 5 of 14
(4,849 Views)
If you look at Gerd's code, you should immediately see that frequency and duty cycle can be changed by the user and no locals are required. You are heading for trouble by ignoring the advice of people with a bit more experience.
0 Kudos
Message 6 of 14
(4,844 Views)
What sort of values are you using? Since the device is software timed, you can't run very fast. A device from NI, would be limited to something less than 1kHz. This sort of device is really a bad choice for PWM.
0 Kudos
Message 7 of 14
(4,821 Views)

Hi fabbro,

 

I use local variables because i want the user to be able to chamge frequency and duty cycle instantaneiusly while the vi is running!

I don't see any relation between the parts "I use locals" and "because …"

As said before: Don't overuse local variables!

 

I like local variable, i use them often despite all specialists do not advise them.

In my view this translates to "I know I do wrong - but it gets better when I do it all the time!"

 

I don't think I will provide any more help to you when you resist to take advices…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 14
(4,805 Views)

Dear Denis,


I am using the MCC USB 2408 2AO:

 

http://www.mccdaq.com/usb-data-acquisition/USB-2408-Series.aspx

 

I use its digital output to generate the PWM signal...

 

I set a frequency of 20 KHz, I don't see any limitation in the frequency of Digital outputs in the datasheet. 
 
I have updated the VI following the advise of Gerd and go to test in a moment.... I'll get back to you guys! Thanks a lot 

0 Kudos
Message 9 of 14
(4,799 Views)

Hi fabbro,

 

I don't see any limitation in the frequency of Digital outputs in the datasheet. 

Read the user manual, page 28. It's very explicite on DO sample rate limits!

 

I set a frequency of 20 KHz

So you did read the LabVIEW help on the Wait function by now?

You know it's limitations?

You know what kind of input value it expects?

 

Homer says "Doh!" 😄

I say "RTFM"!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 14
(4,795 Views)