Analyzing PWM Period and Duty Cycle without an Oscilloscope
Now that I have an oscilloscope, I’ve been able to learn a lot more about the circuit I’ve been designing for the MC-2100, as well as the MC-2100 itself. However, a lot of people don’t have access to a scope (even one as old and crappy as mine :)). I’ve had an idea for a method of analyzing a PWM signal without a scope for a while now. Last night, I got some time to test my idea and it worked fairly well, so I figured I’d share it here.
The method uses a piezo buzzer and a free android fast fourier transform app. The buzzer is hooked up to the PWM signal to produce a sound, and the FFT app is used to record the output. The piezo element produces a click every time the voltage applied to it changes from LOW to HIGH or HIGH to LOW. Thus, when a PWM signal is applied to the buzzer, one click is produced when the pulse starts, and another when the pulse ends. The simple circuit I used to drive the speaker is shown below. I don’t think there’s anything magic about the resistor value, it was simply within reach on my desk. It just allows the piezo element to discharge, since the circuit I was using to drive the buzzer could only source current, not sink. The resistor would go to +5v if the opposite were true.
I used this FFT app to visualize the waveforms produced by the clicks. The FFT portion of the app isn’t all that useful in this case, as the frequency we’re driving the piezo element is way at the bottom of the audible range. However, this particular app has a waveform display as well, which allows us to see the clicks produced by the buzzer against a time scale. Unfortunately, this app doesn’t have triggering/synchronizing capability like an oscilloscope, so there’s no way to lock the waveform in place on the screen while taking readings. Instead, you can stop the reading, freezing the last measurement on the screen. This should be good enough assuming your signal doesn’t vary with time. Once you’ve recorded a set of pulses, you can compare the spacing to the time scale to get a measurement of the period. Here’s an example screenshot from my phone:
You’ll notice in the above screenshot that there is a small time period and a larger time period. Unfortunately, there’s no way of differentiating between the HIGH and LOW output intervals. You’ll just have to understand your circuit well enough to decide which is which. In this case, the small period was the HIGH cycle, and the large period was LOW.
To get better readings of the data, I exported the screenshots to my computer, and used MS Paint to take some measurements. By hovering the cursor over the peaks and watching the X/Y coordinates in the status bar at the bottom of the window, you can “measure” the spacing between the peaks. By also measuring the time scale and using a little math, you can determine how much time is spent in each part of the cycle. The following image shows three different settings of my MC-2100 driver circuit and their respective measurements, with the corresponding PWM signal added in red.
The first step is to measure the number of pixels in a certain time interval. In this case, I measure 50ms, which equates to 550 pixels. I now have the conversion factor for making other measurements on the waveform. For example, the HIGH portion of the first waveform measures 53 pixels. To find the time, I simply divide by 550 pixels and multiply by 50 ms, resulting in a 4.8 ms pulse duration.
This is a pretty crude method for analyzing a signal, but in the absence of better tools, it appears to be more than adequate. The readings were as expected when compared to the oscilloscope reading, as well as the input requirements of the MC-2100.
I’m sure there are better apps/programs out there for this kind of work, and plenty of variations on the method of taking measurements. Hopefully this gives you some new ideas for finding out what’s going on in your circuits!