├── AD9850SPI.cpp ├── AD9850SPI.h ├── LICENCE ├── LISEZMOI.md ├── README.md ├── examples └── AD9850SPI │ └── AD9850SPI.ino ├── images ├── AD9850.png └── AD9850_connections_M2.png ├── keywords.txt └── library.properties /AD9850SPI.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************************** 2 | * Arduino library for AD9850 3 | * Created 23/08/2014 4 | * Christophe Caiveau f4goj@free.fr 5 | * Upgrade to SPI Anthony F4GOH 6 | * 7 | * This library uses the Serial Peripheral Interface (SPI) to accelerate the update 8 | * of the AD9850 from 700µs in software serial to 90µs (54µs for the deltaphase 9 | * calculation and 36µs for the transfert) 10 | * 11 | * Use this library freely 12 | * 13 | * Hardware connections : 14 | * W_CLK -> D13 arduino UNO/NANO, D52 MEGA 15 | * FQ_UD -> any pin except 10 and 12 UNO/NANO, 50 and 53 MEGA 16 | * DATA/D7 -> D11 arduino UNO/NANO, D51 MEGA 17 | * RESET -> any pin except 10 and 12 UNO/NANO, 50 and 53 MEGA 18 | * 19 | * Functions : 20 | * DDS.begin(W_CLK pin, FQ_UD pin, RESET pin); Initialize the output pins and master reset the AD9850 21 | * DDS.calibrate(frequency); Compensation of crystal oscillator frequency 22 | * DDS.setfreq(frequency,phase); frequency in Hz, phase coded on 5 bits 23 | * DDS.down(); power down mode reducing the dissipated power from 380mW to 30mW @5V 24 | * DDS.up(); wake-up the AD9850 25 | * 26 | * AD9850 datasheet at http://www.analog.com/static/imported-files/data_sheets/AD9850.pdf 27 | * 28 | *******************************************************************************************/ 29 | 30 | #include 31 | #include 32 | 33 | AD9850SPI DDS; 34 | 35 | AD9850SPI::AD9850SPI() { 36 | SPI.begin(); 37 | } 38 | 39 | void AD9850SPI::begin(int w_clk, int fq_ud, int reset) { 40 | W_CLK = w_clk; 41 | FQ_UD = fq_ud; 42 | RESET = reset; 43 | deltaphase = 0; 44 | phase = 0; 45 | calibFreq = 125000000; 46 | begin_priv(); 47 | } 48 | 49 | void AD9850SPI::begin_priv() { 50 | pinMode(W_CLK, OUTPUT); 51 | pinMode(FQ_UD, OUTPUT); 52 | pinMode(RESET, OUTPUT); 53 | 54 | SPI.setClockDivider(SPI_CLOCK_DIV4); 55 | SPI.setBitOrder(LSBFIRST); 56 | SPI.setDataMode(SPI_MODE0); 57 | 58 | pulse(RESET); 59 | pulse(W_CLK); 60 | pulse(FQ_UD); 61 | } 62 | 63 | void AD9850SPI::update() { 64 | 65 | for (int i=0; i<4; i++, deltaphase>>=8) { 66 | SPI.transfer(deltaphase & 0xFF); 67 | } 68 | SPI.transfer(phase & 0xFF); 69 | pulse(FQ_UD); 70 | } 71 | 72 | 73 | void AD9850SPI::setfreq(double f, uint8_t p) { 74 | deltaphase = f * 4294967296.0 / calibFreq; 75 | phase = p << 3; 76 | update(); 77 | } 78 | 79 | 80 | void AD9850SPI::down() { 81 | pulse(FQ_UD); 82 | SPI.transfer(0x04); 83 | pulse(FQ_UD); 84 | } 85 | 86 | 87 | void AD9850SPI::up() { 88 | update(); 89 | } 90 | 91 | 92 | void AD9850SPI::calibrate(double TrimFreq) 93 | { 94 | calibFreq = TrimFreq; 95 | } 96 | 97 | void AD9850SPI::powerOn(){ 98 | pinMode(11, OUTPUT); 99 | delay(100); 100 | wakeUp(); 101 | delay(100); 102 | update(); 103 | } 104 | 105 | void AD9850SPI::powerOff(){ 106 | pinMode(11, INPUT); 107 | } 108 | 109 | void AD9850SPI::wakeUp() 110 | { 111 | pulse(RESET); 112 | pulse(W_CLK); 113 | pulse(FQ_UD); 114 | } 115 | 116 | void AD9850SPI::pulse(int pin) { 117 | digitalWrite(pin, HIGH); 118 | digitalWrite(pin, LOW); 119 | } 120 | 121 | void AD9850SPI::vna(unsigned long DS_FTW,uint8_t Mode) { 122 | deltaphase=(double) DS_FTW; 123 | phase=Mode; 124 | update(); 125 | } 126 | -------------------------------------------------------------------------------- /AD9850SPI.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************************** 2 | * Arduino library for AD9850 3 | * Created 23/08/2014 4 | * Christophe Caiveau f4goj@free.fr 5 | * Upgrade to SPI Anthony F4GOH 6 | * 7 | * This library uses the Serial Peripheral Interface (SPI) to accelerate the update 8 | * of the AD9850 from 700µs in software serial to 90µs (54µs for the deltaphase 9 | * calculation and 36µs for the transfert) 10 | * 11 | * Use this library freely 12 | * 13 | * Hardware connections : 14 | * W_CLK -> D13 arduino UNO/NANO, D52 MEGA 15 | * FQ_UD -> any pin except 10 and 12 UNO/NANO, 50 and 53 MEGA 16 | * DATA/D7 -> D11 arduino UNO/NANO, D51 MEGA 17 | * RESET -> any pin except 10 and 12 UNO/NANO, 50 and 53 MEGA 18 | * 19 | * Functions : 20 | * DDS.begin(W_CLK pin, FQ_UD pin, RESET pin); Initialize the output pins and master reset the AD9850 21 | * DDS.calibrate(frequency); Compensation of crystal oscillator frequency 22 | * DDS.setfreq(frequency,phase); frequency in Hz, phase coded on 5 bits 23 | * DDS.down(); power down mode reducing the dissipated power from 380mW to 30mW @5V 24 | * DDS.up(); wake-up the AD9850 25 | * 26 | * AD9850 datasheet at http://www.analog.com/static/imported-files/data_sheets/AD9850.pdf 27 | * 28 | *******************************************************************************************/ 29 | 30 | 31 | #ifndef AD9850SPI_H 32 | #define AD9850SPI_H 33 | #include 34 | 35 | class AD9850SPI 36 | { 37 | public: 38 | AD9850SPI(); 39 | 40 | void begin(int w_clk, int fq_ud, int reset); 41 | void setfreq(double f, uint8_t p); 42 | void down(); 43 | void up(); 44 | void calibrate(double TrimFreq); 45 | void powerOn(); 46 | void powerOff(); 47 | void vna(unsigned long DS_FTW, uint8_t Mode); 48 | 49 | private: 50 | int W_CLK; 51 | int FQ_UD; 52 | int RESET; 53 | uint32_t deltaphase; 54 | uint8_t phase; 55 | void update(); 56 | void begin_priv(); 57 | void pulse(int pin); 58 | void wakeUp(); 59 | double calibFreq; 60 | }; 61 | 62 | extern AD9850SPI DDS; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /LISEZMOI.md: -------------------------------------------------------------------------------- 1 | # Librairie Arduino SPI pour AD9850 # 2 | F4GOJ Christophe f4goj@free.fr 3 | 4 | Août 2014 5 | 6 | Mise à jour vers SPI par F4GOH Anthony f4goh@orange.fr 7 | 8 | Cette librairie utilise l'Interface de Périphérique Série (SPI) pour accélérer la mise à jour de l'AD9850 de 700µs par la liaison série logicielle à 90µs (54µs pour le calcul du mot deltaphase et 36µs pour le transfert) 9 | 10 | Documentation de l'AD9850 à http://www.analog.com/static/imported-files/data_sheets/AD9850.pdf 11 | 12 | Utilisez cette librairie librement. 13 | 14 | ## Installation ## 15 | Pour utiliser la librairie **AD9850SPI** : 16 | - Allez à https://github.com/F4GOJ/AD9850SPI, cliquez le bouton [Download ZIP](https://github.com/F4GOJ/AD9850SPI/archive/master.zip) et enregistrez le fichier ZIP à l'endroit de votre convenance. 17 | - Décompressez le fichier. Vous obtiendrez un répertoire contenant tous les fichiers de la librairie avec un nom comprenant le nom de branche, typiquement **AD9850SPI-master**. 18 | - Renommez le répertoire en **AD9850SPI**. 19 | - Copiez le répertoire renommé dans le répertoire Arduino \libraries. 20 | 21 | 22 | ## Notes d'utilisation## 23 | 24 | La librairie **AD9850SPI** crée une instance de l'objet **DDS**, l'utilisateur n'a pas pas besoin de le faire. 25 | 26 | Pour utiliser la librairie **AD9850SPI**, la librairie SPI doit être incluse. 27 | 28 | ```c++ 29 | #include //http://github.com/F4GOJ/AD9850SPI 30 | #include //http://arduino.cc/en/Reference/SPI (incluse dans l'IDE Arduino) 31 | ``` 32 | ## Connexions : ## 33 | 34 | ![ad9850](https://raw.githubusercontent.com/F4GOJ/AD9850SPI/master/images/AD9850.png) 35 | 36 | - W_CLK -> 13 arduino UNO/NANO, D52 MEGA. 37 | - FQ_UD -> n'importe quelle broche exceptées les 10 et 12 sur un UNO/NANO, 50 et 53 sur un MEGA. 38 | - DATA/D7 -> 11 arduino UNO/NANO, D51 MEGA. 39 | - RESET -> n'importe quelle broche exceptées les 10 et 12 sur un UNO/NANO, 50 et 53 sur un MEGA. 40 | 41 | ## Fonctions : ## 42 | 43 | ###begin(int w_clk_pin, int fq_ud_pin, int reset_pin) 44 | #####Description 45 | Initialise les broches de sortie et effectue une remise à zéro générale de l'AD9850. 46 | #####Syntaxe 47 | `DDS.begin(w_clk, fq_ud, reset);` 48 | #####Paramètres 49 | **w_clk :** Broche de sortie SPI SCK (13 sur un UNO/NANO, 52 sur un MEGA) *(int)*
50 | **fq_ud :** Broche de sortie de mise à jour de la fréquence, n'importe quelle broche exceptées les 10 et 12 sur un UNO/NANO, 50 et 53 sur un MEGA. *(int)*
51 | **reset :** Broche de sortie de RàZ, n'importe quelle broche exceptées les 10 et 12 sur un UNO/NANO, 50 et 53 sur un MEGA. *(int)* 52 | #####Retourne 53 | Rien. 54 | #####Exemple 55 | ```c++ 56 | void setup(){ 57 | DDS.begin(13, 8, 9); 58 | } 59 | ``` 60 | ###calibrate(double trim_frequency) 61 | #####Description 62 | Compensation de la féquence de l'oscillateur.
63 | Peut être utilisée à n'importe quel moment après l'initialisation. 64 | #####Syntaxe 65 | `DDS.calibrate(trim_freq);` 66 | #####Paramètres 67 | **trim_freq :** Ajuster autour de 125000000 pour correspondre à la fréquence réelle de l'oscillateur. *(double)* 68 | #####Retourne 69 | Rien. 70 | #####Exemple 71 | ```c++ 72 | void setup(){ 73 | DDS.begin(13, 8, 9); 74 | } 75 | 76 | void loop(){ 77 | DDS.calibrate(124999000); 78 | } 79 | ``` 80 | ###setfreq(double frequency, int phase) 81 | #####Description 82 | Détermine la fréquence de sortie de l'AD9850 et la phase du signal. 83 | #####Syntaxe 84 | `DDS.setfreq(frequency, phase);` 85 | #####Paramètres 86 | **frequency :** Fréquence de sortie en HZ. *(double)*
87 | **phase :** Phase du signal, codée sur 5 bits permet 32 pas de phase de 11,25° *(int)* 88 | #####Retourne 89 | Rien. 90 | #####Exemple 91 | ```c++ 92 | double frequency = 10000000; 93 | int phase = 0; 94 | DDS.setfreq(frequency, phase); 95 | ``` 96 | ###down() 97 | #####Description 98 | Mode "extinction" réduisant la puissance dissipée de 380mW à 30mW sous 5V 99 | #####Syntaxe 100 | `DDS.down();` 101 | #####Paramètres 102 | Aucun. 103 | #####Retourne 104 | Rien. 105 | #####Exemple 106 | ```c++ 107 | DDS.down(); 108 | ``` 109 | ###up() 110 | #####Description 111 | Sort l'AD9850 du mode "extinction" 112 | #####Syntaxe 113 | `DDS.up();` 114 | #####Paramètres 115 | Aucun. 116 | #####Retourne 117 | Rien. 118 | #####Exemple 119 | ```c++ 120 | DDS.down(); // Entrée en mode "extinction" 121 | 122 | // du code faisant quelquechose 123 | 124 | ... 125 | 126 | DDS.up(); // REVEIL !!! :) 127 | ``` 128 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arduino SPI library for AD9850 # 2 | F4GOJ Christophe f4goj@free.fr 3 | 4 | August 2014 5 | 6 | Upgrade to SPI F4GOH Anthony f4goh@orange.fr 7 | 8 | This library uses the Serial Peripheral Interface (SPI) to accelerate the update of the AD9850 from 700µs in software serial to 90µs (54µs for the deltaphase calculation and 36µs for the transfert) 9 | 10 | AD9850 datasheet at http://www.analog.com/static/imported-files/data_sheets/AD9850.pdf 11 | 12 | Use this library freely. 13 | 14 | ## Installation ## 15 | To use the **AD9850SPI** library: 16 | - Go to https://github.com/F4GOJ/AD9850SPI, click the [Download ZIP](https://github.com/F4GOJ/AD9850SPI/archive/master.zip) button and save the ZIP file to a convenient location on your PC. 17 | - Uncompress the downloaded file. This will result in a folder containing all the files for the library, that has a name that includes the branch name, usually **AD9850SPI-master**. 18 | - Rename the folder to **AD9850SPI**. 19 | - Copy the renamed folder to the Arduino sketchbook\libraries folder. 20 | 21 | 22 | ## Usage notes ## 23 | 24 | The **AD9850SPI** library instantiates a **DDS** object, the user does not need to do this. 25 | 26 | To use the **AD9850SPI** library, the SPI library must also be included. 27 | 28 | ```c++ 29 | #include //http://github.com/F4GOJ/AD9850SPI 30 | #include //http://arduino.cc/en/Reference/SPI (included with Arduino IDE) 31 | ``` 32 | ## Hardware connections : ## 33 | 34 | ![ad9850](https://raw.githubusercontent.com/F4GOJ/AD9850SPI/master/images/AD9850.png)![ad9850_2](https://raw.githubusercontent.com/F4GOJ/AD9850SPI/master/images/AD9850_connections_M2.png) 35 | - W_CLK -> D13 arduino UNO/NANO, D52 MEGA 36 | - FQ_UD -> any pin except 10 and 12 UNO/NANO, 50 and 53 MEGA 37 | - DATA/D7 -> D11 arduino UNO/NANO, D51 MEGA 38 | - RESET -> any pin except 10 and 12 UNO/NANO, 50 and 53 MEGA 39 | 40 | ## Functions : ## 41 | 42 | ### begin(int w_clk_pin, int fq_ud_pin, int reset_pin) 43 | ##### Description 44 | Initialize the output pins and master reset the AD9850 45 | ##### Syntax 46 | `DDS.begin(w_clk, fq_ud, reset);` 47 | ##### Parameters 48 | **w_clk :** SPI SCK output pin (13 on a UNO/NANO, 52 on a MEGA) *(int)*
49 | **fq_ud :** Frequency update pin, any pin except 10 and 12 UNO/NANO, 50 and 53 MEGA. *(int)*
50 | **reset :** Reset output pin, any pin except 10 and 12 UNO/NANO, 50 and 53 MEGA. *(int)* 51 | ##### Returns 52 | None. 53 | ##### Example 54 | ```c++ 55 | void setup(){ 56 | DDS.begin(13, 8, 9); 57 | } 58 | ``` 59 | ### calibrate(double trim_frequency) 60 | ##### Description 61 | Compensation of crystal oscillator frequency.
62 | Can be used at any time after initialization. 63 | ##### Syntax 64 | `DDS.calibrate(trim_freq);` 65 | ##### Parameters 66 | **trim_freq :** Adjust around 125000000 to match the real crystal oscillator frequency. *(double)* 67 | ##### Returns 68 | None. 69 | ##### Example 70 | ```c++ 71 | void setup(){ 72 | DDS.begin(13, 8, 9); 73 | } 74 | 75 | void loop(){ 76 | DDS.calibrate(124999000); 77 | } 78 | ``` 79 | ### setfreq(double frequency, int phase) 80 | ##### Description 81 | Sets the output frequency of the AD9850 and the phase of the signal. 82 | ##### Syntax 83 | `DDS.setfreq(frequency, phase);` 84 | ##### Parameters 85 | **frequency :** Output frequency in Hz. *(double)*
86 | **phase :** Sets the phase of the output signal, coded on 5 bits allows 32 phase steps of 11,25° each. *(int)* 87 | ##### Returns 88 | None. 89 | ##### Example 90 | ```c++ 91 | double frequency = 10000000; 92 | int phase = 0; 93 | DDS.setfreq(frequency, phase); 94 | ``` 95 | ### down() 96 | ##### Description 97 | Power down mode reducing the dissipated power from 380mW to 30mW at 5V 98 | ##### Syntax 99 | `DDS.down();` 100 | ##### Parameters 101 | None. 102 | ##### Returns 103 | None. 104 | ##### Example 105 | ```c++ 106 | DDS.down(); 107 | ``` 108 | ### up() 109 | ##### Description 110 | Wakes-up the AD9850 from power down mode. 111 | ##### Syntax 112 | `DDS.up();` 113 | ##### Parameters 114 | None. 115 | ##### Returns 116 | None. 117 | ##### Example 118 | ```c++ 119 | DDS.down(); // Entering power down mode 120 | 121 | // some code doing something 122 | 123 | ... 124 | 125 | DDS.up(); // WAKE-UP !!! :) 126 | ``` 127 | 128 | -------------------------------------------------------------------------------- /examples/AD9850SPI/AD9850SPI.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int W_CLK_PIN = 13; 5 | const int FQ_UD_PIN = 8; 6 | const int RESET_PIN = 9; 7 | 8 | double freq = 10000000; 9 | double trimFreq = 124999500; 10 | 11 | int phase = 0; 12 | 13 | void setup(){ 14 | DDS.begin(W_CLK_PIN, FQ_UD_PIN, RESET_PIN); 15 | DDS.calibrate(trimFreq); 16 | } 17 | 18 | void loop(){ 19 | DDS.setfreq(freq, phase); 20 | delay(10000); 21 | DDS.down(); 22 | delay(3000); 23 | DDS.up(); 24 | delay(2000); 25 | DDS.setfreq(freq + 500, phase); 26 | delay(5000); 27 | DDS.down(); 28 | while(1); 29 | } 30 | -------------------------------------------------------------------------------- /images/AD9850.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/F4GOJ/AD9850SPI/1ac8a4a0cd02d6fec7e54d3a74c8c2eb5f691119/images/AD9850.png -------------------------------------------------------------------------------- /images/AD9850_connections_M2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/F4GOJ/AD9850SPI/1ac8a4a0cd02d6fec7e54d3a74c8c2eb5f691119/images/AD9850_connections_M2.png -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For AD9850SPI 3 | ####################################### 4 | ####################################### 5 | # Datatypes (KEYWORD1) 6 | ####################################### 7 | 8 | AD9850SPI KEYWORD1 9 | DDS KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | calibrate KEYWORD2 17 | setfreq KEYWORD2 18 | down KEYWORD2 19 | up KEYWORD2 20 | 21 | ####################################### 22 | # Constants (LITERAL1) 23 | ####################################### 24 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=AD9850SPI 2 | version=1.0.2 3 | author=F4GOJ 4 | maintainer=F4GOJ 5 | sentence=Arduino SPI library for AD9850 6 | paragraph=This library uses the Serial Peripheral Interface (SPI) to accelerate the update of the AD9850 from 700µs in software serial to 90µs (54µs for the deltaphase calculation and 36µs for the transfert) 7 | category=Other 8 | url=http://github.com/F4GOJ/AD9850SPI 9 | architectures=* 10 | --------------------------------------------------------------------------------