LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

measure PWM duty cycle

Solved!
Go to solution

Hello everyone,

 

I have never done LabVIEW Real time before and have a quite simple question.

 

I know that there is a pulse width measurement vi in the waveform palette and it can be used to measure the PWM's duty cycle and frequency. My question is, is it necessary to use this pulse width measurement vi on a real time platform (compactRIO, compactDAQ etc...) in order for it to work? In order words, can I just use the normal LabVIEW to measure the PWM's duty cycle and frequency?

 

Is there any alternative to measuring the duty cycle and frequency without using the compactRIO or compactDAQ platform? My concern is because I have not done any Real time programming, and the due date is tight and there is not much to invest into learning the real time programming.

 

Just want to know the experience of others who have done this before.

 

Thanks

 

yours sincerely,

hlim

 

 

0 Kudos
Message 1 of 5
(8,175 Views)

Oh there's lots of ways to measure frequency and duty cycle, several of which don't require real time.  As long as the timeing can be precise from some hardware timed measurements. 

 

If you have an analog in, take a buffered read.  This can either be continuous samples, or a finite sampleing at about 10 times the rate you expect to see the signal frequency.  Then you can run it through some threshold code like this one and get frequency and duty cycle.

 

https://forums.ni.com/t5/LabVIEW/Two-Threshold-Analog-to-Digital/td-p/2738762

 

Or if you have a counter input then the read function will actually return what the frequency and duty cycle are.

 

What hardware do you have on hand?  Any of the mid grade mSeries daq cards are going to have buffered AI daq, and most have a few counters.

Message 2 of 5
(8,152 Views)

Hello Hoovahh,

thanks for your input. We do not have any hardware yet. I am trying to come up with a concept/plan for the project. Our project is to create an automatic test system for testing microcontroller chip peripherals (PWM, timer, UART, GPIO etc...)

 

From your comments on using M series DAQ, sound like it can do all those measurements without even using any Real Time programming. I just have to make sure that the DAQ is fast enough for the test signals.

 

yours sincerely,

hlim

0 Kudos
Message 3 of 5
(8,143 Views)
Solution
Accepted by hlim

Oh yeah RT isn't really required for sample DAQ things like that.  If you have a requirement like evaluate every cycle of a PWM, and if the signal drops out then to send some command within the time of one cycle, then you will want RT or FPGA to be able to react deterministically .  But if you are okay with taking a bunch of samples, then evaluating the data after it has been taken then a cheap DAQ card will probably work just fine.

 

Speed can be a concern.  Lets say you have a 1Khz square wave at 50% duty cycle.  If you sample at 2Khz then you should be able to see that the signal is low for one sample, then high for one sample and you can determine the signal is at 50% duty cycle.  But if you have your wave at 10% duty cycle, then most of the time you will see two samples of low, thinking it is 0% duty cycle, but then once in a while you'll get one high and one low and get a 50% reading, neither of which are right.

 

This is why it is recommended you sample at a rate at least 10 times as fast as your input signal.  So if you have a 1Khz signal sample at 10Khz.  Then if your duty cycle is 10% you'll see one sample high and 9 low.  But even this might not be adequate if you need to have more precision in your measurement.  Luckily NI sells hardware both cheap and expensive for this.  The cheapest hardware that might work for you is this:

 

https://www.ni.com/en-us/shop/model/usb-6001.html

or maybe this

https://www.ni.com/en-us/shop/model/usb-6002.html

 

But you're probably going to want to call up NI and describe your situation and they can best recommend the hardware to use if you are unfamiliar with their offerings.  Depending on your situation you might be able to use an Arduino too.  NI has a toolkit where it can take samples and send them back over USB.  The message sent can be the evaluated frequency and duty cycle, but again it is quite limited, and also doesn't have any support from NI from a hardware stand point, they just provide the toolkit.

Message 4 of 5
(8,136 Views)

Hello Hoovahh,

I now understand how PWM duty cycle is measured, and the role of the sampling rate in the measurement. I accept your information as the solution to my question.

 

yours sincerely,

hlim

0 Kudos
Message 5 of 5
(8,095 Views)