Waveform generator using µc beginners project - Page 1
Forum section: electronics / beginners

author: Rdx
author_rank: Contributor
timestamp: June 29, 2019, 05:31:02 pm
content: Being a mechanical engineer I want to get more into electrical stuff too as a hobby. For this I thought about designing a waveform generator using a microcontroller.For this I have ordered an Atmel XPlained mini board (ATSAMD10) for which Atmel has a very similar software example for DAC software waveform generation (For ATSAMD20) through which I feel confident to being able to build my own adaption out of it, software side.http://ww1.microchip.com/downloads/en/AppNotes/Atmel-42458-Waveform-Generator-and-WAV-Audio-Player-using-DAC_Application-Note_AT11493.pdfI am considering a beginners project to learn stuff that will end up with a useable piece of lab equipment hopefull some questions arise.For example the "requirements" of such waveform generator. Being a electronics beginner I did not yet necessarily miss a waveform generator ever, but I am aware that rather expensive waveform generators are available - so there must be a use-case.How important would it be to have a DC-offset? How could such be achieved?How important would it be to allow change in amplitude? Rn I am considering to only have the frequency adjustable while peak to peak would always be full voltage range of the ATSAMD10 microcontroller. (Could at least be reduced in software, how would it be possible to extend to lets say 5V out of the 3.3V DAC?)Should the waveform be +/- symmetrical (or even DC-offsetable from that?), how could such be achieved? For my understanding the Atmel sample from above just outputs an analogue voltage between GND and the DAC output pin. Is there a way to make it a +/- voltage respective to the microcontoller GND?As mentioned i am a mechanical engineer with currently getting into this hobby wise and building up a set of lab equipment. Any ideas or suggestions are welcomeBest regards from Germany

author: MarkF
author_rank: Super Contributor
timestamp: June 29, 2019, 06:57:31 pm
content: The first thing you need to ask yourself is: What frequency range do I want to achieve?With that processor and its 48 MHz max clock, I would guess your max frequency might be 200,000 Hz. Given the possible number of samples per cycle, processor update rate of the DAC and the number of processor instructions needed per update.You would be better off controlling a dedicated DDS chip to generate the waveform and just using the processor to update the DDS, a small display and a rotary encoder.There are several threads out there on DIY Function Generators.Here is one example:https://www.eevblog.com/forum/projects/idea-for-a-tiny-function-generator/To answer some of your questions:You would want to generate a symmetrical waveform around zero voltage. You also want amplitude adjustment and DC offset adjustment. For the majority of the time, a sine, triangle and square would meet your needs. A nice to have waveform would be a PWM waveform for motor speed control as an example.Even if the low frequency of the processor generated waveform is acceptable, you will need some op-amps to buffer, scale and filter the waveform at a minimum. If the DAC has a lot of bits (12-bits maybe), you could do the amplitude and offset adjustments by scaling each sample. Far from ideal, but feasible. Otherwise, you will need several DACs to do the waveform scaling (i.e. one for the waveform generation, one for amplitude and one for DC offset).From what you said of your background, this is going to be a challenging project. Both from a hardware and a software point of view.

author: ledtester
author_rank: Super Contributor
timestamp: June 30, 2019, 12:02:42 pm
content: There are many DDS (direct digital synthesis) projects documented on the web. Just google "minidds" or better yet "avr minidds" as some the earliest ones were done with the Atmel AVR processors, e.g.:-http://www.radanpro.com/Radan2400/mikrokontroleri/Jesper's%20AVR%20pages%20-%20MiniDDS.htmThese kinds of projects were turned into products and kits that you can get from ebay / aliexpress / banggood / etc. Most of these use a couple of manually adjusted op amps to control DC offset and amplitude.

author: rstofer
author_rank: Super Contributor
timestamp: June 30, 2019, 03:06:55 pm
content: Quote from: Rdx on June 29, 2019, 05:31:02 pmAt the outboard end of the DAC, you may want to add an op amp to do things like scale and offset. Offset will be important when you work with single rail op amps and everything is shifted up by Vcc/2. Now, it's true that you can do that at the target op amp but it can also be done at the source.Here's why it is important: Suppose you are teaching your grandson (a budding ME as it turns out) about FFT. In doing so, it is worth discussing the DC component. You can display the FFT of a 1 kHz square wave with, and without, the DC offset and the resultant spike at zero Hz on the display.There are probably other reasons but the FFT thing is sitting on my table right now. I'm doing it with an Analog Discovery 2.QuoteYou aren't going to get a 5V output from a 3.3V DAC and that's the reason for the final op amp stage. Using a +-15V op amp you can reasonably expect up to +-12V linear output. Any higher output level will probably result in clipping because most dual rail op amps are not rail-to-rail on the output swing (input either, for that matter).QuoteIf you use a dual rail op amp at the output and the +-15V midpoint is tied to the CPU GND, you will have exactly what you want in terms of GND. You will want to shift the DAC output to center around 0V and you do this by reading Chapter 4 of "Op Amps For Everyone". Basically, you just subtract Vcc/2 at the input to the op amp. It's done with a couple of resistors.

author: ledtester
author_rank: Super Contributor
timestamp: July 01, 2019, 05:57:15 am
content: Quote from: Rdx on June 29, 2019, 05:31:02 pmAttached is the output stage of an XR2206 signal generator found in the Elenco XK-700 Digital/Analog trainer. The output of the XR2206 enter the output stage at the point in the upper left marked "signal input". You'll probably have to tweak for the voltage ranges you'll be using, but it gives you an idea of what's involved.The full schematic may be found at:https://www.elenco.com/wp-content/uploads/2017/10/XK700-4.pdfImplementing variable amplitude in software means you will lose a lot of resolution. Say your DAC has 256 (or 1024) steps between 0 and 5V. If you scale the signal to 1 Vpp in software you only have 256/5 = 51 steps at your disposal.Perhaps others can recommend alternatives to the LM318 that would be suitable for this purpose.