Poor Man’s Signal Generator

AD9833I 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.

Signal Generator

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:

4-button control:

  • 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)

tmpFBE4Display all of that on a 128*64 display, put it in a box with nice mini-buttons and there you are. A simple to use, genuinely useful tool for next to nothing.

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.

Facebooktwittergoogle_pluspinterestlinkedin

18 thoughts on “Poor Man’s Signal Generator

  1. If you like those, see what you can get for 7-8 quid on the 'bay and Aliexpress etc...

    Si5351A clock generator breakout board - 8Khz up to 160MHz with I2C control.

    Adafruit also has their version + sample code, although I found it a bit buggy and picked up some better stuff from a different repo on github.

    1. Thanks for that. Well, if you refresh the blog, you'll see I've put the AliExpress link in for that chip - as it has the connectors ready for front panel mounting all for under £7.

      You'll also note I've drastically improved my original offering which now has memory buttons and non-volatile settings.

      I've ordered the clock generator and it should take me very little time to modify this code for the clock generator version.

      Two new dirt-cheap instruments in one day - can't be bad, can it, now all I need is 2 nice-looking metal boxes to go with all of this.

  2. Thanks for that link to the OneButton lib, I've been looking for something like that for a while as doing multi-click / long press detection is kinda tedious. That one is quite slick and will tidy up things quite nicely for a project where I only have space for one button.

  3. How about these 3 toys for about £30 !!
    Amusing to build, and would make nice presents for yourself on Christmas day.
    Once you've made the signal generator, you can check if the others are working!
    As per usual on Xmas day, make sure you have the right batteries (power supply 😉 )
    Ah - them were the days......

    - Signal generator
    XR2206 Function High-Precision Signal Generator Welding Module DIY Kit 1HZ-1MHZ (£5)
    https://www.banggood.com/XR2206-Function-Signal-Generator-DIY-Kit-Sine-Triangle-Square-Output-1HZ-1MHZ-p-1206339.html?rmmds=detail-left-viewhistory&cur_warehouse=CN

    - Oscilloscope (Fitting the case is a bit fiddely though)
    Original JYE Tech DSO138 DIY Digital Oscilloscope Kit SMD Soldered 13803K Version With Housing (£15)
    https://www.banggood.com/DSO138-DIY-Digital-Oscilloscope-Kit-SMD-Soldered-13803K-Version-With-Transparent-Acrylic-Housing-p-1051616.html?cur_warehouse=CN

    - Frequency tester (£6)
    https://www.banggood.com/DIY-Frequency-Tester-1Hz-50MHz-Crystal-Counter-Meter-With-Housing-Kit-p-1063307.html?rmmds=detail-top-buytogether-auto&cur_warehouse=CN

  4. I used these in a lock-in amplifier design over ten years ago, very nice devices. My software engineer grumbled about the complicated process used to set the frequency so I changed the crystal oscillator to 2.684354456MHz (yes, you can order such things) which then allowed the frequency to be simply set in exact 0.01Hz increments. It does, however, limit the maximum frequency you can get, but that wasn't a problem in our application - the audio band.

    1. Actually I'd not thought about it until now but given the ridiculously low price and the fact they are I2c you could do some great audio stuff with these... sadly the one I have does not seem to have address selection which limits the number on a system to... one!

  5. They do a dual one - AD9958, which we eventually used to maintain accurate phase quadrature for the lock-in function. I doubt whether Aliexpress do those for £5.

    Just for reference, if you want to run multiple AD9833's and need accurate relative phases between the outputs, don't try. The chip has an undocumented uncertainty between clock and synch so although they may start in the right phase relationship, they can glitch by a single clock period every now and then. No problem for a single unit, but a disaster when you want two to be exactly 90 degrees different!

  6. I've gone many years without a signal generator and last year I decided to buy a 25Mhz arbitrary waveform generator and it was the best move I've ever done. Testing analog inputs and filtering is a breeze with it. Also great for testing PWM inputs.

    1. In that case, go get some coffee Dave and come back later this afternoon - I'm writing up something that is altogether different - might even be an upscale version of what you're using now? In fact I'm going to take a guess that it IS the 50Mhz version of what you're doing now... go on - tell everyone - you've not told me what model yours is...

      Give me an hour, I'm busy rendering the video. When I'm done, your feedback could be helpful.

        1. Hi Dave, That Siglent model SDG1025 is £290 in the UK currently and the Siglent SDG1062X is £380. I must admit to being tempted by the latter, but I am assessing how much I would use it. As you will be aware its features include a frequency counter too. I'll await developments from Peter.

Leave a Reply

Your email address will not be published. Required fields are marked *