I can’t remember how, but when messing around with scopes and awaiting my new signal generator (more of that in the coming weeks), the AD9833 Programmable Waveform Generator came to my attention. Take a look at this Ebay link. This would you believe is a signal generator. Without those connectors you can purchase the board even more cheaply. So I paid £5, you can get boards at half of that.
How would you like a dirt cheap signal generator with:
- 1hz-12Mhz range
- 4-button operation (6 buttons with 2 memories)
- Sine, Square or Triangle Outputs
- Non-volatile settings
- Audio button feedback
And there’s more. Read on…
So what you are looking at is a low-cost signal generator (in this case with clock output as well as signal output) which runs from 5v and can be programmed by I2c.
So, just out of interest, I went looking for some AD9833 code and I found this. Worth a read as the fellow has some comments about other chips and noise etc… Very pretty. Well, the guy must’ve done something right as my waveform is no-where near that pretty right now – on the other hand I am powering the breadboard mockup from USB – which is really not a good idea and with spaghetti wiring – even worse. I need a metal box but the day is nearing it’s end and I thought you might like what I have up to now.
All I really wanted was some code to program the chip – and I found it, a very short SPI function to set up the frequency and waveform which can be SINE, TRIANGLE or SQUARE.
As for range, this works from 1Hz through to 12Mhz. Now, bear in mind the price before griping about any imperfections.
What this needed was some equally inexpensive display and control hardware around it – and I do cheap very successfully.
So – add to this chip an Arduino Nano rip-off – in other words any small Arduino-type board… usually sub-£2 – an SSD1306 – again around £2 and you have the basics of a tiny, programmable signal generator.
I started writing some code and realised I’d need a debounce routine – then I thought, would it not be nice to have long key press functionality to keep the number of buttons down and hence the cost… WELL!!! This one’s a winner. A lovely little class library for buttons – which allows you to create callbacks for button click and long click for as many buttons as you need.
I already use and actively promote this ascii-only library for the SSD1306. Oh, and I thought a beeper would be nice – but that’s already built into Arduino to no extra code needed there.
and so it was that I ended up with:
- Press for frequency UP (long-press to reset to 1Khz
- Press for frequency DOWN
- Press to cycle frequency change coarseness (1hz, 10hz, 100hz, 1k,10k,100k)
- Press to cycle between SINE, TRIANGLE and SQUARE WAVE
- Audio feedback (button presses)
- optionally 2 memory buttons (long-press to set)
I don’t have a box yet and I need to find 5 suitably neat buttons lying around, so you’ll have to settle for the dog’s breakfast version for now, but trust me – it works a treat with audible feedback for button controls.
The original version using WIRE used 11K of Arduino storage and 500 bytes of RAM but I stripped that out and used a smaller library and now even with all of the new stuff I’ve added like memory buttons and non-volatile storage, it takes 10.5k and 382 bytes of RAM – so I could take this a WHOLE lot further. I’ve enough pins to add far more than 2 memory buttons. Could add at least 4 more.
My friend Peter Oakes suggested this evening half-jokingly that if you put 3 of these together you could make a little mini-synth!!
Anyway, there you are, hope you enjoyed this as much as I enjoyed blowing up a Nano in the process. As you can see in the background, with wires all over the place and powering off USB, the sine wave in the background is rubbish. I expect all that will change when I wire the thing up properly in a box.
I didn’t notice anything about controlling the PWM on that square wave, that would be a nice addition.
The code complete with optional 2 memory buttons – consider it a work in progress – but if you want to have a play, the pins are self-explanatory and the I2c works on A4 and A5
Coming up next: Clock generator version using the S15351A 8Khz to 160Mhz clock generator board.