Author Topic: DIY Function Generator  (Read 57928 times)

0 Members and 1 Guest are viewing this topic.

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: 14192
  • 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: 2543
  • 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".

 

Offline Smokey

  • Super Contributor
  • ***
  • Posts: 2573
  • 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: 14192
  • 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: 2543
  • 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: 14192
  • 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?
 

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

Online 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: 2543
  • 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf