
The higher sampling rate gave me a better waveform accuracy in the high frequencies, as well as more stability. In the end my project ended quite different of yours: I used a cheap Arduino Nano, I get rid of the interrupts (causing a significant overhead) to poll a 200 kHz timer. These ones were installed on the 3 highest bits to make the MSBs as accurate as possible. In my project I used a set of 1 % resistors, and manually matched a few of the 10 and 20 kΩ with an ohmmeter. It may lead to significant errors on the most significant bits, causing large unwanted steps and even creating a non-monotonic curve. I see you used 5 % resistor which is too coarse. IMHO 330 pF is much more suitable, even 1 nF is probably fine.Īnother important thing is the accuracy of the R–2R resistors. With a 10 nF capacitor, the cut-off frequency is slightly above 1.5 kHz, which is way too low. This is much faster than calculating the values individually.Īre you sure of the capacitor value for the anti-aliasing low-pass filter? An R–2R network has an output impedance of R (10 kΩ here) so the 300 Ω resistor is negligible and could be omitted. I stored this array in the Arduino's memory called sine20000 and recalled the values I needed to send to the DAC. Then all the needed to be done in the interrupt routine was some simple math: case 1://triangleįor the sine function, I wrote a simple python script which outputs 20000 values of 127+127sin(x) for one complete cycle: import math Every time the frequency changed I calculated the amount that the triangle and saw function would have to increment at a sampling rate of 100kHz: triInc = 511/period I used several work around to get by this:įor triangle and saw I created the variables sawByte, triByte, sawInc, and triInc. Time intensive operations like mathematical operations with floats and using the sin() function take too much time to complete.
#Test tone generator serial code#
Since the interrupts occur at such a high frequency, I had to keep the interrupt routine, the piece of code encapsulated in the ISR(TIMER1_COMPA_vect) as short as possible. The rest of the code monitors the state of the buttons and knobs and adjusts variables accordingly. The code uses a timer interrupt at a frequency of 100kHz to send new data out to the DAC. Upload the code at the bottom of this step onto the Arduino. I will attach the bottom panel on later in this instructable. I made my project enclosure out of wood, so I had to glue all the pieces (except the bottom) together with wood glue. I cut out shapes of all four waveforms in the front of the enclosure so that I could backlight them with indicator LEDs, you may choose to just drill four 5mm holes for these LEDs in the front panel of the enclosure, place one LED under each momentary switch.Īlso include a rectangular (11mm tall, 12mm wide) cutout somewhere on the side of the enclosure for the arduino's usb port. (3x) 7mm holes for four push buttons- sin, saw, tri, and pulse (3x) 7mm holes for gain, freq, and PWM pots Figure 4 shows the holes that should be drilled on the front panel: If you do not have access to a laser cutter, you can use my 2D files a guide and drill the necessary holes in a project enclosure of some kind. I designed the enclosure using AutoCAD, Autodesk 123D Make, and Corel Draw, and I've included corel draw and adobe illustrator 2D files as well as the STL, and DWG files from this process below. I decided to laser cut a custom enclosure for my project. (4x) 740 ohm 1/4W 5% Carbon Film Resistor (1 package) Radioshack 271-1317īlack diffusor material (tissue paper, plastic, etc) (4x) White Super-bright LED Indicator Radioshack #55050633 (1x) Arduino Proto Shield Radioshack #276-140 (1x) Arduino Uno REV 3 Radioshack #276-128 (2x) 220♟ 35V 20% Radial-lead Electrolytic Capacitor (or anything between 200 and 300 uF) Radioshack #272-1029 (1x) LM386 Low Voltage Audio Power Amplifier Radioshack #276-1731 (1x) 4.7K Ohm 1/4-Watt Carbon Film Resistor Radioshack #271-1330 (1x) 1/8" Stereo In-Line Audio Jack Radioshack #274-274 (1x) 10K-Ohm Audio Control Potentiometer with SPST Switch Radioshack #271-215 (1x) 10K-Omh Audio-Taper Potentiometer Radioshack #271-1721 (1x) 50K-Ohm Linear-Taper Potentiometer Radioshack #271-1716 (9x) 20K Ohm 1/4-Watt Carbon Film Resistor (2 packages) (8x) 10K Ohm 1/4-Watt Carbon Film Resistor (2 packages) Radioshack #271-1335 (4x) Mini SPST 1.5-Amp Momentary Pushbutton Switch (2 packages) Radioshack #275-1556
