06-05-2013 04:51 PM
Hello folks,
I have a NI 9205 module and was wondering if there was a way to measure the duty cycle of a PWM signal that I am generating with a separate microcontroller? I have found a lot of examples with Digital inputs but not analog.. Is this possible?
Thank you,
Bob
06-05-2013 05:16 PM
Sure it is possible, providing you can sample fast enough. What frequency is your PWM signal? To accurately see its shape (and therefore the duty cycle), I think you need to sample about 10x the frequency of the digital waveform.
I have attached some code that shows the principle. We generate an analogue waveform and then measures its duty cycle.
06-05-2013 05:25 PM - edited 06-05-2013 05:35 PM
Possible is exactly what I like to hear. The PWM signal is being generated by an ESC therefore its frequency is most likely 50Hz. I will be measuring these signals at 5kHz and have tried imitating your VI but am still experiencing problems with generating this duty cycle value. Attached is the simple VI I am trying to use. Any ideas??
Thank you,
Bob
06-06-2013 06:42 AM
The express VI you have used outputs the LabVIEW dynamic data type. Since the dynamic data type can hold a number of waveforms and not just one, the Pulse Measurement VI has changed itself to deal with a number of waveforms. This means the duty cycle output is an array; duty cycles for every single waveform in the dynamic data type (even though you only have one).
You can use the Convert from Dynamic Data Type VI to explicitly define what the dynamic data is. See the VI attached.
06-06-2013 10:42 AM
Thank you for the help Lewis, however I get an error when I try to run the VI.
The following shows up:
Error -20308 occurred at "NI_MAPro.lvlib:Pulse Measurements 1 chan.vi:1" when called from "PMW input.vi"
Possible reason(s):
Analysis: The waveform did not cross the mid reference level enough times to perform this measurement. Check the signal length, reference levels, and ref level units.
Any ideas??
Thanks,
Bob
06-06-2013 11:00 AM - edited 06-06-2013 11:10 AM
I feel like the waveform coming into the DAQ is definitely not the pwm signal outputted from my device. I put the pwm signal under a scope and it was what I expected it to be but all I get from the DAQ is a constant slow sine wave. I connected the PWM signal button to the AI0 pin and ground to the COM. Is this correct?
Honestly I don't think this is a Voltage Input but I am not sure which option to select for this.. I tried pulse width counter input but but there were no physical devices found so I couldn't select that option. Image attached.
Thanks,
Robert
06-07-2013 05:29 PM
Hi Robert,
I'm not sure what that error is, try searching for it.
If you want to measure a PWM signal you would usually use a counter input. A counter is a dedicated piece of hardware that is used to measure digital signals. Since the NI 9205 is an analogue device and it doesn't have any counters onboard, you will not be able to select counter input.
I would recommend you get the right tools for the job and buy a digital acquisition device with an onboard counter. It will make reading PWM much easier for you. The NI 6008 has a counter onboard and is only £99. It will also offload processing from software to hardware since you don't have to calculate duty cycle.
If you still want to use analogue post back and we can look into why its not working for you. Tips to start you off: Voltage is the correct setting and Look in the manual and make sure you have connected it like you have configured it (differential, RSE, NRSE page 14)
06-08-2013 07:40 PM - edited 06-08-2013 07:40 PM
Thank you for the reply Lewis, I was really considering purchasing the right hardware for the job and might but am still interested in making this work with the hardware I have now if possible.
So I do have the DAQ measuring voltage as a Referenced Single-Ended (RSE) Measurements (connection is correct). However the only ouput I get from the DAQ on Analog input pin 0 (I have tried different pins with the same result) is a sine wave with a period of about 1 sec. I have the PWM output also connected to ground COM on the DAQ. I have tested the PWM signal on an oscilliscope and it is outputting correctly therefore my device is in fact generating a PWM signal but the DAQ is not reading it. I have set the sample time to 5kHz and 1k samples, min voltage 0 and max voltage 5. I am very lost now because I have tried everything that I can and have looked at a bunch of resources online... Any ideas? I can always post a step by step by step procedure with screenshots if necessary.
Thank you,
Robert
06-08-2013 08:30 PM
Please post some of your data. Run your VI. Stop it with some PWM waveform (or whatever you are getting) showing on the chart. From the Edit menu select Make Current Values Default. Then Save (or Save As.. with a different name). Post that VI.
When you do that, we can see what you are seeing and can actually manipulate your data to find out what is going on even without having your hardware.
I suspect that you either have a connection problem or are not sampling fast enough.
Lynn
06-08-2013 09:48 PM
Are you able to post your scope screenshot? Seems like you do have a capable hardware for measuring duty cycle of a 50Hz signal. From one of your posts that your DAQ doesn't see signal cross reference point, it sounds like either a wrong DAQ setting or wrong signal conditioning... Are you probing input of your DAQ module with a scope when a PWM signal is being injected into the DAQ and that signal on the scope is within 0 ~ +5volts?
-DP
BatchTest Corp.
NI Alliance Partner