Skip to content

Commit cdd3ab2

Browse files
committed
0.2.5 FunctionGenerator
1 parent 7132bb7 commit cdd3ab2

File tree

20 files changed

+1354
-169
lines changed

20 files changed

+1354
-169
lines changed

libraries/FunctionGenerator/.github/workflows/arduino-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
lint:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v3
1010
- uses: arduino/arduino-lint-action@v1
1111
with:
1212
library-manager: update

libraries/FunctionGenerator/.github/workflows/arduino_test_runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v3
1212
- uses: ruby/setup-ruby@v1
1313
with:
1414
ruby-version: 2.6

libraries/FunctionGenerator/.github/workflows/jsoncheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414
- name: json-syntax-check
1515
uses: limitusus/json-syntax-check@v1
1616
with:

libraries/FunctionGenerator/CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.2.5] - 2023-03-25
10+
- add **setDutyCycle()**, **getDutyCycle()**
11+
- implement duty cycle for square(), triangle() and random()
12+
- add **seedRandom(a, b)**
13+
- add some optimizations
14+
- move code from .h to .cpp
15+
- update readme.md
16+
- update GitHub actions
17+
- update license 2023
18+
- minor edits
19+
20+
921
## [0.2.4] - 2022-11-07
1022
- add changelog.md
1123
- add rp2040 to build-CI
1224
- update readme.md
1325

14-
1526
## [0.2.3] - 2021-12-18
1627
- update library.json, license, minor edits
1728

libraries/FunctionGenerator/FunctionGenerator.h

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,66 @@
22
//
33
// FILE: functionGenerator.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.2.4
5+
// VERSION: 0.2.5
66
// PURPOSE: wave form generating functions (use with care)
77
// URL: https://github.com/RobTillaart/FunctionGenerator
8-
//
98

109

1110
#include "Arduino.h"
1211

13-
#define FUNCTIONGENERATOR_LIB_VERSION (F("0.2.4"))
12+
#define FUNCTIONGENERATOR_LIB_VERSION (F("0.2.5"))
1413

1514

1615
class funcgen
1716
{
1817
public:
1918
funcgen(float period = 1.0, float amplitude = 1.0, float phase = 0.0, float yShift = 0.0);
2019

21-
// configuration
20+
21+
/////////////////////////////////////////////////////////////
22+
//
23+
// CONFIGURATION
24+
//
2225
void setPeriod(float period = 1.0);
23-
float getPeriod() { return _period; };
24-
void setFrequency(float freq = 1.0) { setPeriod(1/freq); };
25-
float getFrequency() { return _freq1; };
26-
27-
void setAmplitude(float ampl = 1.0) { _amplitude = ampl; };
28-
float getAmplitude() { return _amplitude; };
29-
void setPhase(float phase = 0.0) { _phase = phase; };
30-
float getPhase() { return _phase; };
31-
void setYShift(float yShift = 0.0) { _yShift = yShift; };
32-
float getYShift() { return _yShift; };
33-
34-
// constant amplitude
26+
float getPeriod();
27+
28+
void setFrequency(float freq = 1.0);
29+
float getFrequency();
30+
31+
void setAmplitude(float ampl = 1.0);
32+
float getAmplitude();
33+
34+
void setPhase(float phase = 0.0);
35+
float getPhase();
36+
37+
void setYShift(float yShift = 0.0);
38+
float getYShift();
39+
40+
void setDutyCycle(float dutyCycle);
41+
float getDutyCycle();
42+
43+
void setRandomSeed(uint32_t a, uint32_t b = 314159265);
44+
45+
46+
/////////////////////////////////////////////////////////////
47+
//
48+
// FUNCTIONS
49+
//
50+
// constant amplitude
3551
float line();
36-
// constant zero for calibration
52+
// constant zero for calibration.
3753
float zero();
38-
39-
// standard wave forms
40-
float sawtooth(float t, uint8_t mode = 0);
54+
55+
// standard wave forms
56+
float sawtooth(float t, uint8_t mode = 0); // 0 ==> /|. 1 ==> sawtooth |\.
4157
float triangle(float t);
4258
float square(float t);
4359
float sinus(float t);
4460
float stair(float t, uint16_t steps = 8, uint8_t mode = 0);
61+
4562
float random();
63+
float random_DC(); // duty cycle variant. Experimental.
64+
4665

4766
private:
4867
float _period;
@@ -53,12 +72,14 @@ class funcgen
5372
float _amplitude;
5473
float _phase;
5574
float _yShift;
56-
// Marsaglia 'constants'
75+
float _dutyCycle;
76+
77+
// Marsaglia 'constants'
5778
uint32_t _m_w = 1;
58-
uint32_t _m_z = 2;
79+
uint32_t _m_z = 2;
5980
uint32_t _random();
6081
};
6182

6283

63-
// -- END OF FILE --
84+
// -- END OF FILE --
6485

libraries/FunctionGenerator/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2015-2022 Rob Tillaart
3+
Copyright (c) 2015-2023 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/FunctionGenerator/examples/functionGenerator/functionGenerator.ino

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// PURPOSE: demo function generators
55
// DATE: 2015-01-03
66
// URL: https://github.com/RobTillaart/FunctionGenerator
7-
//
87

98

109
#include "functionGenerator.h"
@@ -33,11 +32,11 @@ void loop()
3332
{
3433
choice = Serial.read();
3534
}
36-
// wave selection by potMeter
35+
// wave selection by potMeter
3736
// int choice = analogRead(A0) / 200;
3837

3938
float value;
40-
// wait for next millisecond;
39+
// wait for next millisecond;
4140
if (millis() - lastTime > 0)
4241
{
4342
lastTime = millis();
@@ -58,5 +57,5 @@ void loop()
5857
}
5958

6059

61-
// -- END OF FILE --
60+
// -- END OF FILE --
6261

libraries/FunctionGenerator/examples/functionGeneratorDuoPlot/functionGeneratorDuoPlot.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// DATE: 2020-06-10
66
// URL: https://github.com/RobTillaart/FunctionGenerator
77
//
8-
// use a Serial plotter to show the data
8+
// use a Serial plotter to show the data
99

1010

1111
#include "functionGenerator.h"
@@ -17,7 +17,9 @@ funcgen gen2;
1717
void setup()
1818
{
1919
Serial.begin(115200);
20-
// Serial.print("Start functionGeneratorPerformance - LIB VERSION: ");
20+
// Serial.println();
21+
// Serial.println(__FILE__);
22+
// Serial.print("FUNCTIONGENERATOR_LIB_VERSION: ");
2123
// Serial.println(FUNCTIONGENERATOR_LIB_VERSION);
2224

2325
gen1.setFrequency(13);
@@ -46,5 +48,5 @@ void loop()
4648
}
4749

4850

49-
// -- END OF FILE --
51+
// -- END OF FILE --
5052

libraries/FunctionGenerator/examples/functionGeneratorPerformance/functionGeneratorPerformance.ino

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// PURPOSE: demo function generators
55
// DATE: 2015-01-01
66
// URL: https://github.com/RobTillaart/FunctionGenerator
7-
//
87

98

109
#include "functionGenerator.h"
@@ -38,6 +37,8 @@ void setup()
3837
delay(10);
3938
test_random();
4039
delay(10);
40+
test_random_DC();
41+
delay(10);
4142
test_line();
4243
delay(10);
4344
test_zero();
@@ -169,6 +170,22 @@ void test_random()
169170
}
170171

171172

173+
void test_random_DC()
174+
{
175+
start = micros();
176+
for (int i = 0; i < 10000; i++)
177+
{
178+
t = gen.random_DC();
179+
}
180+
stop = micros();
181+
Serial.print(__FUNCTION__);
182+
Serial.print(":\t");
183+
Serial.print((stop - start) / 10000.0);
184+
Serial.print("\t");
185+
Serial.println(1000000.0 / ((stop - start) / 10000.0));
186+
}
187+
188+
172189
void test_line()
173190
{
174191
start = micros();
@@ -206,5 +223,5 @@ void loop()
206223
}
207224

208225

209-
// -- END OF FILE --
226+
// -- END OF FILE --
210227

0 commit comments

Comments
 (0)