11
22[ ![ Arduino CI] ( https://github.com/RobTillaart/FunctionGenerator/workflows/Arduino%20CI/badge.svg )] ( https://github.com/marketplace/actions/arduino_ci )
3+ [ ![ Arduino-lint] ( https://github.com/RobTillaart/FunctionGenerator/actions/workflows/arduino-lint.yml/badge.svg )] ( https://github.com/RobTillaart/FunctionGenerator/actions/workflows/arduino-lint.yml )
4+ [ ![ JSON check] ( https://github.com/RobTillaart/FunctionGenerator/actions/workflows/jsoncheck.yml/badge.svg )] ( https://github.com/RobTillaart/FunctionGenerator/actions/workflows/jsoncheck.yml )
35[ ![ License: MIT] ( https://img.shields.io/badge/license-MIT-green.svg )] ( https://github.com/RobTillaart/FunctionGenerator/blob/master/LICENSE )
46[ ![ GitHub release] ( https://img.shields.io/github/release/RobTillaart/FunctionGenerator.svg?maxAge=3600 )] ( https://github.com/RobTillaart/FunctionGenerator/releases )
57
8+
69# FunctionGenerator
710
8- Arduino library to generate wave forms (nummeric) for a DAC
11+ Arduino library to generate (numeric) wave forms for a DAC
12+
913
1014## Description
1115
12- TODO.
16+ This library presents a class for a function generator in software.
17+ It is typical used to control one or more DAC's.
18+ To maximize signal quality one has to apply all (or most) processor power
19+ to calculate new values over and over again to get enough resolution.
20+ In practice the generator is useful for low frequencies,
21+ 0.01 - 25 Hz, depending on waveform and processor and number of DAC's.
22+ (see indication below).
23+
24+ Note: this class generates float values, performance wise this can be optimized,
25+ to achieve higher speeds at cost of accuracy / precision.
26+
27+
28+ ## Performance
29+
30+ Indication of what performance can be expected (based upon 0.2.1 version).
31+ Note that the values need to be transported to a DAC or serial port too.
32+ Numbers based on performance example, for one single signal.
33+
34+ | Processor | Clock | Waveform | usec/calls | max freq |
35+ | :-------------| ---------:| :---------| -----------:| ---------:|
36+ | Arduino UNO | 16 MHz | sawtooth | 62 | 60 Hz |
37+ | Arduino UNO | 16 MHz | triangle | 74 | 50 Hz |
38+ | Arduino UNO | 16 MHz | square | 53 | 1000 Hz |
39+ | Arduino UNO | 16 MHz | sinus | 164 | 25 Hz |
40+ | Arduino UNO | 16 MHz | stair | 81 | 50 Hz |
41+ | Arduino UNO | 16 MHz | random | 37 | 1000 Hz |
42+ | | | | | |
43+ | ESP32 | 240 MHz | sawtooth | 3.8 | 1000 Hz |
44+ | ESP32 | 240 MHz | triangle | 3.9 | 1000 Hz |
45+ | ESP32 | 240 MHz | square | 2.8 | 1000 Hz |
46+ | ESP32 | 240 MHz | sinus | 13.6 | 250 Hz |
47+ | ESP32 | 240 MHz | stair | 4.8 | 800 Hz |
48+ | ESP32 | 240 MHz | random | 1.3 | 1000 Hz |
49+
50+
51+ - assumption minimal 250 samples per period to get a smooth signal.
52+ if a rougher signal is OK, higher frequencies are possible.
53+ - ESP32 can do more calculations however 1000 Hz seems to be a nice
54+ upper limit for a software based function generator.
55+ - if one wants to control multiple DAC's one need to divide the numbers.
56+
57+
58+ Note: hardware function generator https://github.com/RobTillaart/AD985X
59+
1360
1461## Interface
1562
@@ -18,48 +65,76 @@ TODO.
1865- ** funcgen(float period = 1.0, float amplitude = 1.0, float phase = 0.0, float yShift = 0.0)**
1966All parameters can be set in the constructor but also later in configuration.
2067
68+
2169### Configuration
2270
23- - ** void setPeriod(float period = 1.0)** // seconds
24- - ** float getPeriod**
25- - ** void setFrequency(float freq = 1.0)** // Hertz
26- - ** float getFrequency()**
27- - ** void setAmplitude(float ampl = 1.0)** // -
28- - ** float getAmplitude()**
29- - ** void setPhase(float phase = 0.0)** // phase of period
30- - ** float getPhase()**
31- - ** void setYShift(float yShift = 0.0)** // shift in amplitude, zero point.
32- - ** float getYShift()**
71+ - ** void setPeriod(float period = 1.0)** set the period of the wave in seconds.
72+ - ** float getPeriod()** returns the set period.
73+ - ** void setFrequency(float frequency = 1.0)** set the frequency of the wave in Hertz (1/s).
74+ - ** float getFrequency()** returns the set frequency.
75+ - ** void setAmplitude(float amplitude = 1.0)** sets the amplitude of the wave. TODO point to point?
76+ Setting the amplitude to 0 gives ?what?
77+ - ** float getAmplitude()** returns the set amplitude.
78+ - ** void setPhase(float phase = 0.0)** shifts the phase of the wave. Will only be noticeable when
79+ compared with other waves.
80+ - ** float getPhase()** returns the set phase.
81+ - ** void setYShift(float yShift = 0.0)** sets an Y-shift in amplitude, allows to set some zero point.
82+ - ** float getYShift()** returns the set Y-shift.
83+
3384
3485### Wave forms
3586
3687t is time in seconds
37- - ** float sawtooth(float t)**
38- - ** float triangle(float t)**
39- - ** float square(float t)**
40- - ** float sinus(float t)**
41- - ** float stair(float t, uint16_t steps = 8)**
42- - ** float random()**
43- - ** float line()**
44- - ** float zero()**
45-
46- Line() and zero() are functions that can be used
47- to drive a constant voltage from a DAC and can be
48- used to calibrate the generator / DAC combination.
88+
89+ - ** float sawtooth(float t, uint8_t mode = 0)** mode == 0 (default) ==> sawtooth /|. mode == 1 ==> sawtooth |\.
90+ - ** float triangle(float t)** triangle form, duty cycle 50%.
91+ - ** float square(float t)** square wave with duty cycle 50%.
92+ - ** float sinus(float t)** sinus wave, has no duty cycle.
93+ - ** float stair(float t, uint16_t steps = 8, uint8_t mode = 0)** mode = 0 ==> steps up, mode = 1 steps down.
94+ - ** float random()** noise generation.
95+ - ** float line()** constant voltage line
96+ - ** float zero()** constant zero.
97+
98+ Line() and zero() are functions that can be used to drive a constant voltage from a DAC
99+ and can be used to calibrate the generator / DAC combination.
100+
49101
50102## Operational
51103
52104See examples.
53105
54- ## TODO
55106
56- ideas for the future...
107+ ## Future
108+
109+
110+ #### waveforms
111+
112+ - square duty-cycle (will be slower!)
113+ - triangle duty-cycle (makes sawtooth a special triangle)
114+ - trapezium wave (would merge square and triangle and sawtooth)
57115
116+ #### investigate
117+
118+ - duty-cycle for sinus what does it mean. move peak.
119+ - white noise, pink noise etc.
120+ - investigate algorithms for performance gains (DAC specific values 10-12-16 bit)
121+ - Amplitude modulation ?
122+ - external clock to synchronize two or more sw function generators.
123+ - RC function curve.
124+ - heartbeat curve?
125+ - record a signal and play back
126+
127+ #### misc
128+
129+ - stand-alone functions in separate .h?
130+ - mapping to voltage function.
131+ - check for synergy with https://github.com/RobTillaart/AD985X
132+
133+ #### examples
134+
135+ - example ESP32 version as separate task...
58136- example with DAC. 8 12 16 bit.
59- - example with potmeters for 4 parameters
60- - RC function
61- - Trapezium
62- - Sawtooth reverse?
63- - play "recording"
137+ - example with potentiometers for 4 parameters
138+
64139
65140
0 commit comments