I am measuring a PWM signal with NI hardware. If the PWM I am reading is not a good signal I want to have the full wave of that signal so I can log the raw data for analysis later. For this reason I am using an analog input channel and not a digital channel. I will read the AI channel for some amount of time, then post process the data detecting the Frequency, Duty Cycle, Amplitude, and Mean of the signal. If any of these are outside the expected tolerance we log it.
For a while I was using the canned NI function Pulse Measurements. This returns the period (frequency can be figured out easily) and duty cycle. The issue I have with this function, is I have to blindly trust it. And if a single cycle of my PWM fails then this function will not be able to detect that issue.
So I wrote my own frequency and duty cycle measurement code which is slower then the NI solution, but I can perform a standard deviation on the high times and low times, and detect the integrity of the signal. Attached is my test VI. It has two waveforms that are simulated but you can also use it with real DAQ channels too. Run the VI with the Simulated Data Index set to 0 and it will use a wave that has a single cycle of the PWM held high. My Manual Method can detect this and the "Signal Condition Good" will be red, but the NI method doesn't have any way to tell me the signal was not consistent. Setting the Simulated Data Index to 1 tests it with a good signal that is consistent.
My question is this. Is there an easier way to detect the integrity of a square wave PWM? A method that can determine if the signal has had a cycle where the PWM stopped working?
There’s little confidence on my part in the existence of some prebuilt function that will achieve this. With that being mentioned, I did search and ask around to see if there’s something out there that comes close. Someone directed me to this example located in the forums here…
(be sure to get the data.txt posted in this forum to get the final build graph.vi to run correctly)
…that uses the Threshold Detector.vi. Other than what you’ve done so far, and what is seen in this other example, you may be faced with continuing doing it from scratch. There’s another possible starting point here.
Using an Analog Input for an Edge Count or Encoder Task Using DAQmx
Thanks for the links but I'm not sure they are much help. The first link is finding spikes by looking at how quickly the value changes. I expect a PWM to change value quickly and quite often, my issue is detecting when a change doesn't occur when it should.
The second link is basically what I am doing already but in a much less effiecient (and less standard) way. They have each value of the N samples go into a for loop where they have all the controls in the loop. This must slow down the loop rate alot having to read the value of the controls over and over. It is also doing value thresholding that it could do in a single primative as an array instead of a scalar. Wires also were going backwards.
I see where you're coming from, but as mentioned, the only example found wasn't too far away from the path you're already on. When you state "detect the integrity of a square wave PWM"my interpretation is waveform characterization and/or comparison (PWM or not). Have you come up with anything more?
Attached is an image of the example VI that I attached in my first post. Look at the waveform and you'll see what I mean. If I asked you what the frequency of that signal you would right away know that something was wrong with the signal. But any Frequency calculating function will just blindly try to perform an FFT (or something similar) to find the dominent frequency. My intend of this post was to see if there was a built in way to detect this type of signal issue or if my method I wrote was the right way.
I suggest a time domain approach. Define the maximum time without a transition as your drop out criterion. Then two shift registers and some comparators will find the dropouts.
It has been a long time since this question was posted, but I think is an interesting topic.
One possible solution is to confirm pulse by pulse. This can be done matematically with time data arrays.
Other option I had been using is "Pulse measurements.vi": inside a loop and getting the PWM of each pulse as an array. Each array value can be validated to have a certain value or range.
I have been trying to figure out how to detect PWM fadings, if someone knows an algorithm for it, it can be very helpful.
It has been a while and since this post I've been generally using the technique I first mentioned. It's been tweaked over the years, with a two level threshold two find the indexes of transition, then looking at the mean times between the number of samples from a low, to a high. Then look at the standard deviation of these values and if it is too high then a drop out occured.
This basically can calculate the frequency of every transition, and a fading error could be detected too, but at the moment I'm not sure mine would catch that the way it is now. I suspect this method is much faster than using the Pulse Measurements which is relativly slow, but robust and flexible.
Thanks for the two level threshold link, I will keep it for later review.
For PWM variations (fade), I did an algorithmn like the one you mention with statistical values, mean value and std deviation, but then I opted to do it with the PWM array derivative and looking for patterns:
PWM is increasing, decreasing or fixed value.
But I have not compared the execution time of both options.