Arduino Waveform Generator: Step 1: Technical Considerations
Arduino Waveform Generator: Step 1: Technical Considerations
by rgco
In the lab, one often needs a repetitive signal of a * Fast: 381 kHz sampling rate
certain frequency, shape and amplitude. It may be to
test an amplifier, check out a circuit, a component or * Precise: 1mHz steps frequency range. As accurate
an actuator. Powerful waveform generators are as the Arduino crystal.
available commercially, but it is relatively easily to
make a useful one yourself with an Arduino Uno or * Easy operation: waveform and frequency settable
Arduino Nano, see for example: with single rotary encoder
Here is the description of another one with the * Easy to make: Arduino Uno or Nano plus standard
following features: components
Making an analog signal One shortcoming of the Arduino Uno and Nano is that
it does not have a digital-to-analog (DAC) converter,
Download
https://www.instructables.com/ORIG/FCX/6Q5E/JN3HUGRL/FCX6Q5EJN3HUGRL.pdf
…
Download
https://www.instructables.com/ORIG/F2B/XUAM/JP2XYEF8/F2BXUAMJP2XYEF8.fzz
…
16x2 LCD display + 20kOhm trimmer and 100Ohm 50kOhm variable resistor
series resistor for backlight
10kOhm resistor
5-pin rotary encoder (with integrated pushbutton)
47kOhm resistor
25 resistors of 10kOhm
1muF capacitor
For the buffer/amplifier
Step 3: Construction
Download
https://www.instructables.com/ORIG/FZ1/VHTG/JN3HUGRJ/FZ1VHTGJN3HUGRJ.ino
…
Step 5: Usage
The signal generator can be powered simply through signal can be used.
the mini-USB cable of the Arduino Nano. It is best
done with a power bank, so that there is no accidental It is really helpful to use an oscilloscope to check the
ground loop with the apparatus that it may be signal amplitude, in particular when the signal
connected with. supplies current to another device. If too much current
is drawn, the signal will clip and the signal is heavily
When switched on it will generate a 100Hz sine distorted
wave. By rotating the knob, one of the other 20 wave
types can be chosen. By rotating while pushed, the For very low frequencies, the output can be visualised
cursor can be set to any of the digits of the frequency, with an LED in series with a 10kOhm resistor. Audio
which can then be changed to the desired value. frequencies can be heard with a speaker. Make sure
to set the signal very small ~0.5V, otherwise the
The amplitude can be regulated with the current gets too high and the signal starts clipping.
potentiometer and either the buffered or the amplified
https://www.youtube.com/watch?v=Y5Rsz057c-E
The signal a better at higher frequencies and also the signal at higher frequencys at the Osci is
better.
Arduino Waveform Generator: Page 5
The video shows the signals generated with the LGT8F328p(32MHz) on the MapleMini Dual-Osci
(I have here switched off the secon channel).
https://youtu.be/qg0Yn3Hg5r4
/assets/img/pixel.png
Merhaba
Teşekkür ederim
https://www.youtube.com/watch?v=tasBP7qpmMM&feature=youtu.be
Wow, good work, that looks like a big jump in sample rate, even more than the factor 3.6 from the
clock frequency, it looks like the sampling loop takes fewer cycles thanks to the intrinsic 32 bit
calculations! The scope trace seems to have at least 30 points per cycle, so that would be 3Msps.
You should really publish this as a separate instructable! I once tried but failed to program the
STM32F103C8T6, and would be quite interested to see a reliable instructable on that.
One follow-up idea I had but never came to was to make the function shape more flexible: fewer
shapes, but each shape with additional parameters e.g. duty cycle, rise-time, fall time for block,
amplitude, phase and frequency for double-sine.
Also, if the STM has more RAM and it can search it fast, there is real gain from having a larger
signal array (e.g. 4096samples) : square waves with very low duty cycles or pulse trains would
Arduino Waveform Generator: Page 6
then be possible.
The triangle and sawtooth have a little bump halfway the range, it looks as if your DAC is not
perfectly monotonic, you may want to test that at lower speeds.
I had some problems to migrate Your code, to set the Port (like PORTD = ...) is different .
Therefore I tried it at first with a special "digitalWriteFaster" to the eight Pins, but now I use the
ODR command , it's for all 32 bits of the port ! It's quicker.
I programmed it with the Arduino IDE (STM32DUINO from Roger Clark Melbourne).
On the STM32F103CB (MapleMini / BluePill) is also more space for programming (128k) and
nearly each pin you can use for ext. interrupts .
Because there is enough space for programming, I tested it as simple Sweep - Generator:
https://www.youtube.com/watch?v=UVS4idJIxCA&feature=youtu.be
Hi, it says "Video unavailable. This video is private."
A sweep is interesting. I did not consider it since I had no need for it and the update of the phase
increment inside the core loop would slow things down, or is it not too bad?
Your scope pictures seem to show wiggles that probably correspond to the sampling frequency, I
would guess they come either from the amplification step or from the scope (which scope is that by
the way, it looks like a budget scope but it has a much better bandwidth than my 1Msps DSO138).
An RC filter could be used to filter out the frequencies above the sampling rate. The output
impedance of the DAC already provides the R, so it would just be a matter of adding a capacitor to
ground at the exit of the R2R DAC. The value of C should be or order
1/(fR)=1/(1MHz*10kOhm)=100pF.
Hi, yes I have to insert a RC filter, but I think its good for sine, but perhaps a problem for square
and other waveforms. I will test it , perhaps I make it switchable.
Last week I made some changes with the menu on the ILI9341 display and integrate a little touch-
menu for changing the frequency ...
I used for the touch-screen 2 interrupt-routines (on TOUCH_IRQ), the normal to
change the input and the second only for stop the loop.
On maplemini it's possible to save up to 14 waveforms in separate arrays.
It's quicker if you change the waveform while sweeping ...
https://www.youtube.com/watch?v=2DBm2Bz4bVM
https://www.youtube.com/watch?v=Za_ELC_1gVQ&feature=youtu.be
I made some changes, a small menu for sweep and other ? functions..
I use now ttwo encoder and two normal push-buttons.
/assets/img/pixel.png
Super project !
I have expand it with a second rotary encoder .
https://www.youtube.com/watch?v=3FNXE9sXheA
/assets/img/pixel.png
https://www.youtube.com/watch?v=RQ3Ek9W75dM&feature=youtu.be
Moreover, this generator has an analog output, you can't just connect it to a MOSFET and expect a
high-current analog output. The MOSFETs are great for digital switching, analog DC amplification
is a lot more involved!
ok thanks ..but can you give me an idea how to make this work ....perhaps using some transistors
for boosting the signal?(i am new to electronics and i am just trying to learn)Thanks
The simplest circuit is a power-transistor inside an op-amp feedback loop, see
https://www.allaboutcircuits.com/technical-articles/how-to-buffer-an-op-amp-output-for-higher-
current-part-1/
However, it's hard to make it work in practice. I tried and failed. Beware that the buffer needs to
dissipate a lot of power.
Do you really need true analog signals? If you manage with PWM it'll be much easier. If it's for
audio, it's better to get an off-the-shelf audio amplifier.
This presents an oversimplification of the R2R network requirements for accuracy. The pin outputs
need to be well matched, which is
best done a light loads, so stick with the 10K values. To achieve 8-bit DAC accuracy and be
monotonic (google it), the resistors' should be accurate to 1/512 or about 0.2%, so that makes
them expensive.
However, typical 1% or even 2% resistors have a resistor-to-resistor matching within a
single batch that can be much better than their absolute accuracy. It’s also possible to “hand
select” resistors using a DVM. Note that DVM accuracy is not as important as
its repeatability and resolution, since it’s their ratios that is important here,
but ALL resistors should be within 0.2% of each other! See: "resistor ladder" in Wikipedia. DACs
need to be to monotonic to accurately reproduce signals without distortion.
Just a quick update on my purchase of a DSO138 oscilloscope. The eBay seller, cinnamon 1956-
5, refunded me the cost of the case (look out for that misleading practice where the Selection box
has more than one price, although it didn't when I placed my order, it did later, I'm taking screen
Arduino Waveform Generator: Page 9
prints from now on). The agreement was that I would buy the o'scope from him/her again (at a
higher price for certain), which I've done. So I'm now waiting for another 16 days for the scope to
get here (USA). I guess the case will serve as compensation for the time lost, but all is well.
Nice job! I have a need for something portable that generates more-complex waveforms at low
frequencies, and this may well be the basis for it.
One suggestion: you can buy R2R ladders as SIPs or DIPs, and will probably get a closer match
by using one. Plus you save a bunch of board space and soldering. I found the Bourns 4610X-
R2R-103LF (10K SIP) for a buck at Mouser, and it's probably available at about the same price
from Digi-Key, Farnell, etc.
Thanks for the tip! I must say I was surprised how well the R2R DAC works even without any
special measures: I had started to make a list of resistor values to make matched pairs, but then
got bored and thought I could adjust afterwards if needed. Instead there is no sign of any steps in
going e.g. from 127 to 128. Also the soldering wasn't too bad since the schematics almost matches
the pin layout, so there is no need for bridges, and resistors are easy anyway since they are
symmetric and temperature-resistant. But I'll definitively consider for future projects!
If you don't need the highest frequencies, the waveform array can indeed be extended to e.g. 1024
bytes using a 16-bit integer as index. The number of clock cycles will need to be redetermined
(easiest by trial and error) but I suppose it won't add more than 10 cycles.
Ugly? Heck no, that’s the coolest thing I’ve seen in a while. I like it! I could use a little frequency
generator to set up the IF stages of antique radios I’ve been restoring and I think this would work. I
Like the way you can just set it to sine wave and set a frequency. Like I said, that’s cool! :-)
i have a quick question... going back and reviewing everything, the schematic and breadboard
show you using a “LTC3105” module which goes for $26 on eBay. In the photograph you use a
“MT3608” module which is a much more affordable $3 on eBay but you didn’t show the
connections. Does it make any difference what you use? And Is there any way you might just edit
this to show which connections are used to connect the “MT3608” buck boost module?
I think i understood everything else... love the code!!!!! The way it is written, it is really easy to
understand what’s being done and I’m sure glad I didn’t have to figure out the math.
Buddy
I used an MT3608, which cost 30euro cents on Aliexpress. The LTC3105 was the only step-up
module that I could find on Fritzing (the text has been updated to make it more clear). I don't think
it's critical, it only needs to power 20mA or so for the opamp.
Glad you like it. Let me know in case you make it!
Ok I understand now, thanks.
€ 0.30 I need to be shopping on Alienxpress!
I’m going to see what I have, I think I have almost everything to do it but no matter, if I move
forward, I will certainly let you know!
One other thing, when I look at this, it looks almost ready to build on a PC board, Do you have a
Gerber file for it?
I was just thinking if you didn’t, I don’t think it would take too much to make one and get some
Arduino Waveform Generator: Page 10
boards built.
I think this is such a great idea, an Nano, a bunch of resistors, and a few other parts, you toss in a
board and you have a great kit you could sell. (If you wanted to)
Thanks to all who responded regarding the oscilloscope. I see several vendors on eBay, Amazon,
and the like. Excellent price, I'm ordering one. I also built a probe for zelscope but never got it to
work (other than seeing my voice while using the XP computer's internal mic). There is also
soundcard scope (free) software but I'm not about to build another probe. The ready made scope
shown may only be single-trace but there is no danger of bricking a computer or microprocessor.
Thanks again. (Let's hope we don't alienate China)
Interesting project, I liked it, thanks a lot.
Glad you like it. Let me know in case you make it!
Sure I will.
Very interesting and well written instructable, and I appreciate the well laid out and easy to follow
code to run the device. I'm looking for just such a device but hope to get it to give at least 500 KHz
of undistorted sine wave so I can use it to generate IF frequencies for radio repair work. I wonder if
there'd be any benefit to using two Arduinos instead of one, one for frequency generation and the
other for interrupt handling? Could the output frequency be increased using such a scheme?
500kHz undistorted sine wave with Arduino would be hard. The interrupt handling does not cost
any time, so a second Arduino would not help. One thing that comes to mind is to use the timers to
generate a fast block wave and then use an analog filter to turn it into sine. But the frequency can't
be tuned precisely. There are other instructables out here that describe how to use an external
chip, e.g MAX038 and control it with an Arduino. That'd probably give a much more performing
device
This was a fantastic instructable. I was just looking for a little frequency generator build and then
that fantastic demo of the little oscilloscope was exactly what I was looking for. Did you assemble
your oscilloscope. Now they have them completely assembled at Amazon for less than $26
(https://amzn.to/2CUdSbb). Thanks for writing this one up.
Great project that I will be building soon.
Thanks! let me know in case you manage to build it or find a mistake somewhere. The scope was
bought pre-assembled for 13EUR. There are videos on youtube on how to assemble them, which
easily convinced me not to.
Fantastic project! Thank you for sharing it :-)
Glad you like it. Let me know in case you make it!
Cool!!!