LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW pwm signal generation

Hello everyone. I am wondering if it possible when generating pwm signal with a DAQ card, to program specific number of pwm periods with specific duty cycle ? For example, 30% duty cycle - 5 periods, then 31% duty cycle 5 periods and so on ? Thank you  

0 Kudos
Message 1 of 11
(501 Views)

Hi,

 

you could make it like this?

Generate Multiple Channels of Digital Output with Different Frequencies and Duty Cycles - NI Communi...

 

But you must count the samples you send and change the dutycycle after.

 

Or you generate your own signal and and write for example all 100ms 100 samples of it and watch, if your signal 30%DC is writting 5 times. After that you create the data to 31%DC. I made it like this for best control and so I can generate/send any arbitrary signals.

 

At the end you have to monitor how many cycles you have already written and then change the data to send.

0 Kudos
Message 2 of 11
(457 Views)

This would be easier to implement with a counter output task *IF* you have a device that supports buffered counter output.  Examples are X-series MIO devices and most cDAQ chassis released in the last decade or so. 

 

The example linked in the other reply was written up a year or two before any such devices were available.  It's also a viable method, I just find the counter approach more straightforward on devices that support buffered pulse train generation.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 3 of 11
(453 Views)

thank you so much. Do you have by any chance some examples how to do it ? because i have no idea where to start

0 Kudos
Message 4 of 11
(445 Views)

thank you so much for your reply

0 Kudos
Message 5 of 11
(444 Views)

Hi,

 

I started with a counter-version, but for example my cDAQ-9178 only has 3 internal counter available.  

So please check before, how many signals you have to write...

0 Kudos
Message 6 of 11
(437 Views)

Something like that I think:

 

Generate a Continuous Digital Pulse Train With On The Fly Frequency Control - NI

 

But change the node from freqency  to high-low-ticks.

0 Kudos
Message 7 of 11
(436 Views)

I'd recommend you use the shipping example "Counter (Buffered) - Continuous Output" as a starting point.   You can edit the array of high and low times to achieve the varying PWM you want.  The next step might be to provide a more flexible method to define the PWM array, but the example should be enough to get you started as-is.

 

Note that for this continuous task, the pulse param samples will regenerate -- so when you get to the end of the array of pulse params, it'll start back over from the beginning.  Repeatedly until you stop.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 8 of 11
(429 Views)

Hi. Thank you for the example that you have provided. I have a few questions, because I am bit confused and don't have much experience. I want to use that example but I don't understand some stuff. For example, I am using PXIDAQ card 6361, so when i need to configure Channel parameters and Sample clock Source, I just choose the corresponding pins but I don't need

daq_pinout.png

to connect it physically if I just want to see how the code works? Like I choose any pins that correspond to clock from this list?

Sorry for such basic questions and thank you 

0 Kudos
Message 9 of 11
(394 Views)

No apologies needed for a "basic" question -- when it's new, it's a vast sea of information and the route to the part that's needed isn't obvious.

 

The upper part of your linked diagram shows the mapping from the physical pin # to its more functional designation.  So you see things like Digital Ground, PFI #'s, digital port.line designations, AI channel designations, etc.

 

The lower part of your diagram shows the *default* connections set up internally to route signals between the external PFI pins and the internal counter terminals.  But your X-series device is very flexible, allowing many PFI terminals to be used interchangeably for a variety of timing-related signals such as clocks and triggers.  To see even more about this, select your 6361 device in the MAX configuration tool and then choose the "Device Routes" tab at the bottom of the window.

 

There you'll see a big matrix of allowable routings between external pins and internal functional signals.  (Older devices gave a more limited set of allowable routings.)

 

So you have lots of options and choices available when you want or need them.  DAQmx has a number of ways for you to configure counter tasks to route their internal signals to non-default external PFI pins.  But you don't *have* to use them.  When you don't, DAQmx will use the default connection routing shown in the bottom part of the diagram you posted.

 

And yes, you can run the code even if you don't physically connect any of the signals to anything.

 

Here's a tip though -- open up one of the *other* Counter Input shipping examples that measures frequency or duty cycle.  Configure that to do its measurement on the PFI pin where your first example is generating PWM.  This can help you see that the PWM task is working correctly.  And you never need to do any physical wire & screwdriver work.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
Message 10 of 11
(382 Views)