Sign up ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

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?

share

migrated from electronics.stackexchange.com yesterday

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. yesterday
    
but doesnt Arduino have already its own DAC? – user16307 yesterday
    
No, why would it? Before assuming something, check the specs. – Eugene Sh. yesterday
    
sorry Im not into micro controllers much. Isnt Arduino's analog output a DAC? if not whats that? – user16307 yesterday
    
If you refer the analogWrite function - it is setting PWM output. – Eugene Sh. yesterday

2 Answers 2

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

share|improve this answer
    
no I just gave an e^n as an example. I want to make one which can output any given simple function. – user16307 yesterday
    
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. yesterday
    
@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 yesterday
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 ! – FakeMoustache yesterday
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 yesterday

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.

share|improve this answer
1  
... or create an R-2R ladder on any number of IO pins you want. – Majenko yesterday
    
@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/… – Respawned Fluff yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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