During the fun and enjoyment of experimenting with electronics there will come a time when you need a nice 1 Hz oscillator to generate a square-wave signal to drive something in the circuit. On… off… on… off… for all sorts of things. Perhaps a metronome, to drive a TTL clock, blink some LEDs, or for more nefarious purposes. No matter what you need that magic 1 Hz for – there’s a variety of methods to generate it – some more expensive than others – and some more accurate than others.
A few of you may be thinking “pull out the Arduino” and yes, you could knock out a reasonable 1 Hz – however that’s fine for the bench, but wild overkill for embedding a project as a single purpose. So in this article we’ll run through three oscillator methods that can generate a 1 Hz signal (and other frequencies) using methods that vary in cost, accuracy and difficulty – and don’t rely on mains AC. That will be a topic for another day.
Using a 555 timer IC
You can solve this problem quite well for under a dollar with the 555, however the accuracy is going to heavily rely on having the correct values for the passive components. We’ll use the 555 in astable mode, and from a previous article here’s the circuit:
And with a 5V power supply, here’s the result:
As you can see the cycle time isn’t the best, which can be attributed to the tolerance of the resistors and capacitor C1. A method to increase the accuracy would be to add small trimpots in series with the resistors (and reduce their value accordingly by the trimpot value) – then measure the output with a frequency counter (etc). whilst adjusting the trimpots. If you’re curious about not using C2, the result of doing so introduces some noise on the rising edge, for example:
So if you’ve no other option, or have the right values for the passives – the 555 can do the job. Or get yourself a 555 and experiment with it, there’s lots of fun to be had with it.
Using a GPS receiver module
A variety of GPS modules have a one pulse per second output (PPS) and this includes my well-worn EM406A module (as used in the Arduino tutorials):
With a little work you can turn that PPS output into a usable and incredibly accurate source of 1 Hz. As long as your GPS can receive a signal. In fact, this has been demonstrated in the April 2013 edition of Silicon Chip magazine, in their frequency counter timebase project. But I digress.
If you have an EM406A you most likely have the cable and if not, get one to save your sanity as the connector is quite non-standard. If you’re experimenting a breakout board will also be quite convenient, however you can make your own by just chopping off one end of the cable and soldering the required pins – for example:
You will need access to pins 6, 5, 2 and 1. Looking at the socket on the GPS module, they are numbered 6 to 1 from left to right. Pin 6 is the PPS output, 5 is GND, 2 is for 5V and 1 is GND. Both the GNDs need to be connected together.
Before moving forward you’re probably curious about the pulse, and want to see it. Good idea! However the PPS signal is incredibly quick and has an amplitude of about 2.85 V. If you put a DSO on the PPS and GND output, you can see the pulses as shown below:
To find the length of the pulse, we had to really zoom in to a 2 uS timebase:
Wow, that’s small. So a little external circuitry is required to convert that minuscule pulse into something more useful and friendly. We’ll increase the pulse length by using a “pulse stretcher”. To do this we make a monostable timer (“one shot”) with a 555. For around a half-second pulse we’ll use 47k0 for R1 and 10uF for C1. However this triggers on a low signal, so we first pass the PPS signal through a 74HC14 Schmitt inverter – a handy part which turns irregular signals into more sharply defined ones – and also inverts it which can then be used to trigger the monostable. Our circuit:
and here’s the result – the PPS signal is shown with the matching “stretched” signal on the DSO:
So if you’re a stickley for accuracy, or just want something different for portable or battery-powered applications, using the GPS is a relatively simple solution.
Using a Maxim DS1307/DS3232 real-time clock IC
Those of you with a microcontroller bent may have a Maxim DS1307 or DS3232. Apart from being pretty easy to use as a real-time clock, both of them have a programmable square wave output. Connection via your MCU’s I2C bus is quite easy, for example with the DS1307:
Using a DS3232 is equally as simple. We use a pre-built module with a similar schematic. Once you have either of them connected, the code is quite simple. For the DS1307 (bus address 0x68), write 0x07 then 0x11 to the I2C bus – or for the DS3232 (bus address is also 0x68) write 0x0E then 0x00. Finally, let’s see the 1 Hz on the DSO:
Certainly not the cheapest method, however it gives you an excellent level of accuracy without the GPS.
By no means is this list exhaustive, however hopefully it was interesting and useful. If there’s any other methods you’d like to see demonstrated, leave a comment below and we’ll see what’s possible. And if you made it this far – check out my new book “Arduino Workshop” from No Starch Press.
In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.
The post Various 1 Hz Oscillator Methods appeared first on tronixstuff.