WB5UDE 555 timer Square Wave Project

by Jim Glover WB5UDE

Introduction

This is the start of a larger project, which is more like a series of experiments than a formal project. My goal is to learn and exercise some capabilities, not necessarily to end up with any sort of final product at this time. Here's what I plan to eventually accomplish:

Current Setup

Below you can see what I've set up so far. I've built the 555 square wave oscillator. It's putting out a square wave of approximately 943 Hz. I've managed to feed that into my sound card's microphone input, and have a look at it using Audacity running on the Raspberry Pi.

Here's the physical setup:

Here's the waveform as captured by Audacity:

Here's the spectrum analysis provided by Audacity:

What the graph above shows:

The spectral display above is characteristic of a square wave, with lots of energy in the harmonics. The fundamental frequency is around 943 Hz, showing up where the biggest spike occurs, just below the 1 KHz marker on the graph. If this were a pure square wave, all the peaks would be on the odd harmonics (i.e. just below 3, 5, 7, 9 etc. KHz). I'm not producing an actual square wave here (more on that in the final paragraph), so we also see smaller peaks on the even harmonics.

When I begin filtering the square wave into a sine wave, or when I'm evaluating the (approximation of a) sine wave I get from my phase shifting feedback oscillator, the general appearance of a sine wave in the waveform display will give only a first-order approximation. A better clue will be the degree to which the harmonics have been suppressed in the spectrum graph. If I were to succeed in producing a perfect sine wave, the only blip would be at the frequency of the sine wave. So long as there are blips on the harmonics, I'll know there are imperfections in my sine wave. The smaller the harmonic blips are, the closer I'm getting to a pure sine wave.

The reason the RC filtering will be effective at shaping the square wave from my 555 timer into a sine wave is because the RC filter will be a low pass filter, suppressing the energy which is contained in the harmonics. When most of (or hopefully, essentially all of) the energy in the harmonics has been suppressed, what I'll be left with will be a reasonably pure sine wave.

My 555 timer is producing not quite a square wave, but what we call a rectangular wave. A rectangular wave is the same as a square wave in that the signal shifts nearly instantly between minimum and maximum, and is somewhere in between only for the time it takes the 555 to transition from high to low, or low to high (a very short time). A rectangular wave differs from a square wave because the time spent at the minimum level is not perfectly equal to the time spent at the maximum level. My Ra, Rb, and C values were nominally 1K ohms, 100K ohms, and .01 uF. By the book, that would have produced a rectangular wave with a frequency of about 716 Hz, but my components were standard tolerance, with actual values off their marked values. My scope and my eyeball told me that what I actually got was a time at minimum value of .52 milliseconds, and a time at maximum value of .54 milliseconds, for a frequency of about 943 Hz, with a duty cycle of about 51%. "Duty cycle" means the percentage of one complete cycle during which the signal is at the maximum value. A duty cycle of 50% would mean that we have a perfect square wave. Wow--that 1% sure puts a lot of energy in the even harmonics. Clearly, I can tell more accurately how close I am to perfection by observing the harmonic suppression than I can by merely trying to measure the on time and the off time.

UPDATE--Additional thoughts

I've been thinking about that waveform. It differs from what I see on my oscilloscope. On my oscilloscope, it's very nearly a perfect square(/rectangular) wave. The only imperfection I see on the scope is a slight overshoot on the leading edge of the "on" pulses. I'm not sure whether that's really happening, or an imperfection of my scope and/or probe. I'd lean toward an imperfection of the measuring equipment.

Audacity, meanwhile, shows a very ragged rectangular wave, one with substantial wiggles at both the beginning and end of both the "on" pulses, and the "off" periods as well. Additionally, the level sags during each phase of each cycle. No doubt these imperfections are due to the electrical characteristics of the sound card mic input, most notably, the fact that (according to things I've read on the web) there's quite likely a capacitor in series with the input.

After thinking it over, I've realized those imperfections in the waveform audacity sees through the sound card probably have a lot more to do with the presence of the even order harmonics, than does the 51% duty cycle. I could probably confirm this by producing an audio file which has a perfect 51% duty cycle rectangular wave, loading it into audacity, and doing the spectrum analysis on that. I think I'd see a much cleaner spectrum chart.

So, what does this mean? Well, for one thing, it means analyzing waveforms through the mic input of a sound card (a cheap sound card at that) probably has some serious limitations. Some people who want to do these things get themselves a serious hobby grade sound card such as a high end Soundblaster. That's out of the question, due to being poor "bang for the buck." For similar money, I could probably purchase a good used oscilloscope--or pay for its shipping--though probably not both! Perhaps, however, it would be practical to get an inexpensive ADC (analog-to-digital converter) which, with a modicum of supporting circuitry, could interface with the Raspberry Pi to use for higher quality signal input. Meanwhile, I can use the sound card as a good at least second order approximation of what's really happening in my circuits.

I'm working on that audio file. I'll post the results when I have them.

OK; I made that audio file. Here are the results.

(Spoiler: I was surprised.)

Waveform of a software crafted ~51% rectangular wave:

Spectrum analysis of software crafted ~51% rectangular wave:

My thoughts at this point

Scripted square wave results are in!

My latest thoughts

Home