Why does my oscilloscope display a PWM audio waveform like this?
1mon 17d ago by lemmy.dbzer0.com/u/CrackedLinuxISO in askelectronics@discuss.tchncs.de from lemmy.dbzer0.com
Recently acquired my first oscilloscope (Siglent SDS804x HD with license key "hack" applied) and I've been playing around viewing various waveforms with it. I have a simple microcrontroller circuit generating a 900Hz rectified sine wave, and it passes through a capacitor to remove DC bias.
I'm confused about what I'm looking at when I plug it into my scope. It seems like my audio signal is somehow being represented in the "negative space" of these traces. As I change my code (different freq, different wave, etc) the negative space changes to match. What I expected to see was something akin to this image: A series of square-ish pulses of different width.

What I would eventually like to figure a way to demodulate the audio wave and display it on my scope as its own trace, then play around by analyzing it independently of the PWM. I'm sure that somewhere in all the math functions on this scope, there's a way to achieve that, but I haven't found it yet.
Would you share your schematic and microcontroller firmware?
If you are properly implementing a PWM DAC, you will not see the PWM period change in accordance with the frequency of the signal you are generating. The PWM period is set per sample to relate to the amplitude of the sample, and then a series of low-pass filters is used to cut off the upper harmonics and the PWM frequency.
Given the set up you describe, it sounds like you've got the microcontroller side right, but don't have any filtering on the output, other than parasitics of the scope probe. Have you tried a sample-and-hold and zooming in? I bet you'll see the PWM period you are expecting between the edges.
edit: yeah, I'm noticing now you've got the time base on the scope set way too coarse for what you are trying to observe. consider the reciprocal of whatever you've got your PWM frequency set to, and that'll guide you as to how stretched your x-axis should be.
1/(900Hz) = 0.00111 seconds = 1.11 ms for each full sine width. Your time base is 0.5ms and you can fit 5ms width on the screen. If only a 900Hz signal is present, you should see 5ms/1.11ms = 4.5 full sines on your display. However, the signal appears to be much more dense, so there's definitely high frequency contributors. Zoom in on the time axis and see what's going on, with single shots if needed as someone else suggested. Whatever the other contibutors are they are possibly riding on a 900Hz horse, so unfortunately setting it to trigger is tricky. I would move the trigger value up until it stops triggering, then gently lower it until it taps the max of the overall waveform. Then you will just be sampling the sine(90°) locations on your 900Hz. Oh also, just by eyeballing it looks like the waveform envelope has a period of 1.5ms, 1/(0.0015 seconds) = 667Hz. If my eyeballing is bad then it might really be 900. But as someone else said if this is a PWM'd signal what you're seeing could be explained by not filtering out frequencies above the widths it is using.