Enter Your Project for a chance to win a Nano Grand Prize bundle for the most innovative use of Arduino plus a $400 shopping cart! Back to homepage | Project14 Home | |
Monthly Themes | ||
Monthly Theme Poll |
I think Nanorama initiative is a great idea, so I would really love to contribute, so this is a project I started to work on.
Unfortunately, because of lockdown, I don’t have full access to my laboratory, but nothing can stop a maker (well, except may be the maker’s wife, but that’s another matter), thus I can not test on a real board: I will provide more details as soon as restrictions will fade
From time to time, while debugging embedded software, I need to run the same sequence of digital inputs. For example, if you have an issue when a particular sequence of events occurs, or when a certain sequence of buttons is pressed by the user. So, why not build a programmable function generator?
I want to do something lean-and-mean, because it’s something I will use just few times. I do not want to connect a display, make up all the menus with the buttons to navigate, etcetera.
Do you remember the old good piece of hardware like this one?
where the only interface was a serial connection and menus were built using VT100 escape sequences?
Well, I want to build an interface like that: I will configure the function generator by means of a VT100 terminal interface
Luckily, there is a library that wraps VT100 escape sequences into a set of handy functions. This is the starting point to build a menu-based UI
Since I have some time to spend on this project, my function generator will implement the following functions
- Sine wave
- Square wave (PWM)
- Triangle wave
- Sawtooth wave
- User-defined
I have a spare Arduino Nano, so this will be the target board for this project. After all, I think it is a good choice because it is small in size and the same board is shipped in 3.3V and 5V version. This means I can use the same firmware to generate signal with different amplitudes
The Arduino Nano, however, does not have a DAC converter, so the analog waveforms must be generated by means of a PWM and a low-pass filter.
As a quick reminder, the dc value, given the on and off time, can be calculated using the following formula
You can find a great explanation at this link
https://create.arduino.cc/projecthub/Arduino_Scuola/build-a-simple-dac-for-your-arduino-4c00bd
The PWM frequency on Arduino Nano is 480 Hz (or 960 Hz on pin 5 and 6). So we need to design a low pass filter that cuts well below this frequency (let’s say about 10 Hz – this means that the max frequency of a sin wave we can generate should be less than about 2 Hz in order not to attenuate the signal)
I am going to use a passive filter, because I expect to have loads that takes less than 10mA. So the circuit for the low-pass filter is very simple:
The cut-off frequency is given by the formula
With R = 6,8 kOhm and C = 2.2 uF, the cut-off frequency is 10,64 Hz, which is good
Back to the code, the analog waveforms are generated using lookup tables generated using this site
https://www.daycounter.com/Calculators/
Each table has 128 samples. Every main cycle, I perform the following code
I should evaluate whether to use a linear interpolation between two table’s point to get a better accuracy
For the user-defined functions, we can enter a sequence of high and low and the duration of each step
The source (still work in progress) is available on github
Top Comments