Skip to content

Commit afc9ded

Browse files
authored
update build-CI + badges + minor edits (#3)
* upgrade build-CI + badges + readme.md * add mode flag to reverse sawtooth() and stair()
1 parent fd83fc5 commit afc9ded

14 files changed

Lines changed: 254 additions & 79 deletions

File tree

.arduino-ci.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ compile:
22
# Choosing to run compilation tests on 2 different Arduino platforms
33
platforms:
44
- uno
5-
- leonardo
6-
- due
7-
- zero
5+
# - due
6+
# - zero
7+
# - leonardo
8+
- m4
9+
- esp32
10+
# - esp8266
11+
# - mega2560
12+
# Declaring Dependent Arduino Libraries (to be installed via the Arduino Library Manager)
813
libraries:
9-
- "MCP4725"
14+
- "MCP4725"

.github/workflows/arduino_test_runner.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ name: Arduino CI
44
on: [push, pull_request]
55

66
jobs:
7-
arduino_ci:
7+
runTest:
88
runs-on: ubuntu-latest
99

1010
steps:
1111
- uses: actions/checkout@v2
12-
- uses: Arduino-CI/action@master
13-
# Arduino-CI/action@v0.1.1
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb

README.md

Lines changed: 106 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,62 @@
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)**
1966
All 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

3687
t 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

52104
See 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

examples/functionGenerator/functionGenerator.ino

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
// URL: https://github.com/RobTillaart/FunctionGenerator
88
//
99

10+
1011
#include "functionGenerator.h"
1112

13+
1214
funcgen gen;
1315

1416
uint32_t lastTime = 0;
1517
char choice = '0';
1618

19+
1720
void setup()
1821
{
1922
Serial.begin(500000);
@@ -24,6 +27,7 @@ void setup()
2427
gen.setAmplitude(50);
2528
}
2629

30+
2731
void loop()
2832
{
2933
if (Serial.available())
@@ -54,4 +58,6 @@ void loop()
5458
}
5559
}
5660

57-
// END OF FILE
61+
62+
// -- END OF FILE --
63+

examples/functionGeneratorDuoPlot/functionGeneratorDuoPlot.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
funcgen gen1;
1515
funcgen gen2;
1616

17+
1718
void setup()
1819
{
1920
Serial.begin(115200);
@@ -31,6 +32,7 @@ void setup()
3132
gen2.setYShift(25);
3233
}
3334

35+
3436
void loop()
3537
{
3638
float t = millis() * 0.001;
@@ -44,4 +46,6 @@ void loop()
4446
Serial.println();
4547
}
4648

47-
// END OF FILE
49+
50+
// -- END OF FILE --
51+

examples/functionGeneratorPerformance/functionGeneratorPerformance.ino

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// URL: https://github.com/RobTillaart/FunctionGenerator
88
//
99

10+
1011
#include "functionGenerator.h"
1112

1213
uint32_t start;
@@ -17,6 +18,7 @@ volatile float y;
1718

1819
funcgen gen;
1920

21+
2022
void setup()
2123
{
2224
Serial.begin(115200);
@@ -87,6 +89,7 @@ void test_square()
8789
Serial.println(1000000.0 / ((stop - start) / 10000.0));
8890
}
8991

92+
9093
void test_sawtooth()
9194
{
9295
start = micros();
@@ -102,6 +105,7 @@ void test_sawtooth()
102105
Serial.println(1000000.0 / ((stop - start) / 10000.0));
103106
}
104107

108+
105109
void test_triangle()
106110
{
107111
start = micros();
@@ -117,6 +121,7 @@ void test_triangle()
117121
Serial.println(1000000.0 / ((stop - start) / 10000.0));
118122
}
119123

124+
120125
void test_sinus()
121126
{
122127
start = micros();
@@ -132,6 +137,7 @@ void test_sinus()
132137
Serial.println(1000000.0 / ((stop - start) / 10000.0));
133138
}
134139

140+
135141
void test_stair()
136142
{
137143
start = micros();
@@ -147,6 +153,7 @@ void test_stair()
147153
Serial.println(1000000.0 / ((stop - start) / 10000.0));
148154
}
149155

156+
150157
void test_random()
151158
{
152159
start = micros();
@@ -162,6 +169,7 @@ void test_random()
162169
Serial.println(1000000.0 / ((stop - start) / 10000.0));
163170
}
164171

172+
165173
void test_line()
166174
{
167175
start = micros();
@@ -177,6 +185,7 @@ void test_line()
177185
Serial.println(1000000.0 / ((stop - start) / 10000.0));
178186
}
179187

188+
180189
void test_zero()
181190
{
182191
start = micros();
@@ -192,8 +201,11 @@ void test_zero()
192201
Serial.println(1000000.0 / ((stop - start) / 10000.0));
193202
}
194203

204+
195205
void loop()
196206
{
197207
}
198208

199-
// END OF FILE
209+
210+
// -- END OF FILE --
211+

0 commit comments

Comments
 (0)