Libreria del modulo generador de seniales

Dependents:   Graficador_De_Bode_OTERO-OSSO_PPs2018

Files at this revision

API Documentation at this revision

Comitter:
JAgustinOtero
Date:
Thu Dec 06 00:08:12 2018 +0000
Commit message:
funciones para el generador de seniales

Changed in this revision

AD9833.cpp Show annotated file Show diff for this revision Revisions of this file
AD9833.h Show annotated file Show diff for this revision Revisions of this file
README.txt Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 1bc0260fa422 AD9833.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AD9833.cpp	Thu Dec 06 00:08:12 2018 +0000
@@ -0,0 +1,75 @@
+/////////////////////////////////////////////////////////////////////////
+// AD9833 control code
+// Create by Po-Cheng Chen 07-04-2014
+// Version 0.1
+/////////////////////////////////////////////////////////////////////////
+
+#include "mbed.h"
+#include "SPI.h"
+#include "DigitalOut.h"
+#include "AD9833.h"
+SPI AD9833_SPI(PTD6, PTD7, PTD5); //mosi, miso, sclk --> don't need MISO
+DigitalOut fSync(PTE1); //use p8 as FSync data pin (same as chip select)
+
+/////////////////////////////////////////////////////////////////////////
+// SPI initialization
+/////////////////////////////////////////////////////////////////////////
+void SPI_INITIALIZATION()
+{
+    //Setup the spi for 16 bit data, with 25MHz clock rate, mode 2
+    // Note: mBed is MSB first SPI protocol
+    AD9833_SPI.format(8,2);
+    AD9833_SPI.frequency(250000/*250000*/);
+    fSync = 1;
+    wait_ms(10);
+}
+/////////////////////////////////////////////////////////////////////////
+// SPI writing
+/////////////////////////////////////////////////////////////////////////
+void write_SPI(short dat,short dat2)
+{
+    fSync = 0;
+    AD9833_SPI.write(dat);
+    AD9833_SPI.write(dat2);
+    fSync = 1;
+}
+/////////////////////////////////////////////////////////////////////////
+// Set desired frequency
+// Comments:Calculate the desired frequency accrodingly
+//          Do it in Matlab or mBed?
+/////////////////////////////////////////////////////////////////////////
+void setFreq(long FREQ)
+{
+    int freq_MSB;   //define freq MSB reg value
+    int freq_LSB;   //define freq LSB reg value
+
+    long freq_cal;  //define freq calculated value
+    float freq_val = 0.00000000;    //define ferq calculate tempotary value
+
+    //calculate the frqe reg value
+    //((desired frequency)/(reference frequency)) x 0x10000000.
+    freq_val = (((float)(FREQ))/25000000);
+    freq_cal = freq_val*0x10000000;
+
+    freq_MSB = (int)((freq_cal & 0xFFFC000)>>14); // shift 14 bits
+    freq_LSB = (int)(freq_cal & 0x3FFF);
+
+    freq_MSB = freq_MSB | 0x4000;  //assign freq reg address
+    freq_LSB = freq_LSB | 0x4000;
+    ///////////////////////////////////////////////////////////////////////////////////
+  /*  //print the data from the serial port to verifiy the function
+    printf("freq_LSB 0x%x\n\r", freq_LSB);
+    //print the data from the serial port to verifiy the function
+    printf("freq_MSB 0x%x\n\r", freq_MSB);*/
+    ///////////////////////////////////////////////////////////////////////////////////
+    write_SPI(0x21 , 0x00);      //write control reg - apply reset
+          //write control reg - apply reset
+    write_SPI((freq_LSB & 0xFF00)>>8 , freq_LSB & 0x00FF);    //write freq reg - LSB
+        //write freq reg - LSB
+    write_SPI((freq_MSB & 0xFF00)>>8 , freq_MSB & 0x00FF);
+        //write freq reg - MSB
+    write_SPI(0xC0 , 0x00);      //write phase reg - 0 for now
+    
+    write_SPI(0x20 , 0x00);      //write control reg - disable reset
+    
+}
\ No newline at end of file
diff -r 000000000000 -r 1bc0260fa422 AD9833.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AD9833.h	Thu Dec 06 00:08:12 2018 +0000
@@ -0,0 +1,15 @@
+/*inicializa el SPI
+@param none
+@return none
+*/
+void SPI_INITIALIZATION(void);
+/*envia 2 tramas seguidas de 8 bits 
+@param 8 bits mas significativos, 8 bits menos significativos
+@return none
+*/
+void write_SPI(short dat,short dat2);
+/*envia la tramas necesarias para setear una frecuencia y fase deseadas
+@param frecuencia deseada
+@return none
+*/
+void setFreq(long FREQ);
\ No newline at end of file
diff -r 000000000000 -r 1bc0260fa422 README.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.txt	Thu Dec 06 00:08:12 2018 +0000
@@ -0,0 +1,2 @@
+BIBLIOTECA DE FUNCIONES PARA LA GENERACION DE SEÑALES SENOIDALES
+SU ALTERACION PODRIA PROVOCAR UNA FALLA EN LA MEDICION DE MODULO Y FASE
\ No newline at end of file