1

I want to build a function generator but not the ones which outputs square wave or sawtooth ect. I will input a discrete function lets say f(n) = e^n for n=0 to n=100 and the output array will be outputs as voltage samples creating a e^x like signal on a scope?

Is this possible?

migrated from electronics.stackexchange.com Nov 17 '15 at 18:18

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • If you attach some kind of DAC to it - why not? – Eugene Sh. Nov 17 '15 at 15:21
  • but doesnt Arduino have already its own DAC? – user16307 Nov 17 '15 at 15:22
  • No, why would it? Before assuming something, check the specs. – Eugene Sh. Nov 17 '15 at 15:23
  • sorry Im not into micro controllers much. Isnt Arduino's analog output a DAC? if not whats that? – user16307 Nov 17 '15 at 15:24
  • If you refer the analogWrite function - it is setting PWM output. – Eugene Sh. Nov 17 '15 at 15:25
3

You can generate arbitrary waveforms using either the built-in PWM and a low-pass filter or an external DAC.

You won't get more than 16-bits in PWM ( or AFAIK non-audio DAC with arduino libraries ), so your e^N function will be below your resolution for most of the cycle.

Alternatively, generate a saw-tooth and use an op-amp exponential function

  • no I just gave an e^n as an example. I want to make one which can output any given simple function. – user16307 Nov 17 '15 at 15:27
  • You can't generate arbitrary waveform using PWM, unless you have some kind of PWM-to-waveform circuitry. And the bitness of DAC is depending on DAC only, and can be as high as specified by the DAC itself. – Eugene Sh. Nov 17 '15 at 15:28
  • 1
    @EugeneSh. Add an appropriate low pass filter and PWM becomes a low-quality DAC. If you can find a greater than 16 bit, non-audio, DAC with an arduino library, post a link. – Pete Kirkham Nov 17 '15 at 15:32
  • 1
    I would say that you CAN generate arbitrary waveforms using PWM. All you need is a reconstruction filter. All 1 bit DA (sigma delta) converters basically use PWM. BUT the PWM signal from an Arduino is very low in frequency (around 400 Hz) and only 256 levels (8 bit) so very crude. You could make a half decent 10 Hz arbitrary waveform though. But note the 10 Hz, not very usefull ! – Bimpelrekkie Nov 17 '15 at 15:35
  • 1
    @EugeneSh. Because the comment was towards "Arduino level Hardware". If the OP is going to buy a DAC board ("not really into DAC hardware") and hook it up in the general way, that'll easily be 10mV coupled noise, if not more. – Asmyldof Nov 17 '15 at 16:21
3

Arduino DUE has a built-in DAC (has two in fact) and so you can do arbitrary function generation fairly easily by just going over some arbitrary table (that sampled the function) and output that with analogWrite to the DAC channel[s]; details in this arduino.cc tutorial. They only show sine/triangle/square waves there, but if you look at Waveforms.h at the end of that tutorial you can put arbitrary shapes in there.

By the way this technique of waveform generation of using a lookup table and a DAC is abbreviated DDS for Direct Digital Synthesizer. Here's a more conceptual tutorial on DDS (not involving arduino): http://www.ni.com/white-paper/5516/en/

The DACs built-in Arduino DUE have 12-bit resolution by the way, i.e. 4096 discrete output levels. IF you need better than that, an external DAC is required, which you could connect by TWI/SPI etc.

You can get a poor man's DAC on the Arduino UNO or Leonardo by PWMing with analogWrite on the GPIO pins (as suggested in the other answer), but you need understand low pass filter fundamentals to get that done.

  • 2
    ... or create an R-2R ladder on any number of IO pins you want. – Majenko Nov 17 '15 at 20:50
  • @Majenko: yes, that can surely can be done but it can well turn into a project by itself: e.g pcarduino.blogspot.com/2013/11/… – Fizz Nov 17 '15 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.