mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.2.3 FunctionGenerator
This commit is contained in:
parent
7eb4224bf1
commit
fa36d679ab
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: functionGenerator.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.2
|
||||
// VERSION: 0.2.3
|
||||
// PURPOSE: wave form generating functions (use with care)
|
||||
// URL: https://github.com/RobTillaart/FunctionGenerator
|
||||
//
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define FUNCTIONGENERATOR_LIB_VERSION (F("0.2.2"))
|
||||
#define FUNCTIONGENERATOR_LIB_VERSION (F("0.2.3"))
|
||||
|
||||
|
||||
class funcgen
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2015-2021 Rob Tillaart
|
||||
Copyright (c) 2015-2022 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,7 +1,6 @@
|
||||
//
|
||||
// FILE: functionGenerator.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: demo function generators
|
||||
// DATE: 2015-01-03
|
||||
// URL: https://github.com/RobTillaart/FunctionGenerator
|
||||
@ -37,7 +36,7 @@ void loop()
|
||||
// wave selection by potMeter
|
||||
// int choice = analogRead(A0) / 200;
|
||||
|
||||
float val;
|
||||
float value;
|
||||
// wait for next millisecond;
|
||||
if (millis() - lastTime > 0)
|
||||
{
|
||||
@ -45,16 +44,16 @@ void loop()
|
||||
float t = lastTime * 0.001;
|
||||
switch (choice)
|
||||
{
|
||||
case '0': val = gen.square(t); break;
|
||||
case '1': val = gen.sawtooth(t); break;
|
||||
case '2': val = gen.triangle(t); break;
|
||||
case '3': val = gen.stair(t); break;
|
||||
case '4': val = gen.sinus(t); break;
|
||||
case '5': val = gen.line(); break;
|
||||
case '6': val = gen.random(); break;
|
||||
default: val = gen.zero(); break;
|
||||
case '0': value = gen.square(t); break;
|
||||
case '1': value = gen.sawtooth(t); break;
|
||||
case '2': value = gen.triangle(t); break;
|
||||
case '3': value = gen.stair(t); break;
|
||||
case '4': value = gen.sinus(t); break;
|
||||
case '5': value = gen.line(); break;
|
||||
case '6': value = gen.random(); break;
|
||||
default: value = gen.zero(); break;
|
||||
}
|
||||
Serial.println(val);
|
||||
Serial.println(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
//
|
||||
// FILE: functionGeneratorDuoPlot.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo function generators
|
||||
// DATE: 2020-06-10
|
||||
// URL: https://github.com/RobTillaart/FunctionGenerator
|
||||
|
@ -1,7 +1,6 @@
|
||||
//
|
||||
// FILE: functionGeneratorPerformance.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: demo function generators
|
||||
// DATE: 2015-01-01
|
||||
// URL: https://github.com/RobTillaart/FunctionGenerator
|
||||
@ -24,7 +23,7 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
Serial.print("Start functionGeneratorPerformance - LIB VERSION: ");
|
||||
Serial.println(FUNCTIONGENERATOR_LIB_VERSION);
|
||||
|
||||
|
||||
Serial.println("func \t\tusec\tmax calls/sec");
|
||||
y = analogRead(A0) / 1024;
|
||||
test_square();
|
||||
|
@ -1,7 +1,6 @@
|
||||
//
|
||||
// FILE: functionGeneratorPlotter.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo function generators
|
||||
// DATE: 2020-06-10
|
||||
// URL: https://github.com/RobTillaart/FunctionGenerator
|
||||
|
@ -1,17 +1,13 @@
|
||||
//
|
||||
// FILE: functionGenerator_MCP4725.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo function generators
|
||||
// DATE: 2021-01-06
|
||||
// URL: https://github.com/RobTillaart/FunctionGenerator
|
||||
//
|
||||
// depending on the platform, the range of "smooth" sinus is limited.
|
||||
// other signals are less difficult so have a slightly larger range.
|
||||
//
|
||||
// PLATFORM RANGE Points/sec Points/period
|
||||
// UNO - 25 Hz ~1900 ~75
|
||||
// ESP32 to be tested
|
||||
// see readme.md for mac frequency table.
|
||||
//
|
||||
|
||||
|
||||
@ -21,9 +17,9 @@
|
||||
|
||||
|
||||
funcgen gen;
|
||||
float val = 0;
|
||||
float freq = 40;
|
||||
float amp = 1.0;
|
||||
float value = 0;
|
||||
float frequency = 40;
|
||||
float amplitude = 1.0;
|
||||
|
||||
// q = square
|
||||
// s = sinus
|
||||
@ -42,8 +38,8 @@ void setup()
|
||||
Serial.begin(230400);
|
||||
gen.setAmplitude(1);
|
||||
gen.setYShift(1);
|
||||
gen.setFrequency(freq);
|
||||
val = 0;
|
||||
gen.setFrequency(frequency);
|
||||
value = 0;
|
||||
|
||||
Wire.begin();
|
||||
MCP.begin();
|
||||
@ -73,23 +69,23 @@ void setup()
|
||||
switch (c)
|
||||
{
|
||||
case '+':
|
||||
freq += 0.01;
|
||||
frequency += 0.01;
|
||||
break;
|
||||
case '-':
|
||||
freq -= 0.01;
|
||||
frequency -= 0.01;
|
||||
break;
|
||||
case '*':
|
||||
freq *= 10;
|
||||
frequency *= 10;
|
||||
break;
|
||||
case '/':
|
||||
freq /= 10;
|
||||
frequency /= 10;
|
||||
break;
|
||||
case '0' ... '9':
|
||||
freq *= 10;
|
||||
freq += (c - '0');
|
||||
frequency *= 10;
|
||||
frequency += (c - '0');
|
||||
break;
|
||||
case 'c':
|
||||
freq = 0;
|
||||
frequency = 0;
|
||||
break;
|
||||
case 'A':
|
||||
break;
|
||||
@ -105,30 +101,30 @@ void setup()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
gen.setFrequency(freq);
|
||||
Serial.println(freq);
|
||||
gen.setFrequency(frequency);
|
||||
Serial.println(frequency);
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case 'q':
|
||||
val = 2047 * gen.square(t);
|
||||
value = 2047 * gen.square(t);
|
||||
break;
|
||||
case 'w':
|
||||
val = 2047 * gen.sawtooth(t);
|
||||
value = 2047 * gen.sawtooth(t);
|
||||
break;
|
||||
case 't':
|
||||
val = 2047 * gen.triangle(t);
|
||||
value = 2047 * gen.triangle(t);
|
||||
break;
|
||||
case 'r':
|
||||
val = 2047 * gen.random();
|
||||
value = 2047 * gen.random();
|
||||
break;
|
||||
default:
|
||||
case 's':
|
||||
val = 2047 * gen.sinus(t);
|
||||
value = 2047 * gen.sinus(t);
|
||||
break;
|
||||
}
|
||||
MCP.setValue(val);
|
||||
MCP.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: functionGenerator.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.2
|
||||
// VERSION: 0.2.3
|
||||
// PURPOSE: wave form generating functions (use with care)
|
||||
// URL: https://github.com/RobTillaart/FunctionGenerator
|
||||
//
|
||||
@ -16,7 +16,7 @@
|
||||
// 0.2.1 2020-12-24 Arduino-CI + unit tests
|
||||
// 0.2.2 2021-11-02 update Arduino-CI, badges
|
||||
// add mode for sawtooth and stair.
|
||||
//
|
||||
// 0.2.3 2021-12-18 update library.json, license, minor edits
|
||||
|
||||
|
||||
#include "functionGenerator.h"
|
||||
|
@ -15,8 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/FunctionGenerator"
|
||||
},
|
||||
"version": "0.2.2",
|
||||
"version": "0.2.3",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
"platforms": "*",
|
||||
"headers": "functionGenerator.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=FunctionGenerator
|
||||
version=0.2.2
|
||||
version=0.2.3
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library to generate wave forms (nummeric) for a DAC
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
# FunctionGenerator
|
||||
|
||||
Arduino library to generate (numeric) wave forms for a DAC
|
||||
Arduino library to generate (numeric) wave forms for a DAC.
|
||||
|
||||
|
||||
## Description
|
||||
@ -31,20 +31,21 @@ Indication of what performance can be expected (based upon 0.2.1 version).
|
||||
Note that the values need to be transported to a DAC or serial port too.
|
||||
Numbers based on performance example, for one single signal.
|
||||
|
||||
|
||||
| Processor | Clock | Waveform | usec/calls | max freq |
|
||||
|:-------------|---------:|:---------|-----------:|---------:|
|
||||
| Arduino UNO | 16 MHz | sawtooth | 62 | 60 Hz |
|
||||
| Arduino UNO | 16 MHz | triangle | 74 | 50 Hz |
|
||||
| Arduino UNO | 16 MHz | sawtooth | 62 | 60 Hz |
|
||||
| Arduino UNO | 16 MHz | triangle | 74 | 50 Hz |
|
||||
| Arduino UNO | 16 MHz | square | 53 | 1000 Hz |
|
||||
| Arduino UNO | 16 MHz | sinus | 164 | 25 Hz |
|
||||
| Arduino UNO | 16 MHz | stair | 81 | 50 Hz |
|
||||
| Arduino UNO | 16 MHz | sinus | 164 | 25 Hz |
|
||||
| Arduino UNO | 16 MHz | stair | 81 | 50 Hz |
|
||||
| Arduino UNO | 16 MHz | random | 37 | 1000 Hz |
|
||||
| | | | | |
|
||||
| ESP32 | 240 MHz | sawtooth | 3.8 | 1000 Hz |
|
||||
| ESP32 | 240 MHz | triangle | 3.9 | 1000 Hz |
|
||||
| ESP32 | 240 MHz | square | 2.8 | 1000 Hz |
|
||||
| ESP32 | 240 MHz | sinus | 13.6 | 250 Hz |
|
||||
| ESP32 | 240 MHz | stair | 4.8 | 800 Hz |
|
||||
| ESP32 | 240 MHz | sinus | 13.6 | 250 Hz |
|
||||
| ESP32 | 240 MHz | stair | 4.8 | 800 Hz |
|
||||
| ESP32 | 240 MHz | random | 1.3 | 1000 Hz |
|
||||
|
||||
|
||||
@ -52,7 +53,8 @@ Numbers based on performance example, for one single signal.
|
||||
if a rougher signal is OK, higher frequencies are possible.
|
||||
- ESP32 can do more calculations however 1000 Hz seems to be a nice
|
||||
upper limit for a software based function generator.
|
||||
- if one wants to control multiple DAC's one need to divide the numbers.
|
||||
- if one wants to control multiple DAC's one need to divide the numbers
|
||||
and round down.
|
||||
|
||||
|
||||
Note: hardware function generator https://github.com/RobTillaart/AD985X
|
||||
@ -71,7 +73,7 @@ All parameters can be set in the constructor but also later in configuration.
|
||||
- **void setPeriod(float period = 1.0)** set the period of the wave in seconds.
|
||||
- **float getPeriod()** returns the set period.
|
||||
- **void setFrequency(float frequency = 1.0)** set the frequency of the wave in Hertz (1/s).
|
||||
- **float getFrequency()** returns the set frequency.
|
||||
- **float getFrequency()** returns the set frequency in Hertz.
|
||||
- **void setAmplitude(float amplitude = 1.0)** sets the amplitude of the wave. TODO point to point?
|
||||
Setting the amplitude to 0 gives ?what?
|
||||
- **float getAmplitude()** returns the set amplitude.
|
||||
@ -92,7 +94,7 @@ t is time in seconds
|
||||
- **float sinus(float t)** sinus wave, has no duty cycle.
|
||||
- **float stair(float t, uint16_t steps = 8, uint8_t mode = 0)** mode = 0 ==> steps up, mode = 1 steps down.
|
||||
- **float random()** noise generation.
|
||||
- **float line()** constant voltage line
|
||||
- **float line()** constant voltage line. Depends on the set YShift and amplitude.
|
||||
- **float zero()** constant zero.
|
||||
|
||||
Line() and zero() are functions that can be used to drive a constant voltage from a DAC
|
||||
@ -112,6 +114,7 @@ See examples.
|
||||
- square duty-cycle (will be slower!)
|
||||
- triangle duty-cycle (makes sawtooth a special triangle)
|
||||
- trapezium wave (would merge square and triangle and sawtooth)
|
||||
- Bezier curve?
|
||||
|
||||
#### investigate
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "FUNCTIONGENERATOR_LIB_VERSION: %s\n", (char*) FUNCTIONGENERATOR_LIB_VERSION);
|
||||
}
|
||||
|
||||
unittest_teardown()
|
||||
@ -40,7 +41,6 @@ unittest_teardown()
|
||||
unittest(test_constructor)
|
||||
{
|
||||
funcgen gen;
|
||||
fprintf(stderr, "VERSION: %s\n", (char*) FUNCTIONGENERATOR_LIB_VERSION);
|
||||
|
||||
fprintf(stderr, "Default values\n");
|
||||
assertEqualFloat(1, gen.getPeriod(), 0.0001);
|
||||
@ -54,7 +54,6 @@ unittest(test_constructor)
|
||||
unittest(test_constructor_param)
|
||||
{
|
||||
funcgen gen(4, 2.5, 0.33, -0.5);
|
||||
fprintf(stderr, "VERSION: %s\n", (char*) FUNCTIONGENERATOR_LIB_VERSION);
|
||||
|
||||
fprintf(stderr, "funcgen gen(4, 2.5, 0.33, -0.5)\n");
|
||||
|
||||
@ -69,7 +68,6 @@ unittest(test_constructor_param)
|
||||
unittest(test_set_get_param)
|
||||
{
|
||||
funcgen gen;
|
||||
fprintf(stderr, "VERSION: %s\n", (char*) FUNCTIONGENERATOR_LIB_VERSION);
|
||||
|
||||
fprintf(stderr, "set get parameters\n");
|
||||
|
||||
@ -93,8 +91,7 @@ unittest(test_set_get_param)
|
||||
unittest(test_line_zero)
|
||||
{
|
||||
funcgen gen;
|
||||
fprintf(stderr, "VERSION: %s\n", (char*) FUNCTIONGENERATOR_LIB_VERSION);
|
||||
|
||||
|
||||
fprintf(stderr, "default line = 1.0 \n");
|
||||
|
||||
assertEqualFloat(1.00, gen.line(), 0.0001);
|
||||
|
Loading…
Reference in New Issue
Block a user