Introduction: Function Generator (arduino Pro Mini)
Hello,
this is a function generator with Arduino Pro Mini and few components that at power on start with a sawtooth of about 40
Hz and 5Vpp. Pressing one time the SWFUN button the output change to a triangular wave and pressing another time the button the output is a sine of always 40 Hz.
The LEDs means:
Blue = sawtooth
Red = triangular
Green = sinusoidal
The firmware of Arduino Pro Mini is here and require the library TimerOne.
Many thanks to the author of this article from which I was inspired.
At the PIN 9 of Arduino there is a square wave of about 32KHz . His duty cycle vary with a linear law from 0 to 1023 (10 bit DAC) and drop to zero immediatly in the sawtooth. In the triangular wave the d.c. vary from 0 to 1023 then from 1022 to 0 excluding odd values (see the code). In this mode the overall period of these two waveform is the same.
Finally the sine wave is obtained with the duty cycle depending from the math. sin function (his output is between -1 and 1) re-mapped into a 0-1023 range.
For all the waveforms the low-pass filter composed by a 10 KOhm resistor and a 100nF capacitor (with a cut-off frequency of 160 Hz about) extract the average value of the rectangular wave that is a linear function of the duty cycle of the 32KHz signal.
The push button, connected to the PIN 2 (with a pull-up of 10 KOhm) trigger the interrupt 0 of arduino that call the changemode function. This function set the general mode variable to set the proper waveform (in the loop function) and set the proper LED.
With this item you can test an oscilloscope and an audio amplifier to ear a very low frequency tone.
Of course this project is limited and you can add a frequency setting maybe up to some hundred Hz or 1 KHz.
Finally note that the schematic refer to an arduino pro mini type ATmega328 (5V, 16 MHz)
Step 1: Project Building
Not too much to say! You can solder the wires to arduino pro mini without mounting pins in bundle or use wires with female to female connectors if you just have an arduino fully mounted. The RAW pin accept a voltage up to 10V so a little square 9V battery can be used.
Of course to load the program into arduino you need the arduino IDE and a USB to serial (TTL) device like that showed in this page.
Have fun!