Author Topic: DIY Function Generator  (Read 57975 times)

0 Members and 1 Guest are viewing this topic.

Offline perfect_disturbanceTopic starter

  • Regular Contributor
  • *
  • Posts: 144
  • Country: us
DIY Function Generator
« on: September 27, 2012, 03:19:53 pm »
OK So I want to try and build a function gen i see there's a couple different ways to go with advantages and disadvantages.

Some people are using dedicated function gen chips like a MAX038 or XR2206 these actually seem pretty straigtforward but both of those chips are no longer in production.
and the only one I could flnd with a listed price on mouser was 80 bucks (which seems unreasonable hi so I may be looking at the wrong part)

http://www.mouser.com/ProductDetail/Exar/XR2206-11-12EB/?qs=sGAEpiMZZMs%252bwIVMMV7AyT%252ba%252bM0aLAJO

The other consept seems to be using a microcontroller (I'd probably use an atmega328) to directly synthesize the signal.  to do this I would need some sort of dac I've seen some people getting by with r/2r networks like this

http://www.mouser.com/ProductDetail/Murata/RGSD8L102G/?qs=sGAEpiMZZMvrmc6UYKmaNYgyMGTqqrwcgSLMHCLOy9Y%3d

I thought I could also use a dac ic but I'm not sure what part would work well for that.  I'd like something I could wire directly to the microcontroller (preferably parallel) with out a lot of other components.

What do people think?
« Last Edit: September 27, 2012, 03:34:05 pm by perfect_disturbance »
 

Offline M0BSW

  • Frequent Contributor
  • **
  • Posts: 673
  • Country: 00
  • Left this site 2013, they will not delete it ????
Re: DIY Function Generator
« Reply #1 on: September 27, 2012, 03:32:00 pm »
Hope you get plenty of replies , because Im looking for a winter project , and this sounds really interesting.
Paul
no one would or will tell me how to delete this account
 

Offline madires

  • Super Contributor
  • ***
  • Posts: 7769
  • Country: de
  • A qualified hobbyist ;)
Re: DIY Function Generator
« Reply #2 on: September 27, 2012, 04:30:37 pm »
Some people are using dedicated function gen chips like a MAX038 or XR2206 these actually seem pretty straigtforward but both of those chips are no longer in production.
and the only one I could flnd with a listed price on mouser was 80 bucks (which seems unreasonable hi so I may be looking at the wrong part)

25 years ago all EE magazines were full of XR2206 circuits :-) Just checked Reichelt, XR 2206CP for EUR 5,20, on stock. Has anyone tested the cheap MCU based DDS signal generators from ebay?
 

Offline kripton2035

  • Super Contributor
  • ***
  • Posts: 2588
  • Country: fr
    • kripton2035 schematics repository
Re: DIY Function Generator
« Reply #3 on: September 27, 2012, 04:56:31 pm »
here is the open source AVR DDS signal generator V2.0
http://www.scienceprog.com/avr-dds-signal-generator-v20/
 

Offline kripton2035

  • Super Contributor
  • ***
  • Posts: 2588
  • Country: fr
    • kripton2035 schematics repository
Re: DIY Function Generator
« Reply #4 on: September 27, 2012, 04:59:18 pm »
 

Offline T4P

  • Super Contributor
  • ***
  • Posts: 3697
  • Country: sg
    • T4P
Re: DIY Function Generator
« Reply #5 on: September 27, 2012, 05:42:34 pm »
max038 on ebay around $15 free shipping...
http://www.ebay.com/sch/i.html?_trksid=p3984.m570.l1313&_nkw=max038&_sacat=0

xr2206 less than $3 on ebay...free shipping too
http://www.ebay.com/sch/i.html?_nkw=xr2206&_sacat=0&_odkw=max038&_osacat=0
XR2206 and the MAX038 is old and done for, inaccurate and runs very hot + power hungry
 

Offline crispus

  • Regular Contributor
  • *
  • Posts: 134
  • Country: ro
Re: DIY Function Generator
« Reply #6 on: September 27, 2012, 06:04:17 pm »
What is the alternative to those old chips?
I know I'm numskull, but I look around me and I feel better.
 

Offline T4P

  • Super Contributor
  • ***
  • Posts: 3697
  • Country: sg
    • T4P
Re: DIY Function Generator
« Reply #7 on: September 27, 2012, 06:36:06 pm »
What is the alternative to those old chips?
DDS! AD98XX series
 

Online AndyC_772

  • Super Contributor
  • ***
  • Posts: 4228
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: DIY Function Generator
« Reply #8 on: September 27, 2012, 06:44:43 pm »
If you wanted, you could do it with a microcontroller, dual port RAM and a DAC. The microcontroller writes a pattern of data corresponding to a sine, square or any other type of wave into one port of the RAM, while on the other port, a programmable counter reads the data out at a predefined rate and presents it to the DAC.

Arguably the best way to implement the counter and RAM would be to use an FPGA; depends how steep a learning curve you're in the mood for, unless you've used them before.

Online PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5129
  • Country: nl
Re: DIY Function Generator
« Reply #9 on: September 27, 2012, 06:54:34 pm »
Or old school: an EPROM (remember those?) with R/2R on the data lines, a counter on a number of address lines and the other address lines to select the waveform  :)
Keyboard error: Press F1 to continue.
 

Offline kripton2035

  • Super Contributor
  • ***
  • Posts: 2588
  • Country: fr
    • kripton2035 schematics repository
Re: DIY Function Generator
« Reply #10 on: September 27, 2012, 07:00:34 pm »
Or old school: an EPROM (remember those?) with R/2R on the data lines, a counter on a number of address lines and the other address lines to select the waveform  :)
typically what's inside a dds chip isn't it ?

I bought this on ebay :
http://www.ebay.com/itm/-/170682095715?item=170682095715
a microcontroller, a display and voila...
« Last Edit: September 27, 2012, 07:02:49 pm by kripton2035 »
 

Online PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5129
  • Country: nl
Re: DIY Function Generator
« Reply #11 on: September 27, 2012, 07:12:27 pm »
typically what's inside a dds chip isn't it ?

Of course, but the EPROM FG can be build on a breadboard on a rainy sunday afternoon.  ;)
Also, you can put sine, square, triangle and such in it very simple.
Keyboard error: Press F1 to continue.
 

Offline G7PSK

  • Super Contributor
  • ***
  • Posts: 3861
  • Country: gb
  • It is hot until proved not.
Re: DIY Function Generator
« Reply #12 on: September 27, 2012, 08:31:35 pm »
 

Offline jerry507

  • Regular Contributor
  • *
  • Posts: 247
Re: DIY Function Generator
« Reply #13 on: September 27, 2012, 09:10:14 pm »
As T4P said, just get a dds. Unless the frequency you want is really low or you want insanely high quality outputs, it's the easiest solution and it'll give you some good experience designing relatively high frequency circuits.
 

Offline M0BSW

  • Frequent Contributor
  • **
  • Posts: 673
  • Country: 00
  • Left this site 2013, they will not delete it ????
Re: DIY Function Generator
« Reply #14 on: September 28, 2012, 07:43:06 pm »
Or old school: an EPROM (remember those?) with R/2R on the data lines, a counter on a number of address lines and the other address lines to select the waveform  :)
typically what's inside a dds chip isn't it ?

I bought this on ebay :
http://www.ebay.com/itm/-/170682095715?item=170682095715
a microcontroller, a display and voila...

So will this you'd just put a display with it some bnc sockets a box, and you have a function generator  !!!!!!!

no one would or will tell me how to delete this account
 

Online Smokey

  • Super Contributor
  • ***
  • Posts: 2597
  • Country: us
  • Not An Expert
Re: DIY Function Generator
« Reply #15 on: September 28, 2012, 08:09:21 pm »
I have that same DDS board from ebay.  It's amazing what you can get for 6 bucks USD.  The chip itself in 1s is like 15bucks USD.  I already built a motherboard for it with uC, control pots, and +/-12V regulator from +5V input.  Going to level shift the DDS output so it's centered around 0V and amplitude scale from there.  Still need to write the code though.  Should be a killer little USB controlled function gen.

Those DDS chips are pretty much just a DAC, but the magic happens with the internal filtering and PLL stuff from what I can tell.  The data sheets are super dense with info.  Generating a nice sine wave is way harder than it appears.
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: DIY Function Generator
« Reply #16 on: September 28, 2012, 10:07:21 pm »
Unless the frequency you want is really low

so what would be the solution for 0-20khz for sine and square if not a conventional dds chip but still digitally controllable?
 

Online Smokey

  • Super Contributor
  • ***
  • Posts: 2597
  • Country: us
  • Not An Expert
Re: DIY Function Generator
« Reply #17 on: September 28, 2012, 10:22:33 pm »
They make these DDSs for different applications.  Check out the part matrix at the bottom of the page:
http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/products/index.html
The really fast ones are usually for clock generation, so they have parts that go up into the GHz.  There are other ones specifically for function gen applications, like the AD9833, that has a frequency output from 0MHz to 12.5Mhz at 0.1Hz steps and outputs sine, square, and triangle wave via software settings.  They really are versatile chips.

Here is a really interesting use of the AD9833 DDS.
http://electronicdesign.com/article/analog-and-mixed-signal/turn-dds-chip-into-low-frequency-arbitrary-signal-generator

(edit to add)
For only 20khz you can just hook a DAC up to a uC and step through a sine table.  20khz square wave is easy.
« Last Edit: September 28, 2012, 10:26:00 pm by Smokey »
 

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 3719
  • Country: us
Re: DIY Function Generator
« Reply #18 on: September 28, 2012, 11:06:13 pm »
Those analog devices function generator chips are nice, but they aren't very flexible.  They can definitely do your basic sin, triangle, square wave, but if you want a nice set of modulation, sweep, burst, and triggering options you have to implement that by manually adjusting the tuning word. 

If I were designing a lab function generator I would use an FPGA with an external DAC.
 

Offline grenert

  • Frequent Contributor
  • **
  • Posts: 448
Re: DIY Function Generator
« Reply #19 on: September 29, 2012, 05:53:32 pm »
If you're interested in going the one-chip route, Jameco sells a kit (no enclosure) based on the XR2206:
https://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_20685_-1

They also have the bare chip for $6.49:
https://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_34972_-1

Velleman makes a complete kit that is based on a PIC:
https://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_2137262_-1
 

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 3719
  • Country: us
Re: DIY Function Generator
« Reply #20 on: September 30, 2012, 08:31:36 pm »
so what would be the solution for 0-20khz for sine and square if not a conventional dds chip but still digitally controllable?

The problem with using a conventional DDS for low frequency is that you can really see the stair-stepping with a typical 10 bit DAC.  If you know you are only going to go to 20 kHz you can just change the output filter cutoff, but it is better to use a high resolution DAC or use an FPGA+DAC and apply dither and noise shaping.
 

Offline jerry507

  • Regular Contributor
  • *
  • Posts: 247
Re: DIY Function Generator
« Reply #21 on: October 01, 2012, 04:45:02 pm »
I am always very skeptical of advising people to go with an FPGA for a project if learning to use the FPGA isn't the point. Perhaps this is bias from when I got my butt kicked by an FPGA in college, but it seems like just learning the FPGA can derail the original intent.

That said, wanting to build a function generator or similar test equipment is rarely about building the test equipment and more about learning whatever technology you want to use to build it. So the OP should look at his options:

1. FPGA w/ DAC
2. Microcontroller w/ DAC
3. DDS chip with perhaps some switchable output filters to clean up excessive stairstepping
4. A fully analog solution

Pick a path and then go down that one, so you're focused and have a real goal.
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11653
  • Country: my
  • reassessing directives...
Re: DIY Function Generator
« Reply #22 on: October 01, 2012, 05:23:44 pm »
or switchable among all 1-4? as in "audiophoolery" anything other than 4 is not tolerated? stairstepping will produce highly unwanted harmonics noise.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline perfect_disturbanceTopic starter

  • Regular Contributor
  • *
  • Posts: 144
  • Country: us
Re: DIY Function Generator
« Reply #23 on: October 02, 2012, 05:06:12 pm »
OK so I m interested in the AVR DDS I was looking at some of the schematics and had a couple questions.

first I noticed in the power supply that after each of the regulators there are 2 caps a 100 and a .01 (I'm assuming uF).  In most reference designs I'v seen there is only a .1 cap after the regulator what is the 100 in this on for? Filtering lower frequency noise? Adapting to rapid changes in current drawn buy the rest of the circuit?



Next question is about the resistor network would I be better off buying resistor network or building my own?

Thanks
 

Offline poptones

  • Frequent Contributor
  • **
  • Posts: 709
  • Country: 00
Re: DIY Function Generator
« Reply #24 on: October 02, 2012, 06:57:53 pm »
You should not get bad stairstepping with "conventional dds" if you use linear interpolation. It's not that hard.

If your goal is to make an audio frequency function gen buy a low cost audio i2c DAC and drive it from a microcontroller. Feed it 48ksamples/sec and the built in 8x oversampling feature will take care of a lot of it.

Another way, if you just want sines, is to use a mux as a 3 bit dac and a switched capacitor filter. I built one of these years ago and it works pretty well. And you can get all the parts sampled from maxim.

 

Offline T4P

  • Super Contributor
  • ***
  • Posts: 3697
  • Country: sg
    • T4P
Re: DIY Function Generator
« Reply #25 on: October 03, 2012, 08:04:38 pm »
Improve high frequency filtering.
 

Offline poptones

  • Frequent Contributor
  • **
  • Posts: 709
  • Country: 00
Re: DIY Function Generator
« Reply #26 on: October 04, 2012, 04:11:02 am »
On the above circuit? It's a 6 pole filter and you can change the cutoff frequency. 1st harmonic is going to be some 25db down, by the time you get to 8th it's just noise.
 

Offline ptricks

  • Frequent Contributor
  • **
  • Posts: 671
  • Country: us
Re: DIY Function Generator
« Reply #27 on: October 04, 2012, 07:32:57 pm »
If you haven't seen it, microchip have a new pic that could greatly reduce the parts needed for a function generator, all you would need is a quality DAC.
The pic16f1508 has a numerically controlled oscillator , perfect for generating precise waveforms, configurable logic so you can make your own hardware gates for combining waveforms or triggering, and a complimentary waveform generator.

http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en553471
 

Offline poptones

  • Frequent Contributor
  • **
  • Posts: 709
  • Country: 00
Re: DIY Function Generator
« Reply #28 on: October 04, 2012, 08:48:02 pm »
It has a built in DAC but it is only 5 bits. It would be alright for RF but would suck as an audio gen unless you paired it up with something like the above switched cap 6 pole programmable filter.

The two together might make a good combo, but only for sines. If you try to generate a 1KHz square but you're filtering from 1KHz it's not going to be much of a square wave.

I could not find anything about getting the NCO accumulator signals off the chip via serial.
 

Offline ziplock9000

  • Regular Contributor
  • *
  • Posts: 173
  • Country: gb
Re: DIY Function Generator
« Reply #29 on: January 13, 2017, 09:43:01 pm »
Any updates to this 5 years later? Are there better modules these days as I've outgrown my extremely basic generator?
 

Offline asgard20032

  • Regular Contributor
  • *
  • Posts: 184
Re: DIY Function Generator
« Reply #30 on: January 14, 2017, 07:44:42 am »
It has a built in DAC but it is only 5 bits. It would be alright for RF

Not sure about that. For RF, we need good quality signal. If not, all the harmonic would cause havoc on on neighbor band... FCC...
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14210
  • Country: de
Re: DIY Function Generator
« Reply #31 on: January 14, 2017, 08:02:27 am »
The cheap DDS modules you get en Ebay are still essentially the same: AD9850 based with not so well working filter. This gives a reasonable good quality sine up to maybe 20 MHz. You still need amplitude scaling and output amplifier.
 

Offline pandy

  • Contributor
  • Posts: 14
  • Country: 00
Re: DIY Function Generator
« Reply #32 on: January 14, 2017, 01:31:51 pm »
Any updates to this 5 years later? Are there better modules these days as I've outgrown my extremely basic generator?

You can build your own discrete TTL based DDS - use as a reference design from http://www.epanorama.net/sff/Test_equipment/Generators/Digital%20Sine%20Wave%20Synthesizer.pdf, however nowadays with fast uC available i would rather replace discrete  NCO by software and move RAM LUT to separate IC's (there is plenty asynchronous fast SRAM chips - bigger - better), add to this fast DAC and you may have arbitrary waveform generator.
 
The following users thanked this post: ziplock9000

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: DIY Function Generator
« Reply #33 on: January 14, 2017, 02:19:46 pm »
(..)however nowadays with fast uC available i would rather replace discrete  NCO by software and move RAM LUT to separate IC's (there is plenty asynchronous fast SRAM chips - bigger - better), add to this fast DAC and you may have arbitrary waveform generator.
That was the route I took.
I use STM32 microcontroller (STM32L-Discovery) as an arbitrary signal generator.
The uC comes with two 12-bit DACs that can go up to ~2Msps each (with external op-amp for gain and offset) so this is a double-channel generator. It is capable of generating 20-point sin(x) at 100kHz on each channel. Can be started externally or it can trigger a scope (good for sweeping frequency).

The nice thing is that such signal generator does not use CPU at all so it does not really matter how fast a uC is clocked (32MHz is ok). I just initialize timers and DMA and let it run in background.
 
The following users thanked this post: ziplock9000

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: DIY Function Generator
« Reply #34 on: January 14, 2017, 08:36:01 pm »
I built a DDS with an AD9834, a PIC18F2550 and a small OLED display. It has sine, triangle, square, sweep up and sweep down outputs (although the square wave output is on a different pin). There is adjustable amplitude and DC offset.

The MCU is under the display as shown on the board section to the right.

   
« Last Edit: June 11, 2019, 05:57:30 am by MarkF »
 

Offline AlxDroidDev

  • Frequent Contributor
  • **
  • Posts: 471
  • Country: br
    • Arduino Web Brasil
Re: DIY Function Generator
« Reply #35 on: January 14, 2017, 08:49:49 pm »
What about the ISL5314 ?

I know it is an expensive IC, but would it fit in a project controlled by a STM32 ?
"The nice thing about standards is that you have so many to choose from." (Andrew S. Tanenbaum)
 

Offline Vtile

  • Super Contributor
  • ***
  • Posts: 1144
  • Country: fi
  • Ingineer
Re: DIY Function Generator
« Reply #36 on: January 14, 2017, 09:51:56 pm »
Then there is the OPA route and Discrete route.   :-/O

These cheap arbitrary gens are interesting, I wonder do they suffer from extreme distortion in high frequenzies with full voltage swing as my function generator that is part of my USB oscilloscope (from known oldish brand).

Old 555 chip can handle the function gen duties for as first "function gen".

 

Online Smokey

  • Super Contributor
  • ***
  • Posts: 2597
  • Country: us
  • Not An Expert
Re: DIY Function Generator
« Reply #37 on: January 15, 2017, 02:18:17 am »
One thing to watch out for with cheap arbs is the PC software to create the waveforms.  Cheap hardware often comes with cheap damn near unusable software.
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14210
  • Country: de
Re: DIY Function Generator
« Reply #38 on: January 15, 2017, 10:24:53 am »
Those cheap Chinese function generators often use an FPGA and cheap DAC to provide DDS and arb function. In principle this is very viable and the good ones do it the same way. The problem is more the low DAC quality - often just a few resistors to do R2R: this is limited speed and accuracy (e.g. 6-8 Bit). Also the filter is usually not what is should be for a good DDS.

The other point is the performance of the output stage - so slew rate limits appear at higher amplitude.
 

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: DIY Function Generator
« Reply #39 on: January 15, 2017, 11:36:59 am »
I built a DDS with an AD9834, a PIC18F2550 and a small OLED display.
I wanted to tie STM32L to USB and make some GUI for uploading ROM table and tweaking frequency on-the-fly but due to lack of time I prepare that data offline and just flash a uC.
 

Offline ziplock9000

  • Regular Contributor
  • *
  • Posts: 173
  • Country: gb
Re: DIY Function Generator
« Reply #40 on: January 15, 2017, 10:58:34 pm »
(..)however nowadays with fast uC available i would rather replace discrete  NCO by software and move RAM LUT to separate IC's (there is plenty asynchronous fast SRAM chips - bigger - better), add to this fast DAC and you may have arbitrary waveform generator.
That was the route I took.
I use STM32 microcontroller (STM32L-Discovery) as an arbitrary signal generator.
The uC comes with two 12-bit DACs that can go up to ~2Msps each (with external op-amp for gain and offset) so this is a double-channel generator. It is capable of generating 20-point sin(x) at 100kHz on each channel. Can be started externally or it can trigger a scope (good for sweeping frequency).

The nice thing is that such signal generator does not use CPU at all so it does not really matter how fast a uC is clocked (32MHz is ok). I just initialize timers and DMA and let it run in background.

Any chance you can share your design mate? Did you use external RAM to buffer the waveform or just generate it real-time?
I might do something similar with an arduino although with that I'd need an external DAC.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: DIY Function Generator
« Reply #41 on: January 16, 2017, 12:23:51 am »
I built a DDS with an AD9834, a PIC18F2550 and a small OLED display.
I wanted to tie STM32L to USB and make some GUI for uploading ROM table and tweaking frequency on-the-fly but due to lack of time I prepare that data offline and just flash a uC.
I started trying to build an arbitrary generator but quickly found that the frequencies that I could generate was very limited by the update rate I could achieve for the DAC.  100KHz in your case .  My range is limited to 1Hz to 1Mhz because I only used a 32MHz clock for the AD9834.  A DAC with a SPI interface would be even more limiting.
 

Offline Vtile

  • Super Contributor
  • ***
  • Posts: 1144
  • Country: fi
  • Ingineer
Re: DIY Function Generator
« Reply #42 on: January 16, 2017, 12:43:17 am »
I kind of return to my previous post... It would be actually interesting to build a function gen from operational amplifiers. I IIRC have seen many old OPA741 based ones floating around.. How good one of those design would be with more modern high stability, high linearity and high speed chips. Hmm... Anyone tried out or can daveCAD the idea as nonsense. The math behind the OPAs should be pretty much the same as in 1968 when 741 did pop out.
 

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: DIY Function Generator
« Reply #43 on: January 16, 2017, 08:39:12 am »
I started trying to build an arbitrary generator but quickly found that the frequencies that I could generate was very limited by the update rate I could achieve for the DAC.  100KHz in your case .  My range is limited to 1Hz to 1Mhz because I only used a 32MHz clock for the AD9834.  A DAC with a SPI interface would be even more limiting.
You cannot generate an arbitrary function with AD9834 at 32Msps as that would require 32MHz*8bit = 256Mbaud SPI! This chip can go that fast only by using internal memory (sine, square and triangle IIRC, + kind of sweep) so no arbitrary.
Arbitrary function generator has to be able to generate absolutely any programmable shape one can imagine. With that  AD you are limited to the SPI speed (<3 MB/s for a PIC18F2550 at ~100% cpu load) so in theory you could reach 3Msps and 8-bit resolution max (IMHO).


Quote
Any chance you can share your design mate? Did you use external RAM to buffer the waveform or just generate it real-time? I might do something similar with an arduino although with that I'd need an external DAC.
Sure. I'll try to include whole Eclipse project into a zip and attach here later (end of the week).
I am not sure how you are going to port that to arduino as it relies solely on the hardware available. I just fill registers (DAC, two TIMs, DMA and GPIO) with config data and press "start", CPU load is exactly 0%. This uC has similar peripherals to popular STM32F103RC if you necessarily need to port that to something else.

I did not have to use any external memory because STM32L152RB has 128kiB of internal flash. Even sampling 2Msps there is enough storage for 128k points (1 x 8bit) or 32k points (2 x 12bit) if you need that much. And there is still 16kiB room in SRAM for an application, if one ever needed such.


« Last Edit: January 16, 2017, 09:17:11 am by Brutte »
 
The following users thanked this post: ziplock9000

Offline ziplock9000

  • Regular Contributor
  • *
  • Posts: 173
  • Country: gb
Re: DIY Function Generator
« Reply #44 on: January 16, 2017, 08:00:37 pm »
Thanks.
I might have a look around to see if there's a DAC + RAM module for the Arduino rather than going with a different uC architecture for the moment. I'd have the Arduino algorithmically populate the RAM and then output it via the DAC.

Complete noob question here.
Does using a uC->RAM->DAC avoid most (or all) of the filtering issues compared to using a real-time DDS+Crystal?
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14210
  • Country: de
Re: DIY Function Generator
« Reply #45 on: January 16, 2017, 08:28:02 pm »
Using a µC, RAM and DAC is rather similar to a DDS chip. So you should have analog filtering in both cases.

The external RAM can be a little faster than using an µC internal sine table. So this way the AVR (Arduino) might get you up to maybe 3.5 MSPS and thus maybe 1.2 MHz with a good reconstruction filter. Having the the sine table in the AVR limits the speed to about 2 MSPS and thus about 700 kHz usable sine frequency. So if you want to go cheap and soft, one could leave out the RAM. One might need a second µC for the user interface, as the µC would be busy all the time, when doing DDS in software.

Since the ready made DDS modules are not that expensive (slightly over 10 EUR / $10) - they are really attractive, as they include the clock and the filter (not really good, but also not that bad and definitely better than no filter). The AD9850 is also way more powerful than you get with µC, RAM and 8 bit DAC, as it includes a 10 Bit DAC and usually uses a 125 MHz clock.
 

Offline ziplock9000

  • Regular Contributor
  • *
  • Posts: 173
  • Country: gb
Re: DIY Function Generator
« Reply #46 on: January 16, 2017, 09:10:45 pm »
Using a µC, RAM and DAC is rather similar to a DDS chip. So you should have analog filtering in both cases.

The external RAM can be a little faster than using an µC internal sine table. So this way the AVR (Arduino) might get you up to maybe 3.5 MSPS and thus maybe 1.2 MHz with a good reconstruction filter. Having the the sine table in the AVR limits the speed to about 2 MSPS and thus about 700 kHz usable sine frequency. So if you want to go cheap and soft, one could leave out the RAM. One might need a second µC for the user interface, as the µC would be busy all the time, when doing DDS in software.

Since the ready made DDS modules are not that expensive (slightly over 10 EUR / $10) - they are really attractive, as they include the clock and the filter (not really good, but also not that bad and definitely better than no filter). The AD9850 is also way more powerful than you get with µC, RAM and 8 bit DAC, as it includes a 10 Bit DAC and usually uses a 125 MHz clock.
Thing is I'd be using this not just for sine waves but as an arbitrary function generator. I'm from a Software Engineer background so I'd write some nice front end software for the Arduino and PC to drive it with a nice GUI. So are you saying that external RAM would not be sufficient for waveforms beyond 3.5MPS?
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: DIY Function Generator
« Reply #47 on: January 16, 2017, 09:25:42 pm »
Using a µC, RAM and DAC is rather similar to a DDS chip. So you should have analog filtering in both cases.

The external RAM can be a little faster than using an µC internal sine table. So this way the AVR (Arduino) might get you up to maybe 3.5 MSPS and thus maybe 1.2 MHz with a good reconstruction filter. Having the the sine table in the AVR limits the speed to about 2 MSPS and thus about 700 kHz usable sine frequency. So if you want to go cheap and soft, one could leave out the RAM. One might need a second µC for the user interface, as the µC would be busy all the time, when doing DDS in software.

Since the ready made DDS modules are not that expensive (slightly over 10 EUR / $10) - they are really attractive, as they include the clock and the filter (not really good, but also not that bad and definitely better than no filter). The AD9850 is also way more powerful than you get with µC, RAM and 8 bit DAC, as it includes a 10 Bit DAC and usually uses a 125 MHz clock.

This dual CPU approach (AVRs) is exactly what is done with the FG085

http://cdn.sparkfun.com/datasheets/Tools/Schematic_085G.pdf

This design can sample at 2.5 Msps to generate a 200 kHz sine wave.  Performance for other waveforms is MUCH lower:

Quote
Function        Range
Sine        -- 200 kHz
Square    --   10 kHz
Triangle   --   10 kHz
Ramp      --   10 kHz
Staircase --   10 kHz

This is a neat little FG but it is nowhere near a real AWG.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: DIY Function Generator
« Reply #48 on: January 16, 2017, 09:45:17 pm »
Thing is I'd be using this not just for sine waves but as an arbitrary function generator. I'm from a Software Engineer background so I'd write some nice front end software for the Arduino and PC to drive it with a nice GUI. So are you saying that external RAM would not be sufficient for waveforms beyond 3.5MPS?

The Arduino is just about fast enough to blink an LED.  Seriously, it is not quick when compared to any of the more advanced ARM chips.  Nor does it have the neat internal features like a DAC or DMA.

It's pretty easy to think about just incrementing RAM addresses and using a DAC to convert the value to a voltage.  The hard part is knowing WHEN to increment the address and this is usually by detecting overflow in a long addition (64 bits?).  This phase accumulator, as it is called, decides when to change addresses (when overflow occurs).  We had a discussion about phase accumulators within the last couple of months over on the FPGA sub-forum.  It might be worth a search.

Perhaps Google for 'digital frequency synthesis'.

Google also returns a lot of hits for 'op amp signal generator'.  In a perfect world, square waves have zero rise time.  At worst, a couple of nanoseconds!  I'm not sure a garden variety op amp can slew that fast.  There is also the problem of 'range'.  There will need to be multiple timing capacitors and some method of switching.  And scaling, and offset, etc...


http://www.ece.ucsb.edu/Faculty/rodwell/Classes/ece218b/notes/DDFS.pdf
 
The following users thanked this post: ziplock9000

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: DIY Function Generator
« Reply #49 on: January 16, 2017, 11:27:04 pm »
I started trying to build an arbitrary generator but quickly found that the frequencies that I could generate was very limited by the update rate I could achieve for the DAC.  100KHz in your case .  My range is limited to 1Hz to 1Mhz because I only used a 32MHz clock for the AD9834.  A DAC with a SPI interface would be even more limiting.
You cannot generate an arbitrary function with AD9834 at 32Msps as that would require 32MHz*8bit = 256Mbaud SPI! This chip can go that fast only by using internal memory (sine, square and triangle IIRC, + kind of sweep) so no arbitrary.
Arbitrary function generator has to be able to generate absolutely any programmable shape one can imagine. With that  AD you are limited to the SPI speed (<3 MB/s for a PIC18F2550 at ~100% cpu load) so in theory you could reach 3Msps and 8-bit resolution max (IMHO).
I know. I didn't start looking at the AD9834 until I decided not to bother with the arbitrary waveform. I started with just a PIC16F877 and it's built-in DAC. I was unable to reach the frequency range I was looking for. That's when I turned to just the waveforms available in the AD9834 and the PIC18F2550 to do the GUI. The AD9834 more than meets my current needs.
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14210
  • Country: de
Re: DIY Function Generator
« Reply #50 on: January 17, 2017, 01:12:06 pm »
External RAM to sample data can be rather fast, but this would need something like an FPGA / CPLD to generate the address sequences. To have a good arb.- generator one might also needs a more or less fine adjustable clock one when to update the clock / data - this is different from an DDS where the clock is fixed.
 
 
The following users thanked this post: ziplock9000

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: DIY Function Generator
« Reply #51 on: January 17, 2017, 03:26:05 pm »
Here I attach the "AWG STM32L.c", that includes all the core functionality of an arbitrary waveform generator for STM32L152RB. You need to link that with peripheral library (available from STM).

It outputs a content of "sin_lut.c" via DAC2 on PA5, trigger output is on PB10 and MCO is on PA8.

I have removed all the USB related stuff as my USB is a mess.



 
The following users thanked this post: ziplock9000

Offline eeFearless

  • Contributor
  • Posts: 31
  • Country: us
Re: DIY Function Generator
« Reply #52 on: January 17, 2017, 04:03:03 pm »
Here is a DDS design from the AARL archives, complete with reconstruction filter and output leveling:

http://www.arrl.org/files/file/QEX_Next_Issue/May-Jun_2013/Fernandes_QEX_5_13.pdf
 

Offline Vtile

  • Super Contributor
  • ***
  • Posts: 1144
  • Country: fi
  • Ingineer
Re: DIY Function Generator
« Reply #53 on: January 17, 2017, 04:50:31 pm »
I could have swear that someone replied to the OPA aproach. What I quickly looked up ie. Tektronix CFG280 function generator 0..11MHz (20Vpp) is build around handfull of uA741s. With much more functionality than one needs to get started. Also there is discrete Wien-Bridge sine oscillator designs (from tubes to transistors) with Pot-selectable output from few tens to few kiloherts outputs, such can also be modified to have other wave froms as output with a few extra components (mainly OPAs and comparators).

(These are also programmable, but the programming language is hardwiring.)
« Last Edit: January 17, 2017, 04:59:35 pm by Vtile »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: DIY Function Generator
« Reply #54 on: January 17, 2017, 04:52:51 pm »
Here is a DDS design from the AARL archives, complete with reconstruction filter and output leveling:

http://www.arrl.org/files/file/QEX_Next_Issue/May-Jun_2013/Fernandes_QEX_5_13.pdf

That's a great document!  It clearly shows that the DDS chip (AD9833) is the least of the problem.  The author wraps a barn full of stuff around the outside.
Really nice work!
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: DIY Function Generator
« Reply #55 on: January 17, 2017, 07:07:15 pm »
Here's my DDS design with only a tenths worth of stuff around it.

   

   

« Last Edit: June 05, 2019, 10:09:52 pm by MarkF »
 

Offline eeFearless

  • Contributor
  • Posts: 31
  • Country: us
Re: DIY Function Generator
« Reply #56 on: January 17, 2017, 07:50:56 pm »
Is VOUTB from the MCP DAC for adjusting DC offset?

Wouldn't you want a big honking cap at the 470/100/2.7K junction, so the AC differential gain is symmetric?
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14210
  • Country: de
Re: DIY Function Generator
« Reply #57 on: January 17, 2017, 08:09:20 pm »
It looks like VoutB is for adjusting the offset. For symmetry one could just use slightly different resistor values (e.g. around 2.78 K in the feedback of the OP) to include the extra resistance.  One might even save one ore resistor and possibly the lower OP.

However this circuit is still missing two parts: the reconstruction filter is very low grade. Also there is no coarse adjustment for the amplitude (like the relay part) in the other circuit. Also the upper frequency limit and amplitude is rather low. In addition the output impedance is not at 50 Ohms in the simple circuit.

So that simpler circuit has some good ideas (like having the offset) and using an DAC to set the amplitude. However there is also a oversimplification in using a slow OP as an filter and the low output amplitude.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: DIY Function Generator
« Reply #58 on: January 17, 2017, 08:55:20 pm »
Yes. VoutB is the offset adjustment and VoutA is the amplitude control. The amplitude gain is set for 2Vpp with a +/- 1V offset control. The op-amp gain could be adjusted for a larger output if desired.  I see no reason for a coarse amplitude adjustment with noise prone relay contacts. The coarse/fine adjustment is part of the GUI with finer adjustments achieved with a 12 bit DAC (MCP4822) instead of the 8 bit DAC (MCP4802) I used.

As for the reconstruction filter, I found it almost unnecessary with the 1Hz to 1MHz frequency range I limited the DDS to. A FFT shows the DDS output to be very clean without one.

The 50 ohm output impedance is a weak point for me. Any suggestion for a fix is welcome.

Edit: See the attached application note on the amplitude control for the AD9834. It is a coarse adjustment in itself.
« Last Edit: January 17, 2017, 09:12:08 pm by MarkF »
 

Offline ziplock9000

  • Regular Contributor
  • *
  • Posts: 173
  • Country: gb
Re: DIY Function Generator
« Reply #59 on: January 17, 2017, 09:42:56 pm »
External RAM to sample data can be rather fast, but this would need something like an FPGA / CPLD to generate the address sequences. To have a good arb.- generator one might also needs a more or less fine adjustable clock one when to update the clock / data - this is different from an DDS where the clock is fixed.
Ah balls. It's looking more and more like even a modest 10Mhz range arb gen is out of range and better to just buy one :/
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14210
  • Country: de
Re: DIY Function Generator
« Reply #60 on: January 17, 2017, 09:53:48 pm »
Fixing the output to get closer to a 50 Ohms output is easy: replace the 51 Ohms behind the OP with 100 Ohms and adjust the filter to 100 Ohms. These two resistors are effectively in parallel to determine the output impedance. Having the filter at the output is not such a good idea.

The output amplitude is also limited by the OPs current limit and the maximum slew rate. For the TLE2081 the slew rate limit is about 10 V_ss at 1 MHz. Which would result in 2.5 V_ss to a 50 Ohms load. So 2 V_ss is already rather close to that limit. There is also a current limit: 1 V at a 50 Ohms load already needs about 30 mA from the OP (with 100 Ohms resistors). So it needs an better OP (or two) to get a higher amplitude.

There is some filtering: the one a the output and the limited bandwidth of the OP also acts like a low pass filter. Still only 4th order with low Q and thus a limit to something like 1-2 MHz despite of a limit of about 10 MHz from the DDS chip.

The amplitude adjustment via the reference input of the DAC in the DDS chip is good for fine adjustment, but not working well for low amplitudes, as this will increase the DDS internal DAC errors. Having a 12 Bit DAC to control does not help here. It is just that one should not go down below about 10% of the maximum for the ref input.

So an additional switchable 20 dB attenuators would really help to extend the amplitude range, without adding to much noise / distortion. For a 50 Ohms signal, relays are not bad and at only 1-5 MHz there is no need for special RF relays. With fine adjustment via the ref input one can get away with just 1 or 2 relays (or maybe just mechanical switches) for steps of 20 dB and maybe another 10 or 20 dB. A passive divider at the output is also the best way to get a really low noise and SWR, at least for the low amplitude setting.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: DIY Function Generator
« Reply #61 on: January 17, 2017, 10:02:04 pm »
External RAM to sample data can be rather fast, but this would need something like an FPGA / CPLD to generate the address sequences. To have a good arb.- generator one might also needs a more or less fine adjustable clock one when to update the clock / data - this is different from an DDS where the clock is fixed.
Ah balls. It's looking more and more like even a modest 10Mhz range arb gen is out of range and better to just buy one :/

Absolutely!

There are some fairly inexpensive AWGs that can produce some very nice results.  Something in the Siglent or Rigol lines will be just fine.  Even the very cheap FG085 can do something useful.  It a very neat gadget up to a 200 kHz (sine).

Within its frequency range of 12 MHz at +- 5V, the Digilent Analog Discovery can do some very impressive work.  For $279, this device is totally underappreciated.
http://store.digilentinc.com/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply/


 
The following users thanked this post: ziplock9000

Offline ziplock9000

  • Regular Contributor
  • *
  • Posts: 173
  • Country: gb
Re: DIY Function Generator
« Reply #62 on: January 17, 2017, 10:54:10 pm »
External RAM to sample data can be rather fast, but this would need something like an FPGA / CPLD to generate the address sequences. To have a good arb.- generator one might also needs a more or less fine adjustable clock one when to update the clock / data - this is different from an DDS where the clock is fixed.
Ah balls. It's looking more and more like even a modest 10Mhz range arb gen is out of range and better to just buy one :/

Absolutely!

There are some fairly inexpensive AWGs that can produce some very nice results.  Something in the Siglent or Rigol lines will be just fine.  Even the very cheap FG085 can do something useful.  It a very neat gadget up to a 200 kHz (sine).

Within its frequency range of 12 MHz at +- 5V, the Digilent Analog Discovery can do some very impressive work.  For $279, this device is totally underappreciated.
http://store.digilentinc.com/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply/
What I was hoping to build looks similar to the FG085 but with a PC/Windows based front end for versatility. Thanks
 

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: DIY Function Generator
« Reply #63 on: January 18, 2017, 09:04:26 am »
I also like the ideas of a 1Gs 8-channel 14-bit ARB, it would be very interesting to have it on my desk but to be fair I do not have $1000 and anything that sticks beyond 1MHz analog bandwidth is beyond my field of interest. I need a true arbitrary waveform generator (and not sin+square), for embedded, testing and debugging. Current micros are clocked in the range of 50-100MHz, they cannot cope with signals from >1MHz bandwidth (even a stupid PID @ 100kHz is a challenge on a 100MHz micro) so I really have no interest in a 5MHz triangle waveform.
 
What I was hoping to build looks similar to the FG085 but with a PC/Windows based front end for versatility. Thanks
FG085 looks too limited in functionality for me but the bandwidth is ok-ish.

I need:
-a sine sweep, from A to B, in logarithmic scale. Two decades at least. 1Hz:100Hz, 2Hz:200Hz, 5Hz:500Hz,..., 5kHz:~500kHz
-random noise generator, with replay (so not that random)
-trapezoidal shape (for servo control)
-ramp with reset output (for integrating opamp with zeroing)
-external output trigger, input trigger and clock (to synchronize that with external gear for debugging, or to cascade/parallel with second arb generator),
-incremental encoder/pushbutton emulator with switching noise (for testing noisy encoder/button interfaces)
-hardware keyboard and standalone operation not required
-USB interface
« Last Edit: January 18, 2017, 09:07:16 am by Brutte »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: DIY Function Generator
« Reply #64 on: January 18, 2017, 03:51:59 pm »
External RAM to sample data can be rather fast, but this would need something like an FPGA / CPLD to generate the address sequences. To have a good arb.- generator one might also needs a more or less fine adjustable clock one when to update the clock / data - this is different from an DDS where the clock is fixed.
Ah balls. It's looking more and more like even a modest 10Mhz range arb gen is out of range and better to just buy one :/

Absolutely!

There are some fairly inexpensive AWGs that can produce some very nice results.  Something in the Siglent or Rigol lines will be just fine.  Even the very cheap FG085 can do something useful.  It a very neat gadget up to a 200 kHz (sine).

Within its frequency range of 12 MHz at +- 5V, the Digilent Analog Discovery can do some very impressive work.  For $279, this device is totally underappreciated.
http://store.digilentinc.com/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply/
What I was hoping to build looks similar to the FG085 but with a PC/Windows based front end for versatility. Thanks

For $35 and a couple of hours work, you can just buy the FG085 and leave it laying on your workbench.  No USB cables, no coupling with the PC, etc.
https://www.amazon.com/Function-Generator-DIY-Tech-FG085/dp/B00C5UO8U6

If building an AWG is a learning project with value beyond just making signals, great!  Building something is good.  OTOH, if the goal is to have some kind of signal source for other projects, maybe $35 isn't such a bad idea.  Besides, you still get some soldering practice and that isn't all bad.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: DIY Function Generator
« Reply #65 on: January 18, 2017, 04:02:43 pm »
I also like the ideas of a 1Gs 8-channel 14-bit ARB, it would be very interesting to have it on my desk but to be fair I do not have $1000 and anything that sticks beyond 1MHz analog bandwidth is beyond my field of interest. I need a true arbitrary waveform generator (and not sin+square), for embedded, testing and debugging. Current micros are clocked in the range of 50-100MHz, they cannot cope with signals from >1MHz bandwidth (even a stupid PID @ 100kHz is a challenge on a 100MHz micro) so I really have no interest in a 5MHz triangle waveform.
 
What I was hoping to build looks similar to the FG085 but with a PC/Windows based front end for versatility. Thanks
FG085 looks too limited in functionality for me but the bandwidth is ok-ish.

I need:
-a sine sweep, from A to B, in logarithmic scale. Two decades at least. 1Hz:100Hz, 2Hz:200Hz, 5Hz:500Hz,..., 5kHz:~500kHz
-random noise generator, with replay (so not that random)
-trapezoidal shape (for servo control)
-ramp with reset output (for integrating opamp with zeroing)
-external output trigger, input trigger and clock (to synchronize that with external gear for debugging, or to cascade/parallel with second arb generator),
-incremental encoder/pushbutton emulator with switching noise (for testing noisy encoder/button interfaces)
-hardware keyboard and standalone operation not required
-USB interface

You really should look at the Digilent Analog Discovery.  It turns out that your 'sweep' requirement is met by the Network app while the Wavegen app will meet the noise, trapezoid and general signal requirements.  External input trigger is probably possible (there are pins for it but I have TESTED it myself).  I'm not sure about trigger out...

It costs nothing to download the Waveforms software and play around with the demo mode:
http://store.digilentinc.com/waveforms-2015-download-only/

Here's an overview page with a link to the Reference Manual (among other things):
https://reference.digilentinc.com/reference/instrumentation/analog-discovery-2/start?redirect=1
 
The following users thanked this post: Brutte

Offline AE7OO

  • Regular Contributor
  • *
  • Posts: 65
  • Country: us
Re: DIY Function Generator
« Reply #66 on: April 13, 2019, 04:32:26 am »
I've got the semi-updated (Meaning it has the 12bit/2048 update, but still has the CH340 serial to USB) MHS-5200A - 25Mhz.  Sine wave output to 25Mhz, all other outputs restricted to give or take 6Mhz.  It is a ARB with about 200Ms(Closer to 170 according to Sigrok), 12bit with 2048 points and 15 memories. 
As long as you keep the output to a semi-low level, about 7Vpp above 10Mhz OR 14Vpp below, it works just fine. 
As far as I can tell the complete serial protocol has been reverse engineered, but the native software I've got is not too bad.  It handle outputs of both channels, freq measurements, freq sweeping, and has basic waveform generation.

It runs about from about $70 on Amazon(Prime) for the 25Mhz one.  Trying to go lower than this price, you'll end up with either a Kit, a reference board design, a analog (aka XR220x) generator or a audio only gen.
I know the thread is old but....
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf