Signal Generator AD9833

Introduction: Signal Generator AD9833

A signal generator is a very useful piece of test gear. This one uses an AD9833 module and an Arduino Nano - that's all, not even a PCB. You can optionally add an OLED display. The AD9833 can gererate sine, triangle and square waves from 0.1 Hz to 12.5 MHz - the software in this project is limited to 1Hz to 100kHz.

There have been other Instructables using an Arduino and an AD9833, here and here. This is simpler and can be used as a sweep generator. Sweep generators help test the frequency response of filters, amplifiers and so on. Unlike the other Instructables designs, this does not include an amplifier or amplitude control but you could add them if you wanted.

Step 1: Simplest Signal Generator

For the simplest Signal Generator, you just solder the AD9833 module onto the back of the Arduino Nano. No PCB is needed.

The AD9833 module I chose is similar to this one. I'm not saying that's the best or cheapest supplier but you should buy one that looks like that photo (or the photo above).

The connections between the modules are:

  • grounds connected together
  • D2 = FSync
  • D3 = Clk
  • D4 = Data
  • D6 = Vcc of AD9833

The AD9833 is powered from data pin D6 of the Arduino - the Arduino can supply sufficient current. I've added a 100n decoupling capacitor because I thought I "ought" to but I couldn't see any difference - there is already a decoupling capacitor on the AD9833 module board.

If you were being fancy, you might worry about "analogue ground" vs "digital ground" but if you were being fancy, you'd be spending more than £4.

The simplest Signal Generator is controlled and powered over a USB lead from a PC. The USB emulates a serial port running at 115200bps (8-bits, no parity). The commands are:

  • '0'..'9': shift digit into "min" frequency array
  • 'S': set AD9833 frequency and produce sine wave
  • 'T': set frequency and produce triangle wave
  • 'Q': set frequency and produce square wave
  • 'R': reset the AD9833
  • 'M': copy "min" frequency array into "max" array
  • 'G': sweep from "min" to "max" over 1 second
  • 'H': sweep from "min" to "max" over 5 seconds
  • 'I': sweep from "min" to "max" over 20 seconds

The Arduino program contains two 6-character arrays "min" and "max. If you transmit a digit then it is shifted into the "min" array. If you send an 'S' then the "min" array characters are converted into a longint frequency and sent to the AD9833. So sending the string

002500S

will set the AD9833 output to a 2500Hz sine wave. You must always send all 6 digits. The minimum frequency is 000001 and the maximum frequency is 999999.

If you send an 'M' then the "min" array is copied into the "max" array. If you send an 'H' then the AD9833 repeatedly outputs a gradually increasing frequency over 5 seconds. It starts at "min" frequency and 5 seconds later is at "max" frequency. So

020000M000100SH

sweeps from 100Hz to 20kHz. The frequency change is logarithmic so after 1 second the frequency will be 288Hz, after 2 seconds 833Hz then 2402, 6931 and 20000. The frequency is changed every milliSecond.

The loop stops when the Arduino receives another character so be careful not to send the command followed by carriage-return or line-feed. That extra character would terminate the loop. If you're using the Serial Monitor, there's a box at the bottom right that might say for instance "Both NL & CR" which (I think) sends characters after your command. Set it to "No line ending".

You can download the Windows EXE program below which will send the required commands or you could write your own. The Arduino INO file is also here.

Step 2: Add an OLED

If you add an OLED and two buttons, the signal generator can work alone without a PC.

Those of you who have read my oscilloscope Instructable will recognise the similarity. The AD9833 module can be added to my oscilloscope to produce an "Oscilloscope and Signal Generator in a Matchbox".

The display is a 1.3" OLED running at 3.3V which is controlled by an SH1106 chip via an I2C bus.

Search eBay for 1.3" OLED. I don't want to recommend a particular seller as links quickly go out of date. Choose one that looks like that photo, says "I2C" or "IIC" and has four pins labelled VDD GND SCL SDA. (Some displays seem to have the pins in a different order. Check them. The proper name for the clock of I2C is "SCL" but on eBay the boards can be labelled "SCK" like my one in the photo.)

A fuller description of the OLED library is in my oscilloscope Instructable in Step 8. You should download and install the driver library SimpleSH1106.zip which is in Step 8. (I don't want to upload another copy here and have to maintain two copies.)

The INO file can be downloaded below. The pin numbers used for the OLED are declared around line 70. If you have built my "Oscilloscope and Signal Generator in a Matchbox" and want to test this INO file with it, alternative pin numbers are enabled via a #define.

I've shown a stripboard layout for the circuit. There are two stripboards - one for the Nano and the AD9833 and one for the display. They should form a sandwich. The boards are shown from the component side. Fine flexible wires join the two boards. Attach the boards together with soldered stand-offs. In my diagram, the copper of the stripboard is shown in cyan. Red lines are wire links on the stripboard or flexible wires joining the boards together. I haven't shown the power and "signal" leads.

The AD9833 module is soldered on the copper side of the stripboard - on the opposite side from the Nano. Solder pins onto the copper strips then fit the AD9833 onto them and solder it on.

The display shows either a single frequency or the "min" and "max" frequencies.

There are two pushbuttons: a "Horizontal" button to select a digit of the frequencies and a "Vertical" button to change that digit.

I power the signal generator from the circuit I'm developing - I always have 5V available at my workstation.

Step 3: Using a Two-Line LCD

mausi_mick has redesigned the circuit to use a 2-line LCD and a rotary encoder instead of the OLED and pushbuttons. This Step describes his design. You can see a video of it here.

He has used a LCD1602 with an I2C interface piggyback board (approx £5 total). They are a simple way of connecting a LCD1602 to an Arduino and require only three of the Arduino's pins.

Alternatively, you could use a plain LCD1602 (£2.50) which requires 6 Arduino pins. Here's an Instructable.

He uses a rotary encoder which makes setting the menus much quicker. Turning or clicking the encoder triggers a "Pin-Change-Interrupt".

The menu has two new functions:

  • Changing frequency ( Low and High) from 0 ... 12 MHz
  • Changing delay (from 100µs,200µs,500µs,1ms...1s) (sweep-mode).

The signal gererator currently is powered from a USB-supply but he intends to change that to a Li-ion battery with a boost convertor to give 5V (using a MT3608 SMPS). USB supplies have a lot of noise so the battery will improve the quality of the signal. Of course, a boost convertor might also create noise. Personally, I'd use 4 AA cells or two Li cells and no booster.

The sketch can be downloaded below. A KiCAD PCB layout is available of his GitHub page.

Step 4: Future Developments

Could it be battery powered? Yes, just add a 9V PP3 connected to the RAW pin of the Nano. It typically uses 20mA.

Could it be powered by a single lithium cell? I don't see why not. You should connect the OLED Vdd and its pull-up resistor to the 3.7V battery (I doubt if the 3.3V output of the Arduino would work properly).

A sweep generator is more useful when testing the frequency response of a filter if you can graph amplitude vs frequency. Measuring the amplitude of a signal is tricky - you have to trade off the decay of your envelope detector vs ripple for low frequencies and response time for high frequencies. Having built your amplitude detector, you could feed its output into the ADC of the Arduino of the "Simplest Signal Generator" then send the result, along with the current frequency to the PC.

This page is a useful starting point or search Google for "envelope detector" or "peak detector". In the suggested circuit above, you would set the signal frequency, wait for it to stabilise, set the Arduino A0 pin to output digital low, wait to discharge C, set A0 to input, wait, then measure with the ADC. Let me know how you get on.

3 People Made This Project!

Recommendations

  • Stick It Challenge

    Stick It Challenge
  • Woodworking Contest

    Woodworking Contest
  • Science Fair Challenge

    Science Fair Challenge

47 Comments

0
mausi_mick
mausi_mick

4 months ago

Hi Peter, again a very nice project !
Inspired from your project I made some modification:
on the hardware:
- LCD1602 instead of the small OLED.
- rotary encoder with push-button

on the software:
- Pin-Change-Interrupt for the Encoder and the Push-Button
- instead of Serial.Read() I use the push-button an the encoder
for work off the Commands.
- I have expand the menu with two functions:
- Changing frequency ( Low and High) from 0 ... 12 MHz
- Changing delay (from 100µs,200µs,500µs,1ms...1s) (sweep-mode).

Because of the quick response of the input from encoder and push-button it's easy to change
the input values.

Now the function-generator is very flexible and I hope useful.
.

If You have interest, I can send the code and perhaps a small video video on YouTube.

mausi_mick
-

P1000178.JPG
0
Peter Balch
Peter Balch

Reply 4 months ago

Do you want me to add your design as an extra "step"?

I'll need a schematic, the code, a photo and maybe some text.

Or could you write your own Instructable?

I can't remember if you have my email address. Just google for peterbalch.

0
mausi_mick
mausi_mick

Reply 4 months ago

Ji Peter,

ready to Christmas !
I made a layout with Kicad,

here are the files and pictures:


... and peaceful feast days

Kalle





AD9833_Nano_Schematic_Kicad.gifAD9833_Nano_Board_Kicad.gifAD9833_Nano_PCB_filled_Kicad.gif
0
Peter Balch
Peter Balch

Reply 4 months ago

I have added your design as a new Step. Please let me know if you'd like me to change anything.

Peter

0
mausi_mick
mausi_mick

Reply 4 months ago

High Peter,
You had a lot of work , Thanks !

But I think it is perhaps better and not so much effort for You , if I put all changes and extensions in the github repository.
Now I have modified the encoder (normal ext. ISR PIN2 and Pin3 , and only the push-button with PCI).

I intend to expand the program with a digital precision-current-source
(1 µA ... 4.095 mA step-width 1µA) / (10 µA ...40.95 mA step-width 10µ A ) and some other functions.

Kalle

ConstCurrSource_1µA---4995µA.JPG
0
Peter Balch
Peter Balch

Reply 4 months ago

That's a good way of doing it. Does it run off a battery?

If you want to send me the code, the circuit and a photo, I could add it to the instructable as another Step.

0
mausi_mick
mausi_mick

Reply 4 months ago

At the moment it works on the USB-supply, but I will use a small Lion-Battery and step up to 5V with a MT3608. I hope it has no influence on the signal quality below about 2 MHz.
I have made some changes by the commands:

// 0 'S': start Sine
// 1 'T': start Triangle
// 2 'Q': start Square
// 3 'L': set Freq.-Low
// 4 'H': set Freq.-High
// 5 'F': set Freq.-Low and Freq-High
// 6 'G': start Sweep
// 7 'M': swap Freq. Low <--> High
// 8 'D': set / change Delay sweep
// 9 'W': set / change Nr./Pos. sweep
//10 'R': Reset AD9833

I have a question to 'M' move in Your program:

You copy freq-Low to freq. High, but delete the old High-freq.
Is it right ?
I have change my program and swap Low to High and (old-)High to Low.
So have two frequencies and if I need the other, I can quick
swap.

I can send You the program on this way ?

Karl Ernst Ruessmann

P1000178.JPG
0
Peter Balch
Peter Balch

Reply 4 months ago

Thanks for the files. I'm beginning to write an extra Step.

The schematic is rather small and hard to read. Can you send a bigger one please.

And do you have a photo?

> You copy freq-Low to freq. High, but delete the old High-freq.
Is it right ?

I can't remember how the code works and I'm a bit busy with Christmas just now. Could it be that I am treating the High and Low variables as a queue - if you send N values, the latest two become High and Low?

Peter

0
mausi_mick
mausi_mick

Reply 4 months ago

Hi Peter,
thanks for the quick response on the special day !

I'll send You 3 Pictures (from Kicad) but I can also send the original to Your mail-address like the Arduino sketch ?


AD9833_Nano_PCB_filled_Kicad.gifAD9833_Nano_Board_Kicad.gifAD9833_Nano_Schematic_Kicad.gif
0
digeratilove
digeratilove

7 months ago

wow...simple is the best policy.... you did it.... i want to make this project now...^^

0
satyaprakash patra
satyaprakash patra

Question 10 months ago on Introduction

Can you please help me to generate a Square wave with a 1.7 MHz frequency by that circuit and please tell me what modification may be done in this main programme to generate this wave?

0
Peter Balch
Peter Balch

Answer 10 months ago

The SG_freqSet() function sets the frequency of the output and the type of the wave.

What problem are you having?

0
spacetribe
spacetribe

1 year ago

Hi Peter, and thanks for this.

Sorry if this is a silly question. In the datasheet I fail to see a clear mention of the feature I'm looking for, which is that the frequency register is maintained without power. I mean, it comes with some pre-set frequency so there must be some way to do this .Yet all the tutorials I see put an emphasis on RESET as an essential procedure. What if I just need a specific sine frequency, always, and want the SPI programming inputs disconnected after programming?

Worst case scenario, if a power-up reset-and-programming step is always required, what would be the simplest preliminary-stage component driving such a system? Arduino nano? Or is AD9833 simply not the way to go and some other single component, such as AD9850, is required?

Cheers

0
Peter Balch
Peter Balch

Reply 1 year ago

That's a good question - but I don't know the answer.

The AD9833 datasheet says "When the AD9833 is powered up, the part should be reset" which implies that it doesn't remember its settings.

The AD9850 doc talks about "This shutdown mode prevents excessive current leakage in the dynamic registers of the device" which implies that its registers are dynamic - they don't remember their settings.

Both chips have a shutdown/sleep mode. Could you make the chip sleep when it's not in use - so it would remember its settings when it wakes up? I think the answer is no. The AD9833 takes 0.5mS when in sleep mode - which is huge. I can't see where the AD9850 doc specifies the shutdown current.

> what would be the simplest preliminary-stage component driving such a system?

I think it would have to be a processor of some sort. If it were me, I'd probably use a PIC12Fxxx chip which is about £0.50.

Are you making a product? How big is the production run? It's always a pain having to program chips but you can buy PICs pre-programmed.

Or is this a one-off personal project? In which case, to save time, go with the chip you already know.

> Or is AD9833 simply not the way to go and some other single component, such as AD9850, is required?

What is it used for? What frequency? How accurate must the frequency be? Is it a sine wave or square? How pure a sine wave? There are lots of other ways of generating signals.

Peter

0
spacetribe
spacetribe

Reply 1 year ago

Thanks for the input. It's appreciated. I would love for it to be around the upper limit of what the AD9833 can put out and still get a relatively clean sine. It's for R&D but will be implemented for a product at some point so it would be nice keep the architecture stable. I will look into the chip you mentioned. I'm looking for an easy way to get a stable sine at a set frequency in the 10-20MHz range. It's actually a requirement that is simple enough to have it met as a single component but maybe I'm missing something. I see the Pic12F683 does up to 8MHz. I'll have a look around the Microchip website then.

0
schopra1980
schopra1980

1 year ago

Hello dear,
Thank you for ths simple and effective project. I have a specific requirement. Can you help me?
I want to make a 1-10MHz sweep generator, but I want have a KNOB to vary the frequency, and manual options to select waveform (square or sine).
Can you please guide me here?
Once I find a resonant point say at 7MHz, I want to run it at ONLY this resonant frequency.

0
Peter Balch
Peter Balch

Reply 1 year ago

The easiest way is to have a rotary encoder. If you seach Instructables for "Rotary Encoder Arduino" you find several of projects which will teach you what to do:

https://www.instructables.com/circuits/howto/Rotary+Encoder+Arduino/

So you'll replace the pushbuttons of my design with rotary encoder inputs.

If you look at my INO file, you will see the pins for the buttons defined as BtnHorz and BtnVert. Serach the whole of the INO for BtnHorz and BtnVert.

You'll see that when they're pressed, the functions incSelSG() and incAdjSG() are called. You should call incSelSG() and incAdjSG when the rotary encoders turn.

But you want to increment or decrement depending on which way the encoder is turning. You'll see that I always do the same thing using ++ or --. For instance:

freqSGLo[SelSG]++;
SelSG--;

You should increment or decrement depending on which encoder turns.

> Once I find a resonant point say at 7MHz, I want to run it at ONLY this resonant frequency.

You could store the value in EEPROM so that next time the circuit is switched on, it goes to that frequency. Seach Instructables for "arduino eeprom".

0
ian111carruthers
ian111carruthers

Question 1 year ago on Introduction

Hello, I need to produce a frequency sweep from 1Hz to 80Khz at a rate of 8 times per second, could I use an external programmable clock such as the Si51351 to achieve this?
Kind Regards

0
Peter Balch
Peter Balch

Answer 1 year ago

Do you mean the Si5351? Why is that better than just using the internal timing of the Arduino? What is it you're wanting to achieve?

My Arduino software changes the frequency every millisecond. So 1/8 sec is 125 steps. The sweep is logarithmic so the frequency will increase by about 3.6% every step. Is that resolution good enough? Do you need the sweep continuous rather than discrete?