Skip to content

Commit

Permalink
changed ifdef
Browse files Browse the repository at this point in the history
  • Loading branch information
M. Stokroos committed Aug 13, 2020
1 parent f5d9f74 commit b65c99c
Show file tree
Hide file tree
Showing 7 changed files with 388 additions and 370 deletions.
19 changes: 12 additions & 7 deletions examples/AudioGenerator/AudioGenerator.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
*
* File: AudioGenerator.ino
* Purpose: Native Direct Digital Synthesizer library example project
* Version: 1.0.0
* Date: 24-10-2018
* Version: 1.0.2
* Release date: 24-10-2018
* Last edit date: 10-08-2020
*
* URL: https://github.com/MartinStokroos/NativeDDS
* License: MIT License
*
* Version history:
* v1.0.0, 24 Oct 2018 - initial release
* v1.0.1, 18 Nov 2018 - some textual changes in comments
* v1.0.1, 18 Nov 2018 - textual changes in comments
* v1.0.2, 10-08-2020 - select 8-bit/10bit DDS from main c file but it does not work (yet).
*
* This sketch demonstrates the Native DDS library. Native DDS is a Direct Digital Synthesizer
* algorithm that runs in software on the Arduino. In this example, a 220Hz and a 440Hz sine wave are
Expand All @@ -27,7 +31,8 @@
*
*/

#include <NativeDDS.h> //define EIGHTBIT
//#define DDS_8BIT //Why does defining it here won't work? Now it still should be done from NativeDDS.h
#include "NativeDDS.h"

//#define DEBUG

Expand Down Expand Up @@ -83,9 +88,9 @@ void loop() {



//******************************************************************
// Timer2 ISR, running at 31372.549Hz, also the update rate of the DDS
//******************************************************************
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Timer2 ISR, running at 31372.549Hz, and is also the update rate for the DDS
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ISR(TIMER2_OVF_vect) {
#if defined(DEBUG)
digitalWriteFast(DEBUG_PIN, true); // check the loop period time and the execution time in the loop.
Expand Down
21 changes: 14 additions & 7 deletions examples/SineWave/SineWave.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/*
* File: SineWave.ino
* Purpose: Native Direct Digital Synthesizer library example project
* Version: 1.1.0
* Date: 22-10-2018
* Version: 1.1.1
* First release date: 22-10-2018
* Last edit date: 10-08-2020
*
* URL: https://github.com/MartinStokroos/NativeDDS
* License: MIT License
*
* Version history:
* v1.0.0, 22 Oct 2018 - initial release
* v1.1.0, 18 Nov 2018 - looptime=200us (5kHz). Pin3 + pin11 PWM frequency=31250Hz and the output frequency=100Hz.
* v1.1.1, 10-08-2020 - select 8-bit/10bit DDS from main c file but it does not work (yet).
*
* This sketch demonstrates the Native DDS library. Native DDS is a Direct Digital Synthesizer
* algorithm that runs in software on the Arduino. In this example the output frequency is set to 100Hz.
Expand All @@ -28,7 +32,8 @@
*
*/

#include <NativeDDS.h>
//#define DDS_8BIT //Why does defining it here won't work? Now it still should be done from NativeDDS.h
#include "NativeDDS.h"

#define LPERIOD 200 // loop period time in us. Update freq. is 5kHz
#define PWM_OUT 3 // define PWM output pin
Expand All @@ -41,6 +46,7 @@ int output;
DDS_1Ch mySine; // create instance of DDS_1Ch



void setup() {
// run once:
pinMode(PWM_OUT, OUTPUT);
Expand All @@ -57,21 +63,22 @@ void setup() {
void loop() {
// run repeatedly:

#if defined(EIGHTBIT)
#ifdef DDS_8BIT
//digitalWrite(DEBUG_PIN, HIGH); // for checking loop period time and loop execution time (signal high time)

mySine.update(); //update the DDS, measured execution time <10us

//digitalWrite(DEBUG_PIN, LOW);
analogWrite(PWM_OUT, mySine.out1 + 127); // add 127 to convert to unsigned.
#else

#elif defined (DDS_10BIT)
//digitalWrite(DEBUG_PIN, HIGH); // debugging: check loop period time and loop execution time (signal high time)

mySine.update(); // update the DDS, measured execution time <20us

//digitalWrite(DEBUG_PIN, LOW);
output = mySine.out1 + 511; // add 511 to convert to unsigned.
analogWrite(PWM_OUT, output>>2); // convert to 8-bit and write to analog out.
analogWrite(PWM_OUT, output>>2); // convert back to to 8-bit and write to analog out.
#endif

while(nextLoop > micros()); // wait until the end of the time interval
Expand Down
9 changes: 7 additions & 2 deletions examples/WobblingServo/WobblingServo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* File: WobblingServo.ino
* Purpose: Native Direct Digital Synthesizer library example project
* Version: 1.0.0
* Date: 23-10-2018
* First release date: 23-10-2018
* Last edit date: 10-08-2020
*
* URL: https://github.com/MartinStokroos/NativeDDS
* License: MIT License
*
* Version history:
* v1.0.1, 10-08-2020 - select 8-bit/10bit DDS from main c file. Does not work (yet).
*
* This sketch demonstrates the Native DDS library. Native DDS is a Direct Digital Synthesizer
* algorithm that runs in software on the Arduino. In this example the DDS sine wave output frequency
Expand All @@ -20,7 +24,8 @@
*/


#include <NativeDDS.h>
//#define DDS_8BIT //Why does defining it here won't work? Now it still should be done from NativeDDS.h
#include "NativeDDS.h"
#include <Servo.h>

#define LPERIOD 1000 // loop period time in us. In this case 1.0ms => f_clk=1kHz
Expand Down
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ update KEYWORD2
# Constants (LITERAL1)
#######################################

DDS_8BIT LITERAL1
DDS_10BIT LITERAL1
Loading

0 comments on commit b65c99c

Please sign in to comment.