Author Topic: ATmega 32u4 and AD9833 based function generator  (Read 12671 times)

0 Members and 2 Guests are viewing this topic.

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
ATmega 32u4 and AD9833 based function generator
« on: June 09, 2020, 01:57:33 pm »
Hi All,

I have designed this small function generator loosely based on this article https://www.allaboutcircuits.com/projects/how-to-DIY-waveform-generator-analog-devices-ad9833-ATmega328p/ and I was wondering if someone would look over it with a fresh set of eyes for any blinding errors. I have triple checked it and run the ERC but as this is my first "larger" scale project and I don't fully trust myself (yet) ;D.

Many Thanks,
Gabriel
 

Offline moffy

  • Super Contributor
  • ***
  • Posts: 2094
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #1 on: June 10, 2020, 12:31:45 am »
Looks pretty good except for a few problems:
1. The output of the DDS DAC needs a substantial low pass filter to get rid of the high frequency noise. Look at some of the other DDS data sheets for examples.
2. The LM7322 only has 20MHz GBW when you can be dealing with a signal up to 12.5MHz. You need an opamp with a GBW 5 to 10x that of the LM7322.
3. The 100nf caps on the rotary encoder seem a little large, perhaps 10nf? Not sure about this, you might be correct.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2651
  • Country: us
Re: ATmega 32u4 and AD9833 based function generator
« Reply #2 on: June 10, 2020, 02:26:23 am »
Take a look at another thread with my AD9834 Function Generator:
   Looking for <$50 function generator

A better op-amp on the output would be the LM7171 which has 100mA output current.
However, even the LM7171 will NOT be able to drive a 50Ω load at full voltage. 
Actually, you are not even setting a 50Ω output.

As said, you need at least a small reconstruction filter on the output.
I only did a 2nd one.  But, you may want a sharper roll off.
   Filter design:  https://www-users.cs.york.ac.uk/~fisher/lcfilter/

Also a said, the capacitors on the encoder are too big and you are missing two resistors.
See my design straight from the PEC11 Encoder datasheet.


I would use a higher clock frequency for the AD9833 if you want frequencies above 1MHz.
Never mind, 25MHz is the maximum.
« Last Edit: June 10, 2020, 02:32:01 am by MarkF »
 

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #3 on: June 10, 2020, 02:32:33 am »
Looks pretty good except for a few problems:
1. The output of the DDS DAC needs a substantial low pass filter to get rid of the high frequency noise. Look at some of the other DDS data sheets for examples.
2. The LM7322 only has 20MHz GBW when you can be dealing with a signal up to 12.5MHz. You need an opamp with a GBW 5 to 10x that of the LM7322.
3. The 100nf caps on the rotary encoder seem a little large, perhaps 10nf? Not sure about this, you might be correct.

Thanks for the feedback! I'm not sure about the low pass filter or how to design it, and the datasheet for the AD9833 isn't much help as it doesn't mention it at all.

I tired a quick parametric search for a op-amp that would meet the requirements (+-12V, preferably rail-to-rail and now with the high GBW) and I didn't really find anything. Do you have any recommendations that I could use in place of the LM7322?

I just copied a diagram of the internet for the rotary encoder and used that. I also had a rotary encoder (component without the module) lying around so I tried it out and it works fine... You might be right it might not be optimal.

 
The following users thanked this post: WattsThat

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #4 on: June 10, 2020, 02:55:36 am »
Take a look at another thread with my AD9834 Function Generator:
   Looking for <$50 function generator

A better op-amp on the output would be the LM7171 which has 100mA output current.
However, even the LM7171 will NOT be able to drive a 50Ω load at full voltage. 
Actually, you are not even setting a 50Ω output.

As said, you need at least a small reconstruction filter on the output.
I only did a 2nd one.  But, you may want a sharper roll off.
   Filter design:  https://www-users.cs.york.ac.uk/~fisher/lcfilter/

Also a said, the capacitors on the encoder are too big and you are missing two resistors.
See my design straight from the PEC11 Encoder datasheet.


I would use a higher clock frequency for the AD9833 if you want frequencies above 1MHz.
Never mind, 25MHz is the maximum.

Ok cool, thanks for your reply! I just read your reply now.

As for the op-amp do you have any recommendations that could supply the 600-odd mA required for the 50Ω loading while still having the right GBW and all? Or any good workarounds for it?

I just looked at the link and that looks like it will work for me to calculate the filter. Is there any advantage of having the sharper roll-off. Also, the impedance would be 50Ω and the corner frequency is 12.5MHz, right?

I'll have a look at the encoder datasheet and redraw that section then.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2651
  • Country: us
Re: ATmega 32u4 and AD9833 based function generator
« Reply #5 on: June 10, 2020, 03:30:15 am »
I read somewhere showing how to parallel LM7171 op-amps for more current but can't find it.
Maybe look at through-hole parts for better heat dissipation.
The SOIC-8 part can only go to about 2Vpp into a 50Ω load.

I only did a 2nd order filter.
The AD9834 boards on eBay appear to have a 6th order.
Here is a quick run of a 6th order series filter with the online program:
You may want to play around with standard values to see how it changes.

Remember the square waveform of the AD9833 DDS also will go through the filter.
The filter will round over the edges.  To_filter or Not_to_filter.  That is the question...

1001739-0
« Last Edit: June 10, 2020, 04:07:04 am by MarkF »
 

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #6 on: June 11, 2020, 12:01:24 am »
Ok here is an updated schematic with the filter added along with the updated rotary encoder and also a readback for the switch. I am still struggling to find an appropriate op-amp... I would need to parallel 6 of the LM7171s to get the required 600mA, and I don't really think that is a viable option. Especially as I would need 12 altogether (6 each for the offset and amplitude). Any suggestions or is it just not worth the hassle?

EDIT: I forgot to attach the file oops
« Last Edit: June 11, 2020, 12:27:28 am by Gabriel »
 

Offline glentek

  • Regular Contributor
  • *
  • Posts: 56
Re: ATmega 32u4 and AD9833 based function generator
« Reply #7 on: June 11, 2020, 12:36:11 am »
Itead had a similar unit for sale 10 years ago - I bought one but really never got around to using it. Have a look, might give you some ideas.
https://www.itead.cc/blog/iemp-dds-signal-generator-in-stock-and-data-release
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2651
  • Country: us
Re: ATmega 32u4 and AD9833 based function generator
« Reply #8 on: June 11, 2020, 02:16:21 am »
Ok here is an updated schematic with the filter added along with the updated rotary encoder and also a readback for the switch. I am still struggling to find an appropriate op-amp... I would need to parallel 6 of the LM7171s to get the required 600mA, and I don't really think that is a viable option. Especially as I would need 12 altogether (6 each for the offset and amplitude). Any suggestions or is it just not worth the hassle?

EDIT: I forgot to attach the file oops

Almost there:

   Encoder:  The capacitors are in the wrong place.

   

   Output filter:  R2 from the design tool is your 50Ω load.
                        Basically, you have it backwards.

   
« Last Edit: June 11, 2020, 02:20:01 am by MarkF »
 

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #9 on: June 11, 2020, 02:28:29 am »
Ok my bad, I corrected both errors.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2651
  • Country: us
Re: ATmega 32u4 and AD9833 based function generator
« Reply #10 on: June 11, 2020, 02:34:37 am »
One enhancement that you may be interested in having is a frequency sweep.

You can do this by having the Atmega update the AD9833's frequency from an interrupt.
With a fixed interrupt, you calculate a delta freq. per update and a sweep period.
At the end of the sweep period, you reset the AD9833 freq. back to the initial value and start sweeping again.
With a positive delta you can sweep up and with a negative delta you can sweep down.
It works very well with not much math.

I also generated a "start_of_sweep" pulse with an unused I/O pin for a trigger.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2651
  • Country: us
Re: ATmega 32u4 and AD9833 based function generator
« Reply #11 on: June 11, 2020, 02:41:24 am »
A second nice_to_have is a PWM output.

You can do this with a second unused I/O pin on the Atmega.
You should buffer this output to another output connector. 
  (I would not merge it into the AD9833 output.)

Food for thought before you have a PCB made.

All this starts to add up code-wise and how efficient you coding skills are.
I used a graphical display which burnt up a lot of my program space.
 

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #12 on: June 11, 2020, 02:59:55 am »
These definitely feature that I may add, even if I don't end up coding it in it is still nice to have on the PCB for future expansion. I also plan to implement SCPI at least to a basic level (hence the 32u4 for the USB). I am using a standard 20x4 LCD so I am doing fine. The code currently takes up 8920 bytes (of 28672) without any optimisation and TBH my code is a bit of a mess...
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2651
  • Country: us
Re: ATmega 32u4 and AD9833 based function generator
« Reply #13 on: June 11, 2020, 03:14:37 am »
These definitely feature that I may add, even if I don't end up coding it in it is still nice to have on the PCB for future expansion. I also plan to implement SCPI at least to a basic level (hence the 32u4 for the USB). I am using a standard 20x4 LCD so I am doing fine. The code currently takes up 8920 bytes (of 28672) without any optimisation and TBH my code is a bit of a mess...

Just for comparison, I used 32621 of 32768 bytes in my PIC18F2550.
 

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #14 on: June 11, 2020, 03:21:04 am »
Oh wow, good job!  :clap:
I still have plenty more to write so we'll see how I go  :-\
 

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #15 on: June 13, 2020, 08:17:33 am »
Ok, I have looked further into the op-amp question. The only ones that I can really find that would suit all the requirements are xDSL interface op-amps. Here is the selection chart from AD: https://www.analog.com/en/parametricsearch/11070#/d=5002|2687|4502|300|4501|4101|4500|4108|2839|2840|s3|s5&p5002=600m|2&p4502=100M|4G&p2840=24|220&p2687=|2

The only issue with these is that I have found them extremely hard to source and where I could find them they are very expensive, somewhere over AUD$20 ($13 Yankee bucks)...
I am starting to consider whether it is worth trying to get another op-amp with more current or if I should just stick to the current one (LM7171 as suggested by MarkF).

Anyway, apart from that dilemma I think I can move onto making the PCB for it. I have implemented a pin for the sweep trigger and the PWM just as headers on the board just in case I need it. Thanks for the idea Mark!
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2651
  • Country: us
Re: ATmega 32u4 and AD9833 based function generator
« Reply #16 on: June 13, 2020, 03:35:04 pm »
Which ever op-amp you go with, it might be worth considering a through hole part simply because they are bigger with better heat dissipation.  There are ones with a thermal pad in the center but difficult (if not impossible) to hand solder.

1002830-0
 

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #17 on: June 14, 2020, 12:44:24 am »
Here is the 3rd version of the schematic, now with the PWM, sweep trigger and the opamps swapped to the LM7171s. I decided it isn't worth the huge extra cost to get the high current op-amps.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2651
  • Country: us
Re: ATmega 32u4 and AD9833 based function generator
« Reply #18 on: June 14, 2020, 01:56:11 am »
Your filter on the output is still NOT correct.
The LC components are reversed left-to-right.

Without checking the ATmega 32u4, the pin used for PWM is capable of a PWM output?
In the PIC, only certain pins can do PWM.
 

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #19 on: June 14, 2020, 02:17:45 am »
Aghh, I thought I already reversed it, but guess not then. Fixed it up.

As for the 32u4 I double-checked witch pins I could use and used one that is PWM capable so that I all good!
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2651
  • Country: us
Re: ATmega 32u4 and AD9833 based function generator
« Reply #20 on: June 14, 2020, 02:23:58 am »
Inspired by a video by Alan Wolke, I built his Time Domain Reflectometer (TDR) to generate really fast edges.
I used four outputs with 200Ω resistors for a 50Ω output impedance.
You might be interested in using the 74AC14 as a buffer/driver for you PWM pin.

1002959-0

 

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #21 on: June 16, 2020, 12:34:26 am »
Sorry, I somehow missed your reply!

I think that will have to be a separate project, I think it should be fine as it is.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2651
  • Country: us
Re: ATmega 32u4 and AD9833 based function generator
« Reply #22 on: June 16, 2020, 01:43:40 am »
Requirements creep!    :palm:

You don't want to drive an external signal with your processor.
I made the mistake of not buffering my digital output and
now use a BNC coupler to that little PCB as a buffer.

If you think you might want it, I recommend adding the footprints now.


1004736-0

Edit:  Updated drawing to eliminate PWM signal overall inversion.
« Last Edit: June 19, 2020, 09:18:32 am by MarkF »
 

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1460
  • Country: us
Re: ATmega 32u4 and AD9833 based function generator
« Reply #23 on: June 18, 2020, 01:42:41 pm »
One enhancement that you may be interested in having is a frequency sweep.
Sweep is great, make sure that it does both linear and logarithmic sweeps.

It works very well with not much math.
Mmm, it takes a wee bit more math. >:D
 

Offline GabrielTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: au
Re: ATmega 32u4 and AD9833 based function generator
« Reply #24 on: June 18, 2020, 11:06:03 pm »
Ok, I might just add it in then, it will be just easier like that. It's also pretty cheap (AUD$0.45) that's not a problem.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf