You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repository contains the *NativeDDS* library for Arduino. *NativeDDS* is a software implemented Direct Digital Synthesizer. *NativeDDS* generates sinusoidal waves for example for use in audio applications, motor drives, sine wave inverters or as a reference frequency source. The library is easy portable to other platforms.
1
+
# Native DDS Library for Arduino v1.2
2
+
This repository contains the *NativeDDS* library for Arduino. *NativeDDS* is a software implemented Direct Digital Synthesizer. *NativeDDS* generates sinusoidal waves for example for use in audio applications, motor drives, sine wave inverters or for a reference frequency source. The library is easy portable to other platforms.
3
3
4
4
## Function
5
-
The DDS frequency resolution is 32-bit. This means that the frequency can be tuned with steps of `f_update/(2^32)`, with `f_update = 1/timestep` (see below). The amplitude resolution can be set to eight bit or ten bit by defining `EIGHTBIT` or `TENBIT` in the `NativeDDS.h` file. The eight bit implementation is faster and will be precise enough for most applications.
5
+
The DDS frequency resolution is 32-bit. This means that the frequency can be tuned in steps of `f_update/(2^32)`, with `f_update = 1/timestep` (see below). The amplitude resolution can be eight bits or ten bits by choosing the class instances `DDS_8bit_xx` or `DDS_10bit_xx`. The eight bit implementation is faster and will be precise enough in most applications.
6
6
7
-
The following library classes are implemented:
7
+
The following library instance methods are implemented:
8
8
9
-
*`DDS_1Ch`
10
-
*`DDS_2Ch`
11
-
*`DDS_IQ`
12
-
*`DDS_3Ph`
9
+
*`DDS_8bit_1Ch or DDS_10bit_1Ch`
10
+
*`DDS_8bit_2Ch or DDS_10bit_2Ch`
11
+
*`DDS_8bit_IQ or DDS_10bit_IQ`
12
+
*`DDS_8bit_3Ph or DDS_10bit_3Ph`
13
13
14
-
`DDS_1Ch` is a single (output) channel DDS, `DDS_2Ch` is a dual channel DDS, `DDS_IQ` is a dual channel DDS with orthogonal outputs and `DDS_3Ph` is a three channel DDS.
14
+
The explanation below will be continued for the 8-bit case.
15
+
16
+
`DDS_8bit_1Ch` is a single (output) channel DDS, `DDS_8bit_2Ch` is a dual channel DDS, `DDS_8bit_IQ` is a dual channel DDS generating orthogonal outputs and `DDS_8bit_3Ph` is a three output channel DDS.
15
17
16
18
The following methods exists:
17
19
@@ -21,31 +23,31 @@ The following methods exists:
21
23
22
24
Initialize the class instance with the member function `begin()`. Also, `begin()` must be called each time when the frequency or phase has to be updated.
For the member function `.begin()`, the variable `frequency` is in Hz and `starting-phase` in radians. `timestep` is the loop iteration time period in seconds with which `.update()` is repeatedly invoked.
34
+
For the member function `.begin()`, the variable `frequency` is in Hz and `starting-phase` in radians. `timestep` is the loop repeating time in seconds at which `.update()` is invoked.
33
35
34
-
The following public variables are defined for the outputs:
36
+
The following public output variables are defined:
35
37
36
-
DDS_1Ch: `out1`
38
+
DDS_8bit_1Ch: `out1` and `uout1` for unsigned.
37
39
38
-
DDS_2Ch: `out1`, `out2`
40
+
DDS_8bit_2Ch: `out1`, `out2` and `uout1`, `uout2` for unsigned.
39
41
40
-
DDS_IQ: `outi`, `outq`
42
+
DDS_8bit_IQ: `outi`, `outq` and `uouti`, `uoutq` for unsigned.
41
43
42
-
DDS_3Ph: `outu`, `outv`, `outw`
44
+
DDS_8bit_3Ph: `outu`, `outv`, `outw` and `uoutu`, `uoutv`, `uoutw` for unsigned.
43
45
44
46
## Usage
45
47
* First create an instance of the library object, for example here we define *mySin*:
46
48
47
49
```
48
-
DDS_1Ch mySine;
50
+
DDS_8bit_1Ch mySine;
49
51
```
50
52
51
53
* Initialize the DDS on some place in your setup function:
@@ -60,24 +62,26 @@ void setup() {
60
62
61
63
* Call `mySine.update();` from the main loop or from an Interrupt Service Routine (ISR). Use `.update(void)` on the basis of a regular time interval to generate a jitter free output signal.
62
64
63
-
Right after the previous step, the instantaneous output value is obtained with: `int sample = mySine.out1;`
65
+
Right after the previous step, the instantaneous (unsigned) output value is obtained with: `int sample = mySine.uout1;`
64
66
65
67
```
66
68
void loop() {
67
69
...
68
70
mySine.update();
69
-
sample=mySine.out1
70
-
analogWrite(PWM_OUT, sample + 127); // add 127 to convert to unsigned.
71
+
sample=mySine.uout1
72
+
analogWrite(PWM_OUT, sample);
71
73
...
72
74
}
73
75
```
74
76
75
77
## Examples
76
-
`SineWave.ino` - Example of a single channel DDS. The time base is generated in the main loop. The maximum usable output frequency is limited to about 100Hz.
78
+
`SineWave_8bit.ino` - Example of a single channel 8-bits DDS. The time base is generated in the main loop. The maximum usable output frequency is limited to about 100Hz.
79
+
80
+
`SineWave_10bit.ino` - Example of a single channel 10-bits DDS. The time base is generated in the main loop. The maximum usable output frequency is limited to about 100Hz.
77
81
78
82
`WobblingServo.ino` - A slowly sine-wave modulated servo motor application.
79
83
80
-
`AudioGenerator.ino` - A generator for audible frequencies. A timer interrupt has been used to create a fixed time base.
84
+
`AudioGenerator.ino` - A generator for audible frequencies. A timer interrupt has been used to create the time base.
81
85
82
86
## Acknowledgement
83
87
A lot of time was saved in developing this library by using the alternative Arduino-IDE [Sloeber](https://eclipse.baeyens.it/). Sloeber is a wonderful Arduino plugin for Eclipse. Thanks to Jantje and his contributors!
0 commit comments