Generating a square wave from a 555 timer

Inspired by Afrotechmods, I thought I might try experimenting with RC filters and wave generators. I bought a second probe for my scope so I can see the input and output signals at the same time (neat).

Since I don’t have a signal generator, I thought a good start might be to try making a 555-based circuit that generates a square wave to pass into some filters to see what happens. I did wonder about doing this with an Arduino, but that seems like cheating. And it would be good to get into the habit of doing things in hardware when I can, instead of going straight to a microprocessor.

I’ve also wondered before about producing a 50% duty cycle from a 555, which isn’t something I’ve done — an astable always seems to be more one way than the other, and I’m not sure why. From Wikipedia, I learned that the duty cycle is described as a percentage, where the percentage is the time the signal is high. It can therefore be calculated as:

D = a / P

Where D is the duty cycle, a is the time the signal is active, and P is the period of the wave.

To start with I built the 50% duty cycle circuit from the NE555N datasheet. I don’t have any 51K resistors (which sounds like an odd value) so I used a 47K. Perhaps predictably, the resulting wave was not 50%:

R1 = 47K, C1 = 10nF, f = 1.228KHz, a = 0.3ms, p = 0.82ms, d = 0.366

Experimenting with the value of C1 produced the results I would expect. With 4.7nF:

R1 = 47K, C1 = 4.7nF, f = 1.698KHz, a = 0.22ms, p = 0.59ms, d = 0.373

With 4.7 and 10nF in parallel:

R1 = 47K, C1 = 14.7nF, f = 0.708KHz, a = 0.51, p = 1.39ms, d = 0.367

With 100nF:

R1 = 47K, C1 = 100nF, f = 119.3Hz, a = 3.2ms, p = 8.5ms, d = 0.376

As expected, the frequency decreases as the value of C1 increases, and the duty cycle stays constant (ish). Less expectedly, the wave is not particularly square. Here is the 50KHz calibration signal from the scope for comparison:

Scope 50KHz
Scope 50KHz

In any case, one thing at a time. The 50% duty cycle might be caused by not following the instructions from the datasheet, so I strung together a 47K and 4 1K resistors to get to the magic number. With C1 at 10nF:

R1 = 51K, C1 = 10nF, f = 1.439KHz, a = 0.32ms, p = 0.7ms, 0.457

This is much closer to 50%, but also rather less square. Guess: the higher resistance is causing the cap to charge more slowly, leading to that slower ramp-up. Let’s try a 100K and see how that looks:

R1 = 100K, C1 = 10nF, f = 1.202KHz, a = 0.64ms, p = 0.66ms, d = 0.969

Guess not. The edges are now more similar to the ones with lower values for R1. *confused*. Looking back over the earlier pictures, I think that ramp-up/down actually gets a bit worse as C1 increases. Which does make sense if C1 is taking longer to charge. Changing C1 to 100nF does back this up a bit:

R1 = 100K, C1 = 100nF, f = 117.4Hz, a = 6.8ms, p = 7ms, d = 0.971

So I guess it’s some mixture of R1 and C1 that I don’t understand. Gratifyingly, though, those last two pictures show clearly that altering C1 alters the frequency without changing the duty cycle (much), and it looks like that that relationship is linear: multiplying C1 by 10 gave a value of p 10 times greater.

Anyway. I set kept C1 at 100nF, put R1 back to 51K and added two more 1K resistors, bringing the total up to 53K, and that gave me exactly a 50% cycle:

R1 = 53K, C1 = 100nF, f = 1145.5Hz, a = 3.6ms, p = 7.2ms, d = 0.5

Good enough, I think, despite the not-quite-squareness.

I wondered then if the values in the datasheet are correct (which seems likely) and if it’s just the low tolerance on these resistors that’s accounting for the difference. So I measured the actual values of R1 and R2 which were 52.3K and 22.24K respectively. I guess it’s not those then. I swapped out the 555 for a different one in case that was damaged or the tolerances there could make a difference. Nope. The value of C1 doesn’t affect the duty cycle very much, so it’s probably not that. And I can’t measure that. So it’ll have to be a mystery.

Next: adding low- and high-pass RC filters.

1 thought on “Generating a square wave from a 555 timer”

Comments are closed.