Commit 41fb442f693252f658c2302add9382c99cf4f674
1 parent
09ecc607da
Exists in
master
ad9915.c et ad9915.h : normalisation des noms de fonctions
Showing 2 changed files with 243 additions and 243 deletions Inline Diff
include/ad9915.h
/* | 1 | 1 | /* | |
dds initialisation et SPI | 2 | 2 | dds initialisation et SPI | |
*/ | 3 | 3 | */ | |
4 | 4 | |||
#include <stdint.h> | 5 | 5 | #include <stdint.h> | |
#include <unistd.h> | 6 | 6 | #include <unistd.h> | |
#include <stdio.h> | 7 | 7 | #include <stdio.h> | |
#include <stdlib.h> | 8 | 8 | #include <stdlib.h> | |
#include <getopt.h> | 9 | 9 | #include <getopt.h> | |
#include <fcntl.h> | 10 | 10 | #include <fcntl.h> | |
#include <sys/ioctl.h> | 11 | 11 | #include <sys/ioctl.h> | |
#include <linux/types.h> | 12 | 12 | #include <linux/types.h> | |
#include <linux/spi/spidev.h> | 13 | 13 | #include <linux/spi/spidev.h> | |
/* memory management */ | 14 | 14 | /* memory management */ | |
#include <sys/mman.h> | 15 | 15 | #include <sys/mman.h> | |
#include "spi.h" | 16 | 16 | #include "spi.h" | |
#include <string.h> | 17 | 17 | #include <string.h> | |
#include <math.h> | 18 | 18 | #include <math.h> | |
#include <time.h> | 19 | 19 | #include <time.h> | |
20 | 20 | |||
21 | 21 | |||
static const char CFRAddress[] = {0x00,0x01,0x02,0x03}; | 22 | 22 | static const char CFRAddress[] = {0x00,0x01,0x02,0x03}; | |
23 | 23 | |||
static const char CFR1Start[] ={0x00, 0x01, 0x00, 0x0a}; | 24 | 24 | static const char CFR1Start[] ={0x00, 0x01, 0x00, 0x0a}; | |
//static const char CFR1Start[] ={0x00, 0x01, 0x01, 0x08}; //with osk enable | 25 | 25 | //static const char CFR1Start[] ={0x00, 0x01, 0x01, 0x08}; //with osk enable | |
static const char CFR2Start[] ={0x00, 0x80, 0x09, 0x00}; //0x80 enable prof mode | 26 | 26 | static const char CFR2Start[] ={0x00, 0x80, 0x09, 0x00}; //0x80 enable prof mode | |
static const char CFR3Start[] = {0x00, 0x00, 0x19, 0x1C}; | 27 | 27 | static const char CFR3Start[] = {0x00, 0x00, 0x19, 0x1C}; | |
static const char CFR4Start[] = {0x00, 0x05, 0x21, 0x20}; | 28 | 28 | static const char CFR4Start[] = {0x00, 0x05, 0x21, 0x20}; | |
//static const char CFR4Start[] = {0x20, 0x21, 0x05, 0x00}; | 29 | 29 | //static const char CFR4Start[] = {0x20, 0x21, 0x05, 0x00}; | |
30 | 30 | |||
31 | 31 | |||
static const char USR0Address = 0x1B; | 32 | 32 | static const char USR0Address = 0x1B; | |
static const char FTW0Address = 0x0b; //profile 0 ftw | 33 | 33 | static const char FTW0Address = 0x0b; //profile 0 ftw | |
static const char PA0Address = 0x0c; //profile 0 | 34 | 34 | static const char PA0Address = 0x0c; //profile 0 | |
35 | 35 | |||
static const char DACCalEnable[] = {0x01, 0x05, 0x21, 0x20}; //Command to enable the DAC Cal, should be 0x01XXXXXX, where X is the last 6 digits of CFR4Start | 36 | 36 | static const char DACCalEnable[] = {0x01, 0x05, 0x21, 0x20}; //Command to enable the DAC Cal, should be 0x01XXXXXX, where X is the last 6 digits of CFR4Start | |
37 | 37 | |||
38 | 38 | |||
void Send_Reset(int f_dds); | 39 | 39 | void Send_Reset(int f_dds); | |
void Send_IO_Update (int f_dds); //Send the update to set the control registers | 40 | 40 | void Send_IO_Update (int f_dds); //Send the update to set the control registers | |
void write_register (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0); | 41 | 41 | void write_register (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0); | |
void read_register (int fd, unsigned char addr, uint32_t *readword); | 42 | 42 | void read_register (int fd, unsigned char addr, uint32_t *readword); | |
void read_register_ini (int fd,unsigned char addr); | 43 | 43 | void read_register_ini (int fd,unsigned char addr); | |
void Initialize_DDS (int fd, int f_dds); | 44 | 44 | void Initialize_DDS (int fd, int f_dds); | |
void Calibrate_DAC(int fd, int f_dds); | 45 | 45 | void Calibrate_DAC(int fd, int f_dds); | |
void basic_setup(int fd, int f_dds, uint16_t ampWord, uint16_t phaseWord); | 46 | 46 | void basic_setup(int fd, int f_dds, uint16_t ampWord, uint16_t phaseWord); | |
void modulus_setup(int fd, int f_dds); | 47 | 47 | void modulus_setup(int fd, int f_dds); | |
void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B); | 48 | 48 | void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B); | |
void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord); | 49 | 49 | void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord); | |
void checkSize(void); | 50 | 50 | void checkSize(void); | |
int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord); | 51 | 51 | int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord); | |
int receiveParameterFromPythonServer(char * device, double f_clk, double f_out); | 52 | 52 | int receiveParameterFromPythonServer(char * device, double f_clk, double f_out); | |
int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord); | 53 | 53 | int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord); | |
54 | 54 | |||
//------------ DRCTL | 55 | 55 | //------------ DRCTL | |
56 | 56 | |||
void Send_CTRL_UP(int fp); | 57 | 57 | void sendCtrlUp(int fp); | |
void Send_CTRL_DOWN(int fp); | 58 | 58 | void SendCtrlDown(int fp); | |
void Send_HOLD(int fp); | 59 | 59 | void SendHold(int fp); | |
void Send_UNHOLD(int fp); | 60 | 60 | void SendUnhold(int fp); | |
int testRampFreq(int fd, int f_dds, int fp); | 61 | 61 | int testRampFreq(int fd, int f_dds, int fp); | |
62 | 62 | |||
//-------Profile register mode | 63 | 63 | //-------Profile register mode | |
64 | 64 | |||
int InitialisationProfile (int fd,int f_dds); | 65 | 65 | int initialisationProfileMode (int fd,int f_dds); | |
int PutFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase); | 66 | 66 | int putFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase); | |
67 | 67 | |||
68 | 68 | |||
int PutFrequencyWord(int fd, int f_dds, double freq);//Attention uniquement valable pour fclk = 1 GHz | 69 | 69 | int putFrequencyWord(int fd, int f_dds,double fclk, double freq); | |
int PutPhaseWord(int fd, int f_dds, double phase); | 70 | 70 | int putPhaseWord(int fd, int f_dds, double phase); | |
int PutAmpWord(int fd, int f_dds, double amplitude); | 71 | 71 | int putAmpWord(int fd, int f_dds, double amplitude); | |
72 | 72 | |||
//fonctions rampes hardwres | 73 | 73 | //fonctions rampes hardwres | |
74 | 74 | |||
int FrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown); | 75 | 75 | int frequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown); | |
int ContinueFrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown); | 76 | 76 | int continueFrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown); | |
int AmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown); | 77 | 77 | int amplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown); | |
int ContinueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown); | 78 | 78 | int continueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown); | |
int PhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown); | 79 | 79 | int phaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown); | |
int ContinuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown); | 80 | 80 | int continuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown); | |
81 | 81 | |||
//fin fonctions rampes hardwares | 82 | 82 | //fin fonctions rampes hardwares | |
83 | 83 | |||
// fonctions rampes softwares | 84 | 84 | // fonctions rampes softwares | |
85 | 85 |
src/ad9915.c
/* | 1 | 1 | /* | |
SPI : initialisation du dds et communication SPI | 2 | 2 | SPI : initialisation du dds et communication SPI | |
*/ | 3 | 3 | */ | |
#include"ad9915.h" | 4 | 4 | #include"ad9915.h" | |
#include "spi.h" | 5 | 5 | #include "spi.h" | |
#include "ddsFreq.h" | 6 | 6 | #include "ddsFreq.h" | |
7 | 7 | |||
#define debug | 8 | 8 | #define debug | |
//fonction reset | 9 | 9 | //fonction reset | |
void Send_Reset(int f_dds) | 10 | 10 | void sendReset(int f_dds) | |
{ | 11 | 11 | { | |
char reset='2'; | 12 | 12 | char reset='2'; | |
write(f_dds,&reset,sizeof(reset)); //reset | 13 | 13 | write(f_dds,&reset,sizeof(reset)); //reset | |
sleep(0.1); | 14 | 14 | sleep(0.1); | |
} | 15 | 15 | } | |
16 | 16 | |||
//fonction ioupdate | 17 | 17 | //fonction ioupdate | |
void Send_IO_Update(int f_dds) | 18 | 18 | void sendIOUpdate(int f_dds) | |
{ | 19 | 19 | { | |
char update='1'; | 20 | 20 | char update='1'; | |
write(f_dds,&update,sizeof(update)); //reset | 21 | 21 | write(f_dds,&update,sizeof(update)); //reset | |
sleep(0.1); | 22 | 22 | sleep(0.1); | |
} | 23 | 23 | } | |
24 | 24 | |||
//fonction write register | 25 | 25 | //fonction write register | |
void write_register (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0) | 26 | 26 | void writeRegister (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0) | |
{ | 27 | 27 | { | |
unsigned char tx[5]={0}; | 28 | 28 | unsigned char tx[5]={0}; | |
tx[0]=addr; | 29 | 29 | tx[0]=addr; | |
tx[1]=d3; | 30 | 30 | tx[1]=d3; | |
tx[2]=d2; | 31 | 31 | tx[2]=d2; | |
tx[3]=d1; | 32 | 32 | tx[3]=d1; | |
tx[4]=d0; | 33 | 33 | tx[4]=d0; | |
//spi_put_multiple envoie le vecteur dans cet ordre | 34 | 34 | //spi_put_multiple envoie le vecteur dans cet ordre | |
//[tx0]-[tx1]-[tx2] -> adresse->bit poids Fort->bit poids faible | 35 | 35 | //[tx0]-[tx1]-[tx2] -> adresse->bit poids Fort->bit poids faible | |
spi_put_multiple(fd,tx,5,NULL,0); | 36 | 36 | spi_put_multiple(fd,tx,5,NULL,0); | |
} | 37 | 37 | } | |
38 | 38 | |||
//fonction read register | 39 | 39 | //fonction read register | |
40 | 40 | |||
void read_register (int fd,unsigned char addr, uint32_t *readword) | 41 | 41 | void readRegister (int fd,unsigned char addr, uint32_t *readword) | |
{ | 42 | 42 | { | |
unsigned char tx[1] = {0}; | 43 | 43 | unsigned char tx[1] = {0}; | |
unsigned char rx[4] = {0}; | 44 | 44 | unsigned char rx[4] = {0}; | |
addr = addr|0x80;//instruction byte for the read : 1000 0000 | byte_adress | 45 | 45 | addr = addr|0x80;//instruction byte for the read : 1000 0000 | byte_adress | |
tx[0]=addr; | 46 | 46 | tx[0]=addr; | |
spi_put_multiple(fd,tx,1,rx,4); | 47 | 47 | spi_put_multiple(fd,tx,1,rx,4); | |
//printf("TX:%x RX:%x %x %x %x\n",tx[0],rx[0],rx[1],rx[2],rx[3]); | 48 | 48 | //printf("TX:%x RX:%x %x %x %x\n",tx[0],rx[0],rx[1],rx[2],rx[3]); | |
*readword = 0x00000000; | 49 | 49 | *readword = 0x00000000; | |
*readword = *readword|(rx[0]<<24); | 50 | 50 | *readword = *readword|(rx[0]<<24); | |
*readword = *readword|(rx[1]<<16); | 51 | 51 | *readword = *readword|(rx[1]<<16); | |
*readword = *readword|(rx[2]<<8); | 52 | 52 | *readword = *readword|(rx[2]<<8); | |
*readword = *readword|rx[3]; | 53 | 53 | *readword = *readword|rx[3]; | |
} | 54 | 54 | } | |
55 | 55 | |||
//fonction read register | 56 | 56 | //fonction read register | |
void read_register_ini (int fd, unsigned char addr) | 57 | 57 | void readRegisterIni (int fd, unsigned char addr) | |
{ | 58 | 58 | { | |
unsigned char tx[1] = {0}; | 59 | 59 | unsigned char tx[1] = {0}; | |
unsigned char rx[4] = {0}; | 60 | 60 | unsigned char rx[4] = {0}; | |
addr = addr|0x80; | 61 | 61 | addr = addr|0x80; | |
tx[0]=addr; | 62 | 62 | tx[0]=addr; | |
spi_put_multiple(fd,tx,1,rx,4); | 63 | 63 | spi_put_multiple(fd,tx,1,rx,4); | |
printf("TX:%x RX:%x %x %x %x\n",tx[0],rx[0],rx[1],rx[2],rx[3]); | 64 | 64 | printf("TX:%x RX:%x %x %x %x\n",tx[0],rx[0],rx[1],rx[2],rx[3]); | |
// Send_IO_Update (f_dds); //Send the update to set the control registers | 65 | 65 | // sendIOUpdate (f_dds); //Send the update to set the control registers | |
} | 66 | 66 | } | |
67 | 67 | |||
//initialisation du dds | 68 | 68 | //initialisation du dds | |
void Initialize_DDS (int fd, int f_dds) | 69 | 69 | void initializeDDS (int fd, int f_dds) | |
{ | 70 | 70 | { | |
Send_Reset(f_dds); | 71 | 71 | sendReset(f_dds); | |
write_register(fd,CFRAddress[0],CFR1Start[0], CFR1Start[1], CFR1Start[2], CFR1Start[3]); | 72 | 72 | writeRegister(fd,CFRAddress[0],CFR1Start[0], CFR1Start[1], CFR1Start[2], CFR1Start[3]); | |
Send_IO_Update (f_dds); //Send the update to set the control registers | 73 | 73 | sendIOUpdate (f_dds); //Send the update to set the control registers | |
write_register(fd,CFRAddress[1], CFR2Start[0], CFR2Start[1], CFR2Start[2], CFR2Start[3]); | 74 | 74 | writeRegister(fd,CFRAddress[1], CFR2Start[0], CFR2Start[1], CFR2Start[2], CFR2Start[3]); | |
Send_IO_Update (f_dds); | 75 | 75 | sendIOUpdate (f_dds); | |
write_register(fd,CFRAddress[2], CFR3Start[0], CFR3Start[1], CFR3Start[2], CFR3Start[3]); | 76 | 76 | writeRegister(fd,CFRAddress[2], CFR3Start[0], CFR3Start[1], CFR3Start[2], CFR3Start[3]); | |
Send_IO_Update (f_dds); | 77 | 77 | sendIOUpdate (f_dds); | |
write_register(fd,CFRAddress[3], CFR4Start[0], CFR4Start[1], CFR4Start[2], CFR4Start[3]); | 78 | 78 | writeRegister(fd,CFRAddress[3], CFR4Start[0], CFR4Start[1], CFR4Start[2], CFR4Start[3]); | |
Send_IO_Update (f_dds); | 79 | 79 | sendIOUpdate (f_dds); | |
write_register(fd,USR0Address, 0xA2, 0x00, 0x08, 0x00); | 80 | 80 | writeRegister(fd,USR0Address, 0xA2, 0x00, 0x08, 0x00); | |
Send_IO_Update (f_dds); | 81 | 81 | sendIOUpdate (f_dds); | |
} | 82 | 82 | } | |
83 | 83 | |||
//calibration du dac | 84 | 84 | //calibration du dac | |
void Calibrate_DAC (int fd, int f_dds) | 85 | 85 | void calibrateDAC (int fd, int f_dds) | |
{ | 86 | 86 | { | |
write_register(fd,CFRAddress[3], DACCalEnable[0], DACCalEnable[1], DACCalEnable[2], DACCalEnable[3]); | 87 | 87 | writeRegister(fd,CFRAddress[3], DACCalEnable[0], DACCalEnable[1], DACCalEnable[2], DACCalEnable[3]); | |
Send_IO_Update (f_dds); | 88 | 88 | sendIOUpdate (f_dds); | |
write_register(fd,CFRAddress[3], CFR4Start[0], CFR4Start[1], CFR4Start[2], CFR4Start[3]); | 89 | 89 | writeRegister(fd,CFRAddress[3], CFR4Start[0], CFR4Start[1], CFR4Start[2], CFR4Start[3]); | |
Send_IO_Update (f_dds); | 90 | 90 | sendIOUpdate (f_dds); | |
} | 91 | 91 | } | |
92 | 92 | |||
void modulus_setup(int fd, int f_dds) | 93 | 93 | void modulusSetup(int fd, int f_dds) | |
{ | 94 | 94 | { | |
write_register(fd,0x00,0x00, 0x01, 0x01, 0x0a); //OSK enable //0x08 | 95 | 95 | writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x0a); //OSK enable //0x08 | |
//write_register(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable de base | 96 | 96 | //writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable de base | |
Send_IO_Update (f_dds); | 97 | 97 | sendIOUpdate (f_dds); | |
write_register(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp | 98 | 98 | writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp | |
Send_IO_Update (f_dds); | 99 | 99 | sendIOUpdate (f_dds); | |
} | 100 | 100 | } | |
101 | 101 | |||
void basic_setup(int fd, int f_dds,uint16_t ampWord, uint16_t phaseWord) | 102 | 102 | void basicSetup(int fd, int f_dds,uint16_t ampWord, uint16_t phaseWord) | |
{ | 103 | 103 | { | |
write_register(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable | 104 | 104 | writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable | |
Send_IO_Update (f_dds); | 105 | 105 | sendIOUpdate (f_dds); | |
write_register(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp | 106 | 106 | writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp | |
Send_IO_Update (f_dds); | 107 | 107 | sendIOUpdate (f_dds); | |
write_register(fd,0x04,0x19, 0x99, 0x99, 0x99); //ftw | 108 | 108 | writeRegister(fd,0x04,0x19, 0x99, 0x99, 0x99); //ftw | |
Send_IO_Update (f_dds); | 109 | 109 | sendIOUpdate (f_dds); | |
write_register(fd,0x05,0xC0, 0x00, 0x00, 0x00); //A | 110 | 110 | writeRegister(fd,0x05,0xC0, 0x00, 0x00, 0x00); //A | |
Send_IO_Update (f_dds); | 111 | 111 | sendIOUpdate (f_dds); | |
write_register(fd,0x06,0x00, 0x00, 0x00, 0x05); //B | 112 | 112 | writeRegister(fd,0x06,0x00, 0x00, 0x00, 0x05); //B | |
Send_IO_Update (f_dds); | 113 | 113 | sendIOUpdate (f_dds); | |
//write_register(fd,0x0c, 0x0F, 0xFF, 0x00, 0x00); // amp (12b) ph(16) | 114 | 114 | //writeRegister(fd,0x0c, 0x0F, 0xFF, 0x00, 0x00); // amp (12b) ph(16) | |
write_register(fd,0x0c, (uint8_t)((ampWord>>8) & 0x0F), (uint8_t)(ampWord & 0xFF), (uint8_t)((phaseWord>>8) & 0xFF), (uint8_t)(phaseWord & 0xFF)); // amp (12b) ph(16) | 115 | 115 | writeRegister(fd,0x0c, (uint8_t)((ampWord>>8) & 0x0F), (uint8_t)(ampWord & 0xFF), (uint8_t)((phaseWord>>8) & 0xFF), (uint8_t)(phaseWord & 0xFF)); // amp (12b) ph(16) | |
Send_IO_Update (f_dds); | 116 | 116 | sendIOUpdate (f_dds); | |
} | 117 | 117 | } | |
118 | 118 | |||
void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B) | 119 | 119 | void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B) | |
{ | 120 | 120 | { | |
//uint16_t phaseWord = 0x7400; | 121 | 121 | //uint16_t phaseWord = 0x7400; | |
//uint16_t ampWord = (uint16_t)strtol(argv[4],NULL,0) & 0x0FFF ; //masque en 2 | 122 | 122 | //uint16_t ampWord = (uint16_t)strtol(argv[4],NULL,0) & 0x0FFF ; //masque en 2 | |
//uint16_t ampWord = 0x00000FFF; | 123 | 123 | //uint16_t ampWord = 0x00000FFF; | |
//uint32_t phaseAmpWord = phaseWord | ampWord<<16; | 124 | 124 | //uint32_t phaseAmpWord = phaseWord | ampWord<<16; | |
125 | 125 | |||
//write_register(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable | 126 | 126 | //writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable | |
//Send_IO_Update(f_dds); | 127 | 127 | //sendIOUpdate(f_dds); | |
//write_register(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp | 128 | 128 | //writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp | |
//Send_IO_Update(f_dds); | 129 | 129 | //sendIOUpdate(f_dds); | |
write_register(fd,0x04,ftw>>24&0xFF, ftw>>16&0xFF, ftw>>8&0xFF, ftw&0xFF); //ftw | 130 | 130 | writeRegister(fd,0x04,ftw>>24&0xFF, ftw>>16&0xFF, ftw>>8&0xFF, ftw&0xFF); //ftw | |
Send_IO_Update(f_dds); | 131 | 131 | sendIOUpdate(f_dds); | |
write_register(fd,0x05,A>>24&0xFF,A>>16&0xFF, A>>8&0xFF, A&0xFF); //A | 132 | 132 | writeRegister(fd,0x05,A>>24&0xFF,A>>16&0xFF, A>>8&0xFF, A&0xFF); //A | |
Send_IO_Update(f_dds); | 133 | 133 | sendIOUpdate(f_dds); | |
write_register(fd,0x06,B>>24&0xFF,B>>16&0xFF, B>>8&0xFF, B&0xFF); //B | 134 | 134 | writeRegister(fd,0x06,B>>24&0xFF,B>>16&0xFF, B>>8&0xFF, B&0xFF); //B | |
Send_IO_Update(f_dds); | 135 | 135 | sendIOUpdate(f_dds); | |
// write_register(fd,0x0c, phaseAmpWord>>24&0xFF, phaseAmpWord>>16&0xFF,phaseAmpWord>>8&0xFF,phaseAmpWord&0xFF); // amp (12b) ph(16) | 136 | 136 | // writeRegister(fd,0x0c, phaseAmpWord>>24&0xFF, phaseAmpWord>>16&0xFF,phaseAmpWord>>8&0xFF,phaseAmpWord&0xFF); // amp (12b) ph(16) | |
//Send_IO_Update(f_dds); | 137 | 137 | //sendIOUpdate(f_dds); | |
} | 138 | 138 | } | |
139 | 139 | |||
void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord) | 140 | 140 | void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord) | |
{ | 141 | 141 | { | |
write_register(fd,0x0c, phaseAmpWord>>24&0xFF, phaseAmpWord>>16&0xFF,phaseAmpWord>>8&0xFF,phaseAmpWord&0xFF); // amp (12b) ph(16) | 142 | 142 | writeRegister(fd,0x0c, phaseAmpWord>>24&0xFF, phaseAmpWord>>16&0xFF,phaseAmpWord>>8&0xFF,phaseAmpWord&0xFF); // amp (12b) ph(16) | |
Send_IO_Update(f_dds); | 143 | 143 | sendIOUpdate(f_dds); | |
} | 144 | 144 | } | |
145 | 145 | |||
/* | 146 | 146 | /* | |
void getAmpPhaseWord(int fd) | 147 | 147 | void getAmpPhaseWord(int fd) | |
{ | 148 | 148 | { | |
// unsigned char rx[5]={0}; | 149 | 149 | // unsigned char rx[5]={0}; | |
unsigned char* pt; | 150 | 150 | unsigned char* pt; | |
read_register(fd,0x0c,rx); // amp (12b) ph(16) | 151 | 151 | readRegister(fd,0x0c,rx); // amp (12b) ph(16) | |
rx[0]=*pt; | 152 | 152 | rx[0]=*pt; | |
rx[1]=*(pt+1); | 153 | 153 | rx[1]=*(pt+1); | |
rx[2]=*(pt+2); | 154 | 154 | rx[2]=*(pt+2); | |
rx[3]=*(pt+3); | 155 | 155 | rx[3]=*(pt+3); | |
rx[4]=*(pt+4); | 156 | 156 | rx[4]=*(pt+4); | |
printf("%c %c %c %c %c", rx[0], rx[1], rx[2], rx[3], rx[4]); | 157 | 157 | printf("%c %c %c %c %c", rx[0], rx[1], rx[2], rx[3], rx[4]); | |
} | 158 | 158 | } | |
*/ | 159 | 159 | */ | |
void checkSize(void) | 160 | 160 | void checkSize(void) | |
{ | 161 | 161 | { | |
printf("int : %d\n",sizeof(unsigned int)); | 162 | 162 | printf("int : %d\n",sizeof(unsigned int)); | |
} | 163 | 163 | } | |
164 | 164 | |||
int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord) | 165 | 165 | int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord) | |
{ | 166 | 166 | { | |
#ifdef debug | 167 | 167 | #ifdef debug | |
printf("device=%s\tgpio_update=%s\tf_clk=%e\tf_out=%e\tampWord=%d\tphaseWord=%d\n\n",device,gpio_update,f_clk,f_out,ampWord,phaseWord); | 168 | 168 | printf("device=%s\tgpio_update=%s\tf_clk=%e\tf_out=%e\tampWord=%d\tphaseWord=%d\n\n",device,gpio_update,f_clk,f_out,ampWord,phaseWord); | |
#else | 169 | 169 | #else | |
printf("device=%s\tgpio_update=%s\tf_clk=%e\tf_out=%e\tampWord=%d\tphaseWord=%d\n\n",device,gpio_update,f_clk,f_out,ampWord,phaseWord); | 170 | 170 | printf("device=%s\tgpio_update=%s\tf_clk=%e\tf_out=%e\tampWord=%d\tphaseWord=%d\n\n",device,gpio_update,f_clk,f_out,ampWord,phaseWord); | |
int fd=configureSpi(device); //ex #define FILENAME2 "/dev/spidev0.0" | 171 | 171 | int fd=configureSpi(device); //ex #define FILENAME2 "/dev/spidev0.0" | |
printf("fd(funct)=%d\n",fd); | 172 | 172 | printf("fd(funct)=%d\n",fd); | |
setMode(fd,SPI_MODE_0); | 173 | 173 | setMode(fd,SPI_MODE_0); | |
if (fd <= 0){ | 174 | 174 | if (fd <= 0){ | |
printf("ERREUR : ouverture périphérique SPI %s\n",device); | 175 | 175 | printf("ERREUR : ouverture périphérique SPI %s\n",device); | |
return EXIT_FAILURE; | 176 | 176 | return EXIT_FAILURE; | |
} | 177 | 177 | } | |
int f_dds=open(gpio_update,O_RDWR); //ex #define UPDATE2 "/sys/dds/gpio24/updateOn" | 178 | 178 | int f_dds=open(gpio_update,O_RDWR); //ex #define UPDATE2 "/sys/dds/gpio24/updateOn" | |
printf("f_dds(funct)=%d\n",f_dds); | 179 | 179 | printf("f_dds(funct)=%d\n",f_dds); | |
if (f_dds <= 0){ | 180 | 180 | if (f_dds <= 0){ | |
printf("ERREUR : ouverture ");printf(gpio_update);printf("\n"); | 181 | 181 | printf("ERREUR : ouverture ");printf(gpio_update);printf("\n"); | |
printf("Chargez le module ddsIOupdateX\n"); | 182 | 182 | printf("Chargez le module ddsIOupdateX\n"); | |
return EXIT_FAILURE; | 183 | 183 | return EXIT_FAILURE; | |
} | 184 | 184 | } | |
setddsFreq(fd,f_dds,f_out,f_clk); | 185 | 185 | setddsFreq(fd,f_dds,f_out,f_clk); | |
//debug | 186 | 186 | //debug | |
phaseWord = 0x0000; | 187 | 187 | phaseWord = 0x0000; | |
ampWord=0x0FFF; | 188 | 188 | ampWord=0x0FFF; | |
uint32_t phaseAmpWord = phaseWord | ampWord<<16; | 189 | 189 | uint32_t phaseAmpWord = phaseWord | ampWord<<16; | |
setAmpPhaseWord(fd, f_dds, phaseAmpWord); | 190 | 190 | setAmpPhaseWord(fd, f_dds, phaseAmpWord); | |
#endif | 191 | 191 | #endif | |
return EXIT_SUCCESS; | 192 | 192 | return EXIT_SUCCESS; | |
} | 193 | 193 | } | |
194 | 194 | |||
int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord) | 195 | 195 | int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord) | |
{ | 196 | 196 | { | |
setddsFreq(fd,f_dds,f_out,f_clk); | 197 | 197 | setddsFreq(fd,f_dds,f_out,f_clk); | |
#ifdef debug | 198 | 198 | #ifdef debug | |
phaseWord = 0x0000; | 199 | 199 | phaseWord = 0x0000; | |
ampWord=0x0FFF; | 200 | 200 | ampWord=0x0FFF; | |
#endif | 201 | 201 | #endif | |
uint32_t phaseAmpWord = phaseWord | ampWord<<16; | 202 | 202 | uint32_t phaseAmpWord = phaseWord | ampWord<<16; | |
setAmpPhaseWord(fd, f_dds, phaseAmpWord); | 203 | 203 | setAmpPhaseWord(fd, f_dds, phaseAmpWord); | |
204 | 204 | |||
return EXIT_SUCCESS; | 205 | 205 | return EXIT_SUCCESS; | |
} | 206 | 206 | } | |
207 | 207 | |||
void Send_CTRL_UP(int fp) | 208 | 208 | void sendCtrlUp(int fp) | |
{ | 209 | 209 | { | |
char DRCTLOn='0';//pente positive | 210 | 210 | char DRCTLOn='0';//pente positive | |
write(fp,&DRCTLOn,sizeof(DRCTLOn)); // | 211 | 211 | write(fp,&DRCTLOn,sizeof(DRCTLOn)); // | |
sleep(0.1); | 212 | 212 | sleep(0.1); | |
} | 213 | 213 | } | |
214 | 214 | |||
void Send_CTRL_DOWN(int fp) | 215 | 215 | void sendCtrlDown(int fp) | |
{ | 216 | 216 | { | |
char DRCTLOn='2';//pente negative | 217 | 217 | char DRCTLOn='2';//pente negative | |
write(fp,&DRCTLOn,sizeof(DRCTLOn)); //reset | 218 | 218 | write(fp,&DRCTLOn,sizeof(DRCTLOn)); //reset | |
sleep(0.1); | 219 | 219 | sleep(0.1); | |
} | 220 | 220 | } | |
221 | 221 | |||
void Send_HOLD(int fp) | 222 | 222 | void sendHold(int fp) | |
{ | 223 | 223 | { | |
char DRHOLDOn ='1';//rampe bloquée | 224 | 224 | char DRHOLDOn ='1';//rampe bloquée | |
write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset | 225 | 225 | write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset | |
sleep(0.1); | 226 | 226 | sleep(0.1); | |
} | 227 | 227 | } | |
228 | 228 | |||
void Send_UNHOLD(int fp) | 229 | 229 | void sendUnhold(int fp) | |
{ | 230 | 230 | { | |
char DRHOLDOn ='3';//rampe debloquée | 231 | 231 | char DRHOLDOn ='3';//rampe debloquée | |
write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset | 232 | 232 | write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset | |
sleep(0.1); | 233 | 233 | sleep(0.1); | |
} | 234 | 234 | } | |
235 | 235 | |||
236 | 236 | |||
int testRampFreq(int fd, int f_dds, int fp) | 237 | 237 | int testRampFreq(int fd, int f_dds, int fp) | |
{ | 238 | 238 | { | |
239 | 239 | |||
240 | 240 | |||
//3-Rampe de pente positive + debloquage | 241 | 241 | //3-Rampe de pente positive + debloquage | |
Send_CTRL_DOWN(fp);//rampe up | 242 | 242 | sendCtrlDown(fp);//rampe up | |
Send_UNHOLD(fp); | 243 | 243 | sendUnhold(fp); | |
244 | 244 | |||
Send_Reset(f_dds); | 245 | 245 | sendReset(f_dds); | |
//Initialize_DDS (fd, f_dds); | 246 | 246 | //Initialize_DDS (fd, f_dds); | |
247 | 247 | |||
//0- paramètre de bases | 248 | 248 | //0- paramètre de bases | |
write_register(fd,0x00,0x00,0x01,0x01,0x0a);//OSKenable+Read&write | 249 | 249 | writeRegister(fd,0x00,0x00,0x01,0x01,0x0a);//OSKenable+Read&write | |
Send_IO_Update(f_dds); | 250 | 250 | sendIOUpdate(f_dds); | |
read_register_ini(fd,0x00); | 251 | 251 | readRegisterIni(fd,0x00); | |
252 | 252 | |||
write_register(fd,0x01,0x00, 0x00, 0x09, 0x00); // enable amp ramp | 253 | 253 | writeRegister(fd,0x01,0x00, 0x00, 0x09, 0x00); // enable amp ramp | |
Send_IO_Update(f_dds); | 254 | 254 | sendIOUpdate(f_dds); | |
read_register_ini(fd,0x00); | 255 | 255 | readRegisterIni(fd,0x00); | |
256 | 256 | |||
//1- Donner une frequence f_dds de 1.1e7 Hz sachant que f_clk=1e9 Hz; | 257 | 257 | //1- Donner une frequence f_dds de 1.1e7 Hz sachant que f_clk=1e9 Hz; | |
// => Le mot a donner est (p.19) : FTW=(f_dds/f_clk)*2³² | 258 | 258 | // => Le mot a donner est (p.19) : FTW=(f_dds/f_clk)*2³² | |
// FTW = 42949672.96 = 42 949 673. = 0x028f5c29 | 259 | 259 | // FTW = 42949672.96 = 42 949 673. = 0x028f5c29 | |
// 1.1e7 =0x02d0e560 | 260 | 260 | // 1.1e7 =0x02d0e560 | |
261 | 261 | |||
// 2d0e560 | 262 | 262 | // 2d0e560 | |
263 | 263 | |||
//Calibrate_DAC (fd,f_dds); | 264 | 264 | //Calibrate_DAC (fd,f_dds); | |
265 | 265 | |||
266 | 266 | |||
267 | 267 | |||
write_register(fd,0x0b,0x02,0xd0,0xe5,0x60);//mot de frequence | 268 | 268 | writeRegister(fd,0x0b,0x02,0xd0,0xe5,0x60);//mot de frequence | |
Send_IO_Update(f_dds); | 269 | 269 | sendIOUpdate(f_dds); | |
write_register(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle | 270 | 270 | writeRegister(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle | |
Send_IO_Update(f_dds); | 271 | 271 | sendIOUpdate(f_dds); | |
272 | 272 | |||
printf("Les mots de frequences, d'amplitudes et de phases sont envoyes\n"); | 273 | 273 | printf("Les mots de frequences, d'amplitudes et de phases sont envoyes\n"); | |
printf("Lecture registre de frequence: 0x0b\n"); | 274 | 274 | printf("Lecture registre de frequence: 0x0b\n"); | |
read_register_ini(fd,0x0b); | 275 | 275 | readRegisterIni(fd,0x0b); | |
printf("Lecture registre de amp et phase: 0x0c\n"); | 276 | 276 | printf("Lecture registre de amp et phase: 0x0c\n"); | |
read_register_ini(fd,0x0c); | 277 | 277 | readRegisterIni(fd,0x0c); | |
278 | 278 | |||
Calibrate_DAC (fd,f_dds); | 279 | 279 | Calibrate_DAC (fd,f_dds); | |
printf("\n\n ----------------------- \n\n"); | 280 | 280 | printf("\n\n ----------------------- \n\n"); | |
281 | 281 | |||
282 | 282 | |||
/* | 283 | 283 | /* | |
//2- Taille des dt | 284 | 284 | //2- Taille des dt | |
285 | 285 | |||
write_register(fd,0x08,0xFF,0xFF,0xFF,0xFF); //+dt max, -dt max (+dt = -dt) | 286 | 286 | writeRegister(fd,0x08,0xFF,0xFF,0xFF,0xFF); //+dt max, -dt max (+dt = -dt) | |
Send_IO_Update(f_dds); | 287 | 287 | sendIOUpdate(f_dds); | |
288 | 288 | |||
printf("Les mots de dt sont envoyes\n"); | 289 | 289 | printf("Les mots de dt sont envoyes\n"); | |
printf("Lecture dans le registre 0x08 : taille dt\n"); | 290 | 290 | printf("Lecture dans le registre 0x08 : taille dt\n"); | |
read_register_ini (fd,0x08); | 291 | 291 | readRegisterIni (fd,0x08); | |
292 | 292 | |||
293 | 293 | |||
294 | 294 | |||
295 | 295 | |||
printf("\n\n ----------------------- \n\n"); | 296 | 296 | printf("\n\n ----------------------- \n\n"); | |
297 | 297 | |||
298 | 298 | |||
//3- STEP SIZE :dphi | 299 | 299 | //3- STEP SIZE :dphi | |
300 | 300 | |||
// en theorie dphi =2.25e-28 degrees | 301 | 301 | // en theorie dphi =2.25e-28 degrees | |
write_register(fd,0x06,0x00,0x00,0x00,0x01); | 302 | 302 | writeRegister(fd,0x06,0x00,0x00,0x00,0x01); | |
Send_IO_Update(f_dds); | 303 | 303 | sendIOUpdate(f_dds); | |
304 | 304 | |||
write_register(fd,0x07,0x00,0x00,0x00,0x01); | 305 | 305 | writeRegister(fd,0x07,0x00,0x00,0x00,0x01); | |
Send_IO_Update(f_dds); | 306 | 306 | sendIOUpdate(f_dds); | |
307 | 307 | |||
//printf("\n\n ----------------------- \n\n"); | 308 | 308 | //printf("\n\n ----------------------- \n\n"); | |
printf("Les mots de dphi sont envoyes\n"); | 309 | 309 | printf("Les mots de dphi sont envoyes\n"); | |
printf("Lecture dans les registres 0x06 et 0x07 : taille dt\n"); | 310 | 310 | printf("Lecture dans les registres 0x06 et 0x07 : taille dt\n"); | |
read_register_ini (fd,0x06); | 311 | 311 | readRegisterIni (fd,0x06); | |
read_register_ini (fd,0x07); | 312 | 312 | readRegisterIni (fd,0x07); | |
313 | 313 | |||
printf("\n\n ----------------------- \n\n"); | 314 | 314 | printf("\n\n ----------------------- \n\n"); | |
//4- Ecrire les extremums de la rampe | 315 | 315 | //4- Ecrire les extremums de la rampe | |
316 | 316 | |||
write_register(fd,0x04,0x00,0x00,0x00,0x01);//0 rad | 317 | 317 | writeRegister(fd,0x04,0x00,0x00,0x00,0x01);//0 rad | |
Send_IO_Update(f_dds); | 318 | 318 | sendIOUpdate(f_dds); | |
write_register(fd,0x05,0xFF,0xFF,0xFF,0xFF);//2*pi rad | 319 | 319 | writeRegister(fd,0x05,0xFF,0xFF,0xFF,0xFF);//2*pi rad | |
Send_IO_Update(f_dds); | 320 | 320 | sendIOUpdate(f_dds); | |
321 | 321 | |||
printf("Les mots des frontieres sont envoyes\n"); | 322 | 322 | printf("Les mots des frontieres sont envoyes\n"); | |
printf("Lecture dans les registres 0x04 et 0x05 : taille dt\n"); | 323 | 323 | printf("Lecture dans les registres 0x04 et 0x05 : taille dt\n"); | |
read_register_ini (fd,0x04); | 324 | 324 | readRegisterIni (fd,0x04); | |
read_register_ini (fd,0x05); | 325 | 325 | readRegisterIni (fd,0x05); | |
326 | 326 | |||
327 | 327 | |||
//3-Rampe de pente positive ou négative | 328 | 328 | //3-Rampe de pente positive ou négative | |
// Send_CTRL_UP(fp);//rampe up | 329 | 329 | // Send_CTRL_UP(fp);//rampe up | |
330 | 330 | |||
331 | 331 | |||
//4-ecriture dans le registre 0x01 | 332 | 332 | //4-ecriture dans le registre 0x01 | |
write_register(fd,0x01,0x00, 0xa8, 0x09, 0x00); // enable amp ramp | 333 | 333 | writeRegister(fd,0x01,0x00, 0xa8, 0x09, 0x00); // enable amp ramp | |
Send_IO_Update(f_dds); | 334 | 334 | sendIOUpdate(f_dds); | |
335 | 335 | |||
printf("Lecture dans le registre 0x01 : \n"); | 336 | 336 | printf("Lecture dans le registre 0x01 : \n"); | |
read_register_ini (fd,0x01); | 337 | 337 | readRegisterIni (fd,0x01); | |
// printf("Les mots de dt sont envoyes\n"); | 338 | 338 | // printf("Les mots de dt sont envoyes\n"); | |
printf("Lecture dans le registre 0x08 : taille dt\n"); | 339 | 339 | printf("Lecture dans le registre 0x08 : taille dt\n"); | |
read_register_ini (fd,0x08); | 340 | 340 | readRegisterIni (fd,0x08); | |
341 | 341 | |||
342 | 342 | |||
*/ | 343 | 343 | */ | |
return EXIT_SUCCESS; | 344 | 344 | return EXIT_SUCCESS; | |
} | 345 | 345 | } | |
346 | 346 | |||
//---------------rajout 8/1 | 347 | 347 | //---------------rajout 8/1 | |
348 | 348 | |||
int PutAmpWord(int fd, int f_dds, double amplitude) | 349 | 349 | int putAmpWord(int fd, int f_dds, double amplitude) | |
{ | 350 | 350 | { | |
uint16_t PhaseWord = 0x0000; | 351 | 351 | uint16_t PhaseWord = 0x0000; | |
uint16_t AmpWord = 0x0000; | 352 | 352 | uint16_t AmpWord = 0x0000; | |
uint32_t ReadPhaseAmpWord=0x00000000; | 353 | 353 | uint32_t ReadPhaseAmpWord=0x00000000; | |
354 | 354 | |||
AmpWord = rint(amplitude*(pow(2.0,12.0)-1)/100); | 355 | 355 | AmpWord = rint(amplitude*(pow(2.0,12.0)-1)/100); | |
356 | 356 | |||
read_register(fd,0x0c,&ReadPhaseAmpWord); | 357 | 357 | readRegister(fd,0x0c,&ReadPhaseAmpWord); | |
358 | 358 | |||
PhaseWord = ReadPhaseAmpWord&0xFFFF; | 359 | 359 | PhaseWord = ReadPhaseAmpWord&0xFFFF; | |
360 | 360 | |||
write_register(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); | 361 | 361 | writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); | |
Send_IO_Update(f_dds); | 362 | 362 | sendIOUpdate(f_dds); | |
363 | 363 | |||
return 0; | 364 | 364 | return 0; | |
} | 365 | 365 | } | |
366 | 366 | |||
367 | 367 | |||
int PutPhaseWord(int fd, int f_dds, double phase) | 368 | 368 | int putPhaseWord(int fd, int f_dds, double phase) | |
{ | 369 | 369 | { | |
uint16_t PhaseWord = 0x0000; | 370 | 370 | uint16_t PhaseWord = 0x0000; | |
uint16_t AmpWord = 0x0000; | 371 | 371 | uint16_t AmpWord = 0x0000; | |
uint32_t ReadPhaseAmpWord=0x00000000; | 372 | 372 | uint32_t ReadPhaseAmpWord=0x00000000; | |
373 | 373 | |||
PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360); | 374 | 374 | PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360); | |
375 | 375 | |||
read_register(fd,0x0c,&ReadPhaseAmpWord); | 376 | 376 | readRegister(fd,0x0c,&ReadPhaseAmpWord); | |
377 | 377 | |||
AmpWord = ReadPhaseAmpWord>>16&0xFFFF; | 378 | 378 | AmpWord = ReadPhaseAmpWord>>16&0xFFFF; | |
379 | 379 | |||
write_register(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); | 380 | 380 | writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); | |
Send_IO_Update(f_dds); | 381 | 381 | sendIOUpdate(f_dds); | |
382 | 382 | |||
return 0; | 383 | 383 | return 0; | |
} | 384 | 384 | } | |
385 | 385 | |||
int PutFrequencyWord(int fd, int f_dds, double fout)//Attention uniquement valable pour fclk = 1 GHz | 386 | 386 | int putFrequencyWord(int fd, int f_dds, double fclk,double fout)//Attention uniquement valable pour fclk = 1 GHz | |
{ | 387 | 387 | { | |
388 | 388 | |||
uint32_t FTWR = 0x00000000; | 389 | 389 | uint32_t FTWR = 0x00000000; | |
FTWR = rint((fout/1e9)*pow(2.0,32.0)); | 390 | 390 | FTWR = rint((fout/fclk)*pow(2.0,32.0)); | |
write_register(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence | 391 | 391 | writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence | |
Send_IO_Update(f_dds); | 392 | 392 | sendIOUpdate(f_dds); | |
393 | 393 | |||
return 0; | 394 | 394 | return 0; | |
} | 395 | 395 | } | |
396 | 396 | |||
397 | 397 | |||
int PutFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase)//n'existe pas dans le mode profile enable | 398 | 398 | int putFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase)//n'existe pas dans le mode profile enable | |
{ | 399 | 399 | { | |
400 | 400 | |||
uint32_t FTWR = 0x00000000; | 401 | 401 | uint32_t FTWR = 0x00000000; | |
402 | 402 | |||
FTWR = rint((fout/fclk)*pow(2.0,32.0)); | 403 | 403 | FTWR = rint((fout/fclk)*pow(2.0,32.0)); | |
404 | 404 | |||
write_register(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence | 405 | 405 | writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence | |
406 | 406 | |||
Send_IO_Update(f_dds); | 407 | 407 | sendIOUpdate(f_dds); | |
408 | 408 | |||
// write_register(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle | 409 | 409 | // writeRegister(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle | |
// Send_IO_Update(f_dds); | 410 | 410 | // sendIOUpdate(f_dds); | |
411 | 411 | |||
PutPhaseWord(fd,f_dds,phase); | 412 | 412 | putPhaseWord(fd,f_dds,phase); | |
PutAmpWord(fd,f_dds,amp); | 413 | 413 | putAmpWord(fd,f_dds,amp); | |
414 | 414 | |||
return 0; | 415 | 415 | return 0; | |
} | 416 | 416 | } | |
417 | 417 | |||
418 | 418 | |||
int InitialisationProfile (int fd,int f_dds) | 419 | 419 | int initialisationProfileMode (int fd,int f_dds) | |
{ | 420 | 420 | { | |
421 | 421 | |||
Send_Reset(f_dds); //les registres sont maintenant par defaut | 422 | 422 | sendReset(f_dds); //les registres sont maintenant par defaut | |
write_register(fd,0x00,0x00,0x01,0x01,0x0a); //OSK+SDIO input only//ok | 423 | 423 | writeRegister(fd,0x00,0x00,0x01,0x01,0x0a); //OSK+SDIO input only//ok | |
Send_IO_Update(f_dds); | 424 | 424 | sendIOUpdate(f_dds); | |
write_register(fd,0x01,0x00,0x80,0x09,0x00); // profile mode enable very important | 425 | 425 | writeRegister(fd,0x01,0x00,0x80,0x09,0x00); // profile mode enable very important | |
Send_IO_Update(f_dds); | 426 | 426 | sendIOUpdate(f_dds); | |
write_register(fd,0x02,0x00,0x00,0x19,0x1c); // default | 427 | 427 | writeRegister(fd,0x02,0x00,0x00,0x19,0x1c); // default | |
Send_IO_Update(f_dds); | 428 | 428 | sendIOUpdate(f_dds); | |
write_register(fd,0x03,0x01,0x05,0x21,0x20); // calibration 1/2 :enable | 429 | 429 | writeRegister(fd,0x03,0x01,0x05,0x21,0x20); // calibration 1/2 :enable | |
Send_IO_Update(f_dds); | 430 | 430 | sendIOUpdate(f_dds); | |
write_register(fd,0x03,0x00,0x05,0x21,0x20); // calibration 2/2 :desenable | 431 | 431 | writeRegister(fd,0x03,0x00,0x05,0x21,0x20); // calibration 2/2 :desenable | |
Send_IO_Update(f_dds); | 432 | 432 | sendIOUpdate(f_dds); | |
433 | 433 | |||
return 0; | 434 | 434 | return 0; | |
} | 435 | 435 | } | |
436 | 436 | |||
437 | 437 | |||
438 | 438 | |||
//------------------- FIN RAJOUT 8/1 | 439 | 439 | //------------------- FIN RAJOUT 8/1 | |
440 | 440 | |||
441 | 441 | |||
//-------------------------FONCTIONS RAMPES HARDWARE | 442 | 442 | //-------------------------FONCTIONS RAMPES HARDWARE | |
443 | 443 | |||
//1-rampe de frequence | 444 | 444 | //1-rampe de frequence | |
445 | 445 | |||
//rampe simple de fréquence | 446 | 446 | //rampe simple de fréquence | |
int FrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown) | 447 | 447 | int frequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown) | |
{ | 448 | 448 | { | |
//calcul de N => N=DeltaF/df = DeltaT/dt | 449 | 449 | //calcul de N => N=DeltaF/df = DeltaT/dt | |
450 | 450 | |||
//1-fmax > fmin | 451 | 451 | //1-fmax > fmin | |
double DeltaFreq = FreqMax-FreqMin; | 452 | 452 | double DeltaFreq = FreqMax-FreqMin; | |
if(FreqMax<FreqMin) | 453 | 453 | if(FreqMax<FreqMin) | |
{ | 454 | 454 | { | |
printf("FreqMax should be > FreqMin\n"); | 455 | 455 | printf("FreqMax should be > FreqMin\n"); | |
printf("Can't Start the ramp\n"); | 456 | 456 | printf("Can't Start the ramp\n"); | |
return -1; | 457 | 457 | return -1; | |
} | 458 | 458 | } | |
459 | 459 | |||
//2- Calcul du nombre de points de la rampe | 460 | 460 | //2- Calcul du nombre de points de la rampe | |
int NumberPointsUp = DeltaFreq/dfUp; | 461 | 461 | int NumberPointsUp = DeltaFreq/dfUp; | |
int NumberPointsDown = DeltaFreq/dfDown; | 462 | 462 | int NumberPointsDown = DeltaFreq/dfDown; | |
463 | 463 | |||
//3- En déduire la valeur de dtUp et dtDown | 464 | 464 | //3- En déduire la valeur de dtUp et dtDown | |
double dtUp = DeltaTimeUp/NumberPointsUp; | 465 | 465 | double dtUp = DeltaTimeUp/NumberPointsUp; | |
double dtDown = DeltaTimeDown/NumberPointsDown; | 466 | 466 | double dtDown = DeltaTimeDown/NumberPointsDown; | |
467 | 467 | |||
double dtmin = 24/fclk; | 468 | 468 | double dtmin = 24/fclk; | |
double dtmax = dtmin*(pow(2.0,16.0)-1); | 469 | 469 | double dtmax = dtmin*(pow(2.0,16.0)-1); | |
470 | 470 | |||
//Check Up | 471 | 471 | //Check Up | |
if(dtUp<dtmin) | 472 | 472 | if(dtUp<dtmin) | |
{ | 473 | 473 | { | |
printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | 474 | 474 | printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 475 | 475 | printf("Can't start the ramp\n"); | |
return -1; | 476 | 476 | return -1; | |
} | 477 | 477 | } | |
478 | 478 | |||
if(dtUp>dtmax) | 479 | 479 | if(dtUp>dtmax) | |
{ | 480 | 480 | { | |
printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | 481 | 481 | printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 482 | 482 | printf("Can't start the ramp\n"); | |
return -1; | 483 | 483 | return -1; | |
} | 484 | 484 | } | |
485 | 485 | |||
//Check Down | 486 | 486 | //Check Down | |
if(dtDown<dtmin) | 487 | 487 | if(dtDown<dtmin) | |
{ | 488 | 488 | { | |
printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | 489 | 489 | printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 490 | 490 | printf("Can't start the ramp\n"); | |
return -1; | 491 | 491 | return -1; | |
} | 492 | 492 | } | |
493 | 493 | |||
if(dtDown>dtmax) | 494 | 494 | if(dtDown>dtmax) | |
{ | 495 | 495 | { | |
printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | 496 | 496 | printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 497 | 497 | printf("Can't start the ramp\n"); | |
return -1; | 498 | 498 | return -1; | |
} | 499 | 499 | } | |
500 | 500 | |||
501 | 501 | |||
//4 - Put word in register | 502 | 502 | //4 - Put word in register | |
503 | 503 | |||
504 | 504 | |||
//4.1 Limit register | 505 | 505 | //4.1 Limit register | |
uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); | 506 | 506 | uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); | |
write_register(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence | 507 | 507 | writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence | |
Send_IO_Update(f_dds); | 508 | 508 | sendIOUpdate(f_dds); | |
509 | 509 | |||
uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); | 510 | 510 | uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); | |
write_register(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence | 511 | 511 | writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence | |
Send_IO_Update(f_dds); | 512 | 512 | sendIOUpdate(f_dds); | |
513 | 513 | |||
514 | 514 | |||
//4.2 dfUP et dfDown | 515 | 515 | //4.2 dfUP et dfDown | |
double df_up = DeltaFreq/NumberPointsUp; | 516 | 516 | double df_up = DeltaFreq/NumberPointsUp; | |
double df_down = DeltaFreq/NumberPointsDown; | 517 | 517 | double df_down = DeltaFreq/NumberPointsDown; | |
518 | 518 | |||
uint32_t Word_df_up = rint(df_up*pow(2.0,32.0)/fclk); | 519 | 519 | uint32_t Word_df_up = rint(df_up*pow(2.0,32.0)/fclk); | |
uint32_t Word_df_down = rint(df_down*pow(2.0,32.0)/fclk); | 520 | 520 | uint32_t Word_df_down = rint(df_down*pow(2.0,32.0)/fclk); | |
521 | 521 | |||
write_register(fd,0x06,Word_df_up>>24&0xFF,Word_df_up>>16&0xFF,Word_df_up>>8&0xFF,Word_df_up&0xFF); //df_up | 522 | 522 | writeRegister(fd,0x06,Word_df_up>>24&0xFF,Word_df_up>>16&0xFF,Word_df_up>>8&0xFF,Word_df_up&0xFF); //df_up | |
Send_IO_Update(f_dds); | 523 | 523 | sendIOUpdate(f_dds); | |
write_register(fd,0x07,Word_df_down>>24&0xFF,Word_df_down>>16&0xFF,Word_df_down>>8&0xFF,Word_df_down&0xFF);//df_down | 524 | 524 | writeRegister(fd,0x07,Word_df_down>>24&0xFF,Word_df_down>>16&0xFF,Word_df_down>>8&0xFF,Word_df_down&0xFF);//df_down | |
Send_IO_Update(f_dds); | 525 | 525 | sendIOUpdate(f_dds); | |
526 | 526 | |||
527 | 527 | |||
//4.3 dtUp et dtDown | 528 | 528 | //4.3 dtUp et dtDown | |
529 | 529 | |||
uint16_t Word_dt_up = 0x0000; | 530 | 530 | uint16_t Word_dt_up = 0x0000; | |
uint16_t Word_dt_down = 0x0000; | 531 | 531 | uint16_t Word_dt_down = 0x0000; | |
532 | 532 | |||
Word_dt_up = rint(dtUp*fclk/24); | 533 | 533 | Word_dt_up = rint(dtUp*fclk/24); | |
Word_dt_down = rint(dtDown*fclk/24); | 534 | 534 | Word_dt_down = rint(dtDown*fclk/24); | |
535 | 535 | |||
write_register(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | 536 | 536 | writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | |
Send_IO_Update(f_dds); | 537 | 537 | sendIOUpdate(f_dds); | |
538 | 538 | |||
//5 Start of the ramp | 539 | 539 | //5 Start of the ramp | |
540 | 540 | |||
write_register(fd,0x01,0x00,0x08,0x09,0x00); //rampe simple | 541 | 541 | writeRegister(fd,0x01,0x00,0x08,0x09,0x00); //rampe simple | |
Send_IO_Update(f_dds); | 542 | 542 | sendIOUpdate(f_dds); | |
return 0; | 543 | 543 | return 0; | |
544 | 544 | |||
545 | 545 | |||
546 | 546 | |||
return EXIT_SUCCESS; | 547 | 547 | return EXIT_SUCCESS; | |
548 | 548 | |||
} | 549 | 549 | } | |
550 | 550 | |||
551 | 551 | |||
//rampe continue de fréquence | 552 | 552 | //rampe continue de fréquence | |
int ContinueFrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown) | 553 | 553 | int continueFrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown) | |
{ | 554 | 554 | { | |
//calcul de N => N=DeltaF/df = DeltaT/dt | 555 | 555 | //calcul de N => N=DeltaF/df = DeltaT/dt | |
556 | 556 | |||
//1-fmax > fmin | 557 | 557 | //1-fmax > fmin | |
double DeltaFreq = FreqMax-FreqMin; | 558 | 558 | double DeltaFreq = FreqMax-FreqMin; | |
if(FreqMax<FreqMin) | 559 | 559 | if(FreqMax<FreqMin) | |
{ | 560 | 560 | { | |
printf("FreqMax should be > FreqMin\n"); | 561 | 561 | printf("FreqMax should be > FreqMin\n"); | |
printf("Can't Start the ramp\n"); | 562 | 562 | printf("Can't Start the ramp\n"); | |
return -1; | 563 | 563 | return -1; | |
} | 564 | 564 | } | |
565 | 565 | |||
//2- Calcul du nombre de points de la rampe | 566 | 566 | //2- Calcul du nombre de points de la rampe | |
int NumberPointsUp = DeltaFreq/dfUp; | 567 | 567 | int NumberPointsUp = DeltaFreq/dfUp; | |
int NumberPointsDown = DeltaFreq/dfDown; | 568 | 568 | int NumberPointsDown = DeltaFreq/dfDown; | |
569 | 569 | |||
//3- En déduire la valeur de dtUp et dtDown | 570 | 570 | //3- En déduire la valeur de dtUp et dtDown | |
double dtUp = DeltaTimeUp/NumberPointsUp; | 571 | 571 | double dtUp = DeltaTimeUp/NumberPointsUp; | |
double dtDown = DeltaTimeDown/NumberPointsDown; | 572 | 572 | double dtDown = DeltaTimeDown/NumberPointsDown; | |
573 | 573 | |||
double dtmin = 24/fclk; | 574 | 574 | double dtmin = 24/fclk; | |
double dtmax = dtmin*(pow(2.0,16.0)-1); | 575 | 575 | double dtmax = dtmin*(pow(2.0,16.0)-1); | |
576 | 576 | |||
//Check Up | 577 | 577 | //Check Up | |
if(dtUp<dtmin) | 578 | 578 | if(dtUp<dtmin) | |
{ | 579 | 579 | { | |
printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | 580 | 580 | printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 581 | 581 | printf("Can't start the ramp\n"); | |
return -1; | 582 | 582 | return -1; | |
} | 583 | 583 | } | |
584 | 584 | |||
if(dtUp>dtmax) | 585 | 585 | if(dtUp>dtmax) | |
{ | 586 | 586 | { | |
printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | 587 | 587 | printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 588 | 588 | printf("Can't start the ramp\n"); | |
return -1; | 589 | 589 | return -1; | |
} | 590 | 590 | } | |
591 | 591 | |||
//Check Down | 592 | 592 | //Check Down | |
if(dtDown<dtmin) | 593 | 593 | if(dtDown<dtmin) | |
{ | 594 | 594 | { | |
printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | 595 | 595 | printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 596 | 596 | printf("Can't start the ramp\n"); | |
return -1; | 597 | 597 | return -1; | |
} | 598 | 598 | } | |
599 | 599 | |||
if(dtDown>dtmax) | 600 | 600 | if(dtDown>dtmax) | |
{ | 601 | 601 | { | |
printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | 602 | 602 | printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 603 | 603 | printf("Can't start the ramp\n"); | |
return -1; | 604 | 604 | return -1; | |
} | 605 | 605 | } | |
606 | 606 | |||
607 | 607 | |||
//4 - Put word in register | 608 | 608 | //4 - Put word in register | |
609 | 609 | |||
610 | 610 | |||
//4.1 Limit register | 611 | 611 | //4.1 Limit register | |
uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); | 612 | 612 | uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); | |
write_register(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence | 613 | 613 | writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence | |
Send_IO_Update(f_dds); | 614 | 614 | sendIOUpdate(f_dds); | |
615 | 615 | |||
uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); | 616 | 616 | uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); | |
write_register(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence | 617 | 617 | writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence | |
Send_IO_Update(f_dds); | 618 | 618 | sendIOUpdate(f_dds); | |
619 | 619 | |||
620 | 620 | |||
//4.2 dfUP et dfDown | 621 | 621 | //4.2 dfUP et dfDown | |
double df_up = DeltaFreq/NumberPointsUp; | 622 | 622 | double df_up = DeltaFreq/NumberPointsUp; | |
double df_down = DeltaFreq/NumberPointsDown; | 623 | 623 | double df_down = DeltaFreq/NumberPointsDown; | |
624 | 624 | |||
uint32_t Word_df_up = rint(df_up*pow(2.0,32.0)/fclk); | 625 | 625 | uint32_t Word_df_up = rint(df_up*pow(2.0,32.0)/fclk); | |
uint32_t Word_df_down = rint(df_down*pow(2.0,32.0)/fclk); | 626 | 626 | uint32_t Word_df_down = rint(df_down*pow(2.0,32.0)/fclk); | |
627 | 627 | |||
write_register(fd,0x06,Word_df_up>>24&0xFF,Word_df_up>>16&0xFF,Word_df_up>>8&0xFF,Word_df_up&0xFF); //df_up | 628 | 628 | writeRegister(fd,0x06,Word_df_up>>24&0xFF,Word_df_up>>16&0xFF,Word_df_up>>8&0xFF,Word_df_up&0xFF); //df_up | |
Send_IO_Update(f_dds); | 629 | 629 | sendIOUpdate(f_dds); | |
write_register(fd,0x07,Word_df_down>>24&0xFF,Word_df_down>>16&0xFF,Word_df_down>>8&0xFF,Word_df_down&0xFF);//df_down | 630 | 630 | writeRegister(fd,0x07,Word_df_down>>24&0xFF,Word_df_down>>16&0xFF,Word_df_down>>8&0xFF,Word_df_down&0xFF);//df_down | |
Send_IO_Update(f_dds); | 631 | 631 | sendIOUpdate(f_dds); | |
632 | 632 | |||
633 | 633 | |||
//4.3 dtUp et dtDown | 634 | 634 | //4.3 dtUp et dtDown | |
635 | 635 | |||
uint16_t Word_dt_up = 0x0000; | 636 | 636 | uint16_t Word_dt_up = 0x0000; | |
uint16_t Word_dt_down = 0x0000; | 637 | 637 | uint16_t Word_dt_down = 0x0000; | |
638 | 638 | |||
Word_dt_up = rint(dtUp*fclk/24); | 639 | 639 | Word_dt_up = rint(dtUp*fclk/24); | |
Word_dt_down = rint(dtDown*fclk/24); | 640 | 640 | Word_dt_down = rint(dtDown*fclk/24); | |
641 | 641 | |||
write_register(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | 642 | 642 | writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | |
Send_IO_Update(f_dds); | 643 | 643 | sendIOUpdate(f_dds); | |
644 | 644 | |||
//5 Start of the ramp | 645 | 645 | //5 Start of the ramp | |
646 | 646 | |||
write_register(fd,0x01,0x00,0x8e,0x29,0x00); //rampe triangulaire | 647 | 647 | writeRegister(fd,0x01,0x00,0x8e,0x29,0x00); //rampe triangulaire | |
Send_IO_Update(f_dds); | 648 | 648 | sendIOUpdate(f_dds); | |
return 0; | 649 | 649 | return 0; | |
650 | 650 | |||
651 | 651 | |||
652 | 652 | |||
return EXIT_SUCCESS; | 653 | 653 | return EXIT_SUCCESS; | |
654 | 654 | |||
} | 655 | 655 | } | |
656 | 656 | |||
//2-rampe d'amplitude | 657 | 657 | //2-rampe d'amplitude | |
658 | 658 | |||
int AmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) | 659 | 659 | int amplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) | |
{ | 660 | 660 | { | |
661 | 661 | |||
662 | 662 | |||
//calcul de N => N=DeltaF/df = DeltaT/dt | 663 | 663 | //calcul de N => N=DeltaF/df = DeltaT/dt | |
664 | 664 | |||
//1-Amax > Amin | 665 | 665 | //1-Amax > Amin | |
double DeltaAmp = AMax-AMin; | 666 | 666 | double DeltaAmp = AMax-AMin; | |
if(AMax<AMin) | 667 | 667 | if(AMax<AMin) | |
{ | 668 | 668 | { | |
printf("AMax should be > AMin\n"); | 669 | 669 | printf("AMax should be > AMin\n"); | |
printf("Can't Start the ramp\n"); | 670 | 670 | printf("Can't Start the ramp\n"); | |
return -1; | 671 | 671 | return -1; | |
} | 672 | 672 | } | |
673 | 673 | |||
674 | 674 | |||
//2- Calcul du nombre de points de la rampe | 675 | 675 | //2- Calcul du nombre de points de la rampe | |
int NumberPointsUp = DeltaAmp/dAUp; | 676 | 676 | int NumberPointsUp = DeltaAmp/dAUp; | |
int NumberPointsDown = DeltaAmp/dADown; | 677 | 677 | int NumberPointsDown = DeltaAmp/dADown; | |
678 | 678 | |||
//3- En déduire la valeur de dtUp et dtDown | 679 | 679 | //3- En déduire la valeur de dtUp et dtDown | |
double dtUp = DeltaTimeUp/NumberPointsUp; | 680 | 680 | double dtUp = DeltaTimeUp/NumberPointsUp; | |
double dtDown = DeltaTimeDown/NumberPointsDown; | 681 | 681 | double dtDown = DeltaTimeDown/NumberPointsDown; | |
682 | 682 | |||
double dtmin = 24/fclk; | 683 | 683 | double dtmin = 24/fclk; | |
double dtmax = dtmin*(pow(2.0,16.0)-1); | 684 | 684 | double dtmax = dtmin*(pow(2.0,16.0)-1); | |
685 | 685 | |||
//Check Up | 686 | 686 | //Check Up | |
if(dtUp<dtmin) | 687 | 687 | if(dtUp<dtmin) | |
{ | 688 | 688 | { | |
printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | 689 | 689 | printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 690 | 690 | printf("Can't start the ramp\n"); | |
return -1; | 691 | 691 | return -1; | |
} | 692 | 692 | } | |
693 | 693 | |||
if(dtUp>dtmax) | 694 | 694 | if(dtUp>dtmax) | |
{ | 695 | 695 | { | |
printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | 696 | 696 | printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 697 | 697 | printf("Can't start the ramp\n"); | |
return -1; | 698 | 698 | return -1; | |
} | 699 | 699 | } | |
700 | 700 | |||
//Check Down | 701 | 701 | //Check Down | |
if(dtDown<dtmin) | 702 | 702 | if(dtDown<dtmin) | |
{ | 703 | 703 | { | |
printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | 704 | 704 | printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 705 | 705 | printf("Can't start the ramp\n"); | |
return -1; | 706 | 706 | return -1; | |
} | 707 | 707 | } | |
708 | 708 | |||
if(dtDown>dtmax) | 709 | 709 | if(dtDown>dtmax) | |
{ | 710 | 710 | { | |
printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | 711 | 711 | printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 712 | 712 | printf("Can't start the ramp\n"); | |
return -1; | 713 | 713 | return -1; | |
} | 714 | 714 | } | |
715 | 715 | |||
716 | 716 | |||
717 | 717 | |||
//check if DeltaAmp is enouth | 718 | 718 | //check if DeltaAmp is enouth | |
double enouthUP=0.5*NumberPointsUp*100/4095; | 719 | 719 | double enouthUP=0.5*NumberPointsUp*100/4095; | |
double enouthDOWN=0.5*NumberPointsDown*100/4095; | 720 | 720 | double enouthDOWN=0.5*NumberPointsDown*100/4095; | |
721 | 721 | |||
int borneUP = rint(enouthUP); | 722 | 722 | int borneUP = rint(enouthUP); | |
int borneDown = rint(enouthDOWN); | 723 | 723 | int borneDown = rint(enouthDOWN); | |
724 | 724 | |||
if(DeltaAmp<=enouthUP) | 725 | 725 | if(DeltaAmp<=enouthUP) | |
{ | 726 | 726 | { | |
printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | 727 | 727 | printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | |
//return -1; | 728 | 728 | //return -1; | |
} | 729 | 729 | } | |
730 | 730 | |||
if(DeltaAmp<=enouthDOWN) | 731 | 731 | if(DeltaAmp<=enouthDOWN) | |
{ | 732 | 732 | { | |
printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | 733 | 733 | printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | |
//return -1; | 734 | 734 | //return -1; | |
} | 735 | 735 | } | |
736 | 736 | |||
737 | 737 | |||
//4 - Put word in register | 738 | 738 | //4 - Put word in register | |
739 | 739 | |||
740 | 740 | |||
//4.1 Limit register | 741 | 741 | //4.1 Limit register | |
uint32_t WordAmin = rint(AMin*4095/100); | 742 | 742 | uint32_t WordAmin = rint(AMin*4095/100); | |
uint32_t WordAmax= rint(AMax*4095/100); | 743 | 743 | uint32_t WordAmax= rint(AMax*4095/100); | |
744 | 744 | |||
write_register(fd,0x04,WordAmin>>24&0xFF,WordAmin>>16&0xFF,WordAmin>>8&0xFF,WordAmin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | 745 | 745 | writeRegister(fd,0x04,WordAmin>>24&0xFF,WordAmin>>16&0xFF,WordAmin>>8&0xFF,WordAmin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | |
Send_IO_Update(f_dds); | 746 | 746 | sendIOUpdate(f_dds); | |
write_register(fd,0x05,WordAmax>>24&0xFF,WordAmax>>16&0xFF,WordAmax>>8&0xFF,WordAmax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | 747 | 747 | writeRegister(fd,0x05,WordAmax>>24&0xFF,WordAmax>>16&0xFF,WordAmax>>8&0xFF,WordAmax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | |
Send_IO_Update(f_dds); | 748 | 748 | sendIOUpdate(f_dds); | |
749 | 749 | |||
750 | 750 | |||
//4.2 dAUP et dADown | 751 | 751 | //4.2 dAUP et dADown | |
752 | 752 | |||
uint32_t Word_dA_up = rint(dAUp*4095/100); | 753 | 753 | uint32_t Word_dA_up = rint(dAUp*4095/100); | |
uint32_t Word_dA_down = rint(dADown*4095/100); | 754 | 754 | uint32_t Word_dA_down = rint(dADown*4095/100); | |
755 | 755 | |||
write_register(fd,0x06,Word_dA_up>>24&0xFF,Word_dA_up>>16&0xFF,Word_dA_up>>8&0xFF,Word_dA_up&0xFF); //dA_up | 756 | 756 | writeRegister(fd,0x06,Word_dA_up>>24&0xFF,Word_dA_up>>16&0xFF,Word_dA_up>>8&0xFF,Word_dA_up&0xFF); //dA_up | |
Send_IO_Update(f_dds); | 757 | 757 | sendIOUpdate(f_dds); | |
write_register(fd,0x07,Word_dA_down>>24&0xFF,Word_dA_down>>16&0xFF,Word_dA_down>>8&0xFF,Word_dA_down&0xFF);//dA_down | 758 | 758 | writeRegister(fd,0x07,Word_dA_down>>24&0xFF,Word_dA_down>>16&0xFF,Word_dA_down>>8&0xFF,Word_dA_down&0xFF);//dA_down | |
Send_IO_Update(f_dds); | 759 | 759 | sendIOUpdate(f_dds); | |
760 | 760 | |||
761 | 761 | |||
//4.3 dtUp et dtDown | 762 | 762 | //4.3 dtUp et dtDown | |
763 | 763 | |||
uint16_t Word_dt_up = rint(dtUp*fclk/24); | 764 | 764 | uint16_t Word_dt_up = rint(dtUp*fclk/24); | |
uint16_t Word_dt_down = rint(dtDown*fclk/24); | 765 | 765 | uint16_t Word_dt_down = rint(dtDown*fclk/24); | |
766 | 766 | |||
write_register(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | 767 | 767 | writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | |
Send_IO_Update(f_dds); | 768 | 768 | sendIOUpdate(f_dds); | |
769 | 769 | |||
//5 Start of the ramp | 770 | 770 | //5 Start of the ramp | |
771 | 771 | |||
write_register(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante | 772 | 772 | writeRegister(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante | |
//write_register(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue | 773 | 773 | //writeRegister(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue | |
Send_IO_Update(f_dds); | 774 | 774 | sendIOUpdate(f_dds); | |
775 | 775 | |||
return EXIT_SUCCESS; | 776 | 776 | return EXIT_SUCCESS; | |
} | 777 | 777 | } | |
778 | 778 | |||
int ContinueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) | 779 | 779 | int continueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) | |
{ | 780 | 780 | { | |
781 | 781 | |||
782 | 782 | |||
//calcul de N => N=DeltaF/df = DeltaT/dt | 783 | 783 | //calcul de N => N=DeltaF/df = DeltaT/dt | |
784 | 784 | |||
//1-Amax > Amin | 785 | 785 | //1-Amax > Amin | |
double DeltaAmp = AMax-AMin; | 786 | 786 | double DeltaAmp = AMax-AMin; | |
if(AMax<AMin) | 787 | 787 | if(AMax<AMin) | |
{ | 788 | 788 | { | |
printf("AMax should be > AMin\n"); | 789 | 789 | printf("AMax should be > AMin\n"); | |
printf("Can't Start the ramp\n"); | 790 | 790 | printf("Can't Start the ramp\n"); | |
return -1; | 791 | 791 | return -1; | |
} | 792 | 792 | } | |
793 | 793 | |||
794 | 794 | |||
//2- Calcul du nombre de points de la rampe | 795 | 795 | //2- Calcul du nombre de points de la rampe | |
int NumberPointsUp = DeltaAmp/dAUp; | 796 | 796 | int NumberPointsUp = DeltaAmp/dAUp; | |
int NumberPointsDown = DeltaAmp/dADown; | 797 | 797 | int NumberPointsDown = DeltaAmp/dADown; | |
798 | 798 | |||
//3- En déduire la valeur de dtUp et dtDown | 799 | 799 | //3- En déduire la valeur de dtUp et dtDown | |
double dtUp = DeltaTimeUp/NumberPointsUp; | 800 | 800 | double dtUp = DeltaTimeUp/NumberPointsUp; | |
double dtDown = DeltaTimeDown/NumberPointsDown; | 801 | 801 | double dtDown = DeltaTimeDown/NumberPointsDown; | |
802 | 802 | |||
double dtmin = 24/fclk; | 803 | 803 | double dtmin = 24/fclk; | |
double dtmax = dtmin*(pow(2.0,16.0)-1); | 804 | 804 | double dtmax = dtmin*(pow(2.0,16.0)-1); | |
805 | 805 | |||
//Check Up | 806 | 806 | //Check Up | |
if(dtUp<dtmin) | 807 | 807 | if(dtUp<dtmin) | |
{ | 808 | 808 | { | |
printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | 809 | 809 | printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 810 | 810 | printf("Can't start the ramp\n"); | |
return -1; | 811 | 811 | return -1; | |
} | 812 | 812 | } | |
813 | 813 | |||
if(dtUp>dtmax) | 814 | 814 | if(dtUp>dtmax) | |
{ | 815 | 815 | { | |
printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | 816 | 816 | printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 817 | 817 | printf("Can't start the ramp\n"); | |
return -1; | 818 | 818 | return -1; | |
} | 819 | 819 | } | |
820 | 820 | |||
//Check Down | 821 | 821 | //Check Down | |
if(dtDown<dtmin) | 822 | 822 | if(dtDown<dtmin) | |
{ | 823 | 823 | { | |
printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | 824 | 824 | printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 825 | 825 | printf("Can't start the ramp\n"); | |
return -1; | 826 | 826 | return -1; | |
} | 827 | 827 | } | |
828 | 828 | |||
if(dtDown>dtmax) | 829 | 829 | if(dtDown>dtmax) | |
{ | 830 | 830 | { | |
printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | 831 | 831 | printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 832 | 832 | printf("Can't start the ramp\n"); | |
return -1; | 833 | 833 | return -1; | |
} | 834 | 834 | } | |
835 | 835 | |||
836 | 836 | |||
837 | 837 | |||
//check if DeltaAmp is enouth | 838 | 838 | //check if DeltaAmp is enouth | |
double enouthUP=0.5*NumberPointsUp*100/4095; | 839 | 839 | double enouthUP=0.5*NumberPointsUp*100/4095; | |
double enouthDOWN=0.5*NumberPointsDown*100/4095; | 840 | 840 | double enouthDOWN=0.5*NumberPointsDown*100/4095; | |
841 | 841 | |||
int borneUP = rint(enouthUP); | 842 | 842 | int borneUP = rint(enouthUP); | |
int borneDown = rint(enouthDOWN); | 843 | 843 | int borneDown = rint(enouthDOWN); | |
844 | 844 | |||
if(DeltaAmp<=enouthUP) | 845 | 845 | if(DeltaAmp<=enouthUP) | |
{ | 846 | 846 | { | |
printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | 847 | 847 | printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | |
//return -1; | 848 | 848 | //return -1; | |
} | 849 | 849 | } | |
850 | 850 | |||
if(DeltaAmp<=enouthDOWN) | 851 | 851 | if(DeltaAmp<=enouthDOWN) | |
{ | 852 | 852 | { | |
printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | 853 | 853 | printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | |
//return -1; | 854 | 854 | //return -1; | |
} | 855 | 855 | } | |
856 | 856 | |||
857 | 857 | |||
//4 - Put word in register | 858 | 858 | //4 - Put word in register | |
859 | 859 | |||
860 | 860 | |||
//4.1 Limit register | 861 | 861 | //4.1 Limit register | |
uint32_t WordAmin = rint(AMin*4095/100); | 862 | 862 | uint32_t WordAmin = rint(AMin*4095/100); | |
uint32_t WordAmax= rint(AMax*4095/100); | 863 | 863 | uint32_t WordAmax= rint(AMax*4095/100); | |
864 | 864 | |||
write_register(fd,0x04,WordAmin>>24&0xFF,WordAmin>>16&0xFF,WordAmin>>8&0xFF,WordAmin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | 865 | 865 | writeRegister(fd,0x04,WordAmin>>24&0xFF,WordAmin>>16&0xFF,WordAmin>>8&0xFF,WordAmin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | |
Send_IO_Update(f_dds); | 866 | 866 | sendIOUpdate(f_dds); | |
write_register(fd,0x05,WordAmax>>24&0xFF,WordAmax>>16&0xFF,WordAmax>>8&0xFF,WordAmax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | 867 | 867 | writeRegister(fd,0x05,WordAmax>>24&0xFF,WordAmax>>16&0xFF,WordAmax>>8&0xFF,WordAmax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | |
Send_IO_Update(f_dds); | 868 | 868 | sendIOUpdate(f_dds); | |
869 | 869 | |||
870 | 870 | |||
//4.2 dAUP et dADown | 871 | 871 | //4.2 dAUP et dADown | |
872 | 872 | |||
uint32_t Word_dA_up = rint(dAUp*4095/100); | 873 | 873 | uint32_t Word_dA_up = rint(dAUp*4095/100); | |
uint32_t Word_dA_down = rint(dADown*4095/100); | 874 | 874 | uint32_t Word_dA_down = rint(dADown*4095/100); | |
875 | 875 | |||
write_register(fd,0x06,Word_dA_up>>24&0xFF,Word_dA_up>>16&0xFF,Word_dA_up>>8&0xFF,Word_dA_up&0xFF); //dA_up | 876 | 876 | writeRegister(fd,0x06,Word_dA_up>>24&0xFF,Word_dA_up>>16&0xFF,Word_dA_up>>8&0xFF,Word_dA_up&0xFF); //dA_up | |
Send_IO_Update(f_dds); | 877 | 877 | sendIOUpdate(f_dds); | |
write_register(fd,0x07,Word_dA_down>>24&0xFF,Word_dA_down>>16&0xFF,Word_dA_down>>8&0xFF,Word_dA_down&0xFF);//dA_down | 878 | 878 | writeRegister(fd,0x07,Word_dA_down>>24&0xFF,Word_dA_down>>16&0xFF,Word_dA_down>>8&0xFF,Word_dA_down&0xFF);//dA_down | |
Send_IO_Update(f_dds); | 879 | 879 | sendIOUpdate(f_dds); | |
880 | 880 | |||
881 | 881 | |||
//4.3 dtUp et dtDown | 882 | 882 | //4.3 dtUp et dtDown | |
883 | 883 | |||
uint16_t Word_dt_up = rint(dtUp*fclk/24); | 884 | 884 | uint16_t Word_dt_up = rint(dtUp*fclk/24); | |
uint16_t Word_dt_down = rint(dtDown*fclk/24); | 885 | 885 | uint16_t Word_dt_down = rint(dtDown*fclk/24); | |
886 | 886 | |||
write_register(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | 887 | 887 | writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | |
Send_IO_Update(f_dds); | 888 | 888 | sendIOUpdate(f_dds); | |
889 | 889 | |||
//5 Start of the ramp | 890 | 890 | //5 Start of the ramp | |
891 | 891 | |||
//write_register(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante | 892 | 892 | //writeRegister(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante | |
write_register(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue | 893 | 893 | writeRegister(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue | |
Send_IO_Update(f_dds); | 894 | 894 | sendIOUpdate(f_dds); | |
895 | 895 | |||
return EXIT_SUCCESS; | 896 | 896 | return EXIT_SUCCESS; | |
} | 897 | 897 | } | |
898 | 898 | |||
899 | 899 | |||
//3-rampe de ĥase | 900 | 900 | //3-rampe de ĥase | |
901 | 901 | |||
int PhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown) | 902 | 902 | int phaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown) | |
{ | 903 | 903 | { | |
904 | 904 | |||
905 | 905 | |||
//calcul de N => N=Deltaphi/dphi = DeltaT/dt | 906 | 906 | //calcul de N => N=Deltaphi/dphi = DeltaT/dt | |
907 | 907 | |||
//1-phimax > phimin | 908 | 908 | //1-phimax > phimin | |
double DeltaPhi = PhiMax-PhiMin; | 909 | 909 | double DeltaPhi = PhiMax-PhiMin; | |
if(PhiMax<PhiMin) | 910 | 910 | if(PhiMax<PhiMin) | |
{ | 911 | 911 | { | |
printf("PhiMax should be > PhiMin\n"); | 912 | 912 | printf("PhiMax should be > PhiMin\n"); | |
printf("Can't Start the ramp\n"); | 913 | 913 | printf("Can't Start the ramp\n"); | |
return -1; | 914 | 914 | return -1; | |
} | 915 | 915 | } | |
916 | 916 | |||
917 | 917 | |||
//2- Calcul du nombre de points de la rampe | 918 | 918 | //2- Calcul du nombre de points de la rampe | |
int NumberPointsUp = DeltaPhi/dphiUp; | 919 | 919 | int NumberPointsUp = DeltaPhi/dphiUp; | |
int NumberPointsDown = DeltaPhi/dphiDown; | 920 | 920 | int NumberPointsDown = DeltaPhi/dphiDown; | |
921 | 921 | |||
printf("NumberPointsUp = %d\n",NumberPointsUp); | 922 | 922 | printf("NumberPointsUp = %d\n",NumberPointsUp); | |
printf("NumberPointsDown = %d\n",NumberPointsDown); | 923 | 923 | printf("NumberPointsDown = %d\n",NumberPointsDown); | |
924 | 924 | |||
//3- En déduire la valeur de dtUp et dtDown | 925 | 925 | //3- En déduire la valeur de dtUp et dtDown | |
double dtUp = DeltaTimeUp/NumberPointsUp; | 926 | 926 | double dtUp = DeltaTimeUp/NumberPointsUp; | |
double dtDown = DeltaTimeDown/NumberPointsDown; | 927 | 927 | double dtDown = DeltaTimeDown/NumberPointsDown; | |
928 | 928 | |||
double dtmin = 24/fclk; | 929 | 929 | double dtmin = 24/fclk; | |
double dtmax = dtmin*(pow(2.0,16.0)-1); | 930 | 930 | double dtmax = dtmin*(pow(2.0,16.0)-1); | |
931 | 931 | |||
//Check Up | 932 | 932 | //Check Up | |
if(dtUp<dtmin) | 933 | 933 | if(dtUp<dtmin) | |
{ | 934 | 934 | { | |
printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | 935 | 935 | printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 936 | 936 | printf("Can't start the ramp\n"); | |
return -1; | 937 | 937 | return -1; | |
} | 938 | 938 | } | |
939 | 939 | |||
if(dtUp>dtmax) | 940 | 940 | if(dtUp>dtmax) | |
{ | 941 | 941 | { | |
printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | 942 | 942 | printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 943 | 943 | printf("Can't start the ramp\n"); | |
return -1; | 944 | 944 | return -1; | |
} | 945 | 945 | } | |
946 | 946 | |||
//Check Down | 947 | 947 | //Check Down | |
if(dtDown<dtmin) | 948 | 948 | if(dtDown<dtmin) | |
{ | 949 | 949 | { | |
printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | 950 | 950 | printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 951 | 951 | printf("Can't start the ramp\n"); | |
return -1; | 952 | 952 | return -1; | |
} | 953 | 953 | } | |
954 | 954 | |||
if(dtDown>dtmax) | 955 | 955 | if(dtDown>dtmax) | |
{ | 956 | 956 | { | |
printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | 957 | 957 | printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 958 | 958 | printf("Can't start the ramp\n"); | |
return -1; | 959 | 959 | return -1; | |
} | 960 | 960 | } | |
961 | 961 | |||
962 | 962 | |||
963 | 963 | |||
//check if DeltaAmp is enouth | 964 | 964 | //check if DeltaAmp is enouth | |
/* | 965 | 965 | /* | |
double enouthUP=0.5*NumberPointsUp*100/4095; | 966 | 966 | double enouthUP=0.5*NumberPointsUp*100/4095; | |
double enouthDOWN=0.5*NumberPointsDown*100/4095; | 967 | 967 | double enouthDOWN=0.5*NumberPointsDown*100/4095; | |
968 | 968 | |||
int borneUP = rint(enouthUP); | 969 | 969 | int borneUP = rint(enouthUP); | |
int borneDown = rint(enouthDOWN); | 970 | 970 | int borneDown = rint(enouthDOWN); | |
971 | 971 | |||
if(DeltaAmp<=enouthUP) | 972 | 972 | if(DeltaAmp<=enouthUP) | |
{ | 973 | 973 | { | |
printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | 974 | 974 | printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | |
//return -1; | 975 | 975 | //return -1; | |
} | 976 | 976 | } | |
977 | 977 | |||
if(DeltaAmp<=enouthDOWN) | 978 | 978 | if(DeltaAmp<=enouthDOWN) | |
{ | 979 | 979 | { | |
printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | 980 | 980 | printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | |
//return -1; | 981 | 981 | //return -1; | |
} | 982 | 982 | } | |
983 | 983 | |||
*/ | 984 | 984 | */ | |
985 | 985 | |||
//4 - Put word in register | 986 | 986 | //4 - Put word in register | |
987 | 987 | |||
988 | 988 | |||
//4.1 Limit register | 989 | 989 | //4.1 Limit register | |
uint32_t WordPhimin = rint(PhiMin*65535/360); | 990 | 990 | uint32_t WordPhimin = rint(PhiMin*65535/360); | |
uint32_t WordPhimax= rint(PhiMax*65535/360); | 991 | 991 | uint32_t WordPhimax= rint(PhiMax*65535/360); | |
992 | 992 | |||
993 | 993 | |||
printf("WordPhimin = %.32x\n",WordPhimin); | 994 | 994 | printf("WordPhimin = %.32x\n",WordPhimin); | |
printf("WordPhimax = %.32x\n",WordPhimax); | 995 | 995 | printf("WordPhimax = %.32x\n",WordPhimax); | |
996 | 996 | |||
997 | 997 | |||
write_register(fd,0x04,WordPhimin>>24&0xFF,WordPhimin>>16&0xFF,WordPhimin>>8&0xFF,WordPhimin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | 998 | 998 | writeRegister(fd,0x04,WordPhimin>>24&0xFF,WordPhimin>>16&0xFF,WordPhimin>>8&0xFF,WordPhimin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | |
Send_IO_Update(f_dds); | 999 | 999 | sendIOUpdate(f_dds); | |
write_register(fd,0x05,WordPhimax>>24&0xFF,WordPhimax>>16&0xFF,WordPhimax>>8&0xFF,WordPhimax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | 1000 | 1000 | writeRegister(fd,0x05,WordPhimax>>24&0xFF,WordPhimax>>16&0xFF,WordPhimax>>8&0xFF,WordPhimax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | |
Send_IO_Update(f_dds); | 1001 | 1001 | sendIOUpdate(f_dds); | |
1002 | 1002 | |||
1003 | 1003 | |||
//4.2 dphiUP et dphiDown | 1004 | 1004 | //4.2 dphiUP et dphiDown | |
1005 | 1005 | |||
// uint32_t Word_dphi_up = rint(dphiUp*(pow(2.0,29.0)-1)/45); | 1006 | 1006 | // uint32_t Word_dphi_up = rint(dphiUp*(pow(2.0,29.0)-1)/45); | |
// uint32_t Word_dphi_down = rint(dphiDown*(pow(2.0,29.0)-1)/45); | 1007 | 1007 | // uint32_t Word_dphi_down = rint(dphiDown*(pow(2.0,29.0)-1)/45); | |
uint32_t Word_dphi_up = rint(dphiUp*(65535/360)); | 1008 | 1008 | uint32_t Word_dphi_up = rint(dphiUp*(65535/360)); | |
uint32_t Word_dphi_down = rint(dphiDown*(65535/360)); | 1009 | 1009 | uint32_t Word_dphi_down = rint(dphiDown*(65535/360)); | |
1010 | 1010 | |||
printf("Word_dphi_up = %.32x\n",Word_dphi_up); | 1011 | 1011 | printf("Word_dphi_up = %.32x\n",Word_dphi_up); | |
printf("Word_dphi_down = %.32x\n",Word_dphi_down); | 1012 | 1012 | printf("Word_dphi_down = %.32x\n",Word_dphi_down); | |
1013 | 1013 | |||
/* | 1014 | 1014 | /* | |
write_register(fd,0x06,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up>>0&0xFF,Word_dphi_up&0xFF); //dphi_up | 1015 | 1015 | writeRegister(fd,0x06,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up>>0&0xFF,Word_dphi_up&0xFF); //dphi_up | |
Send_IO_Update(f_dds); | 1016 | 1016 | sendIOUpdate(f_dds); | |
write_register(fd,0x07,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down>>0&0xFF,Word_dphi_down&0xFF);//dphi_down | 1017 | 1017 | writeRegister(fd,0x07,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down>>0&0xFF,Word_dphi_down&0xFF);//dphi_down | |
Send_IO_Update(f_dds); | 1018 | 1018 | sendIOUpdate(f_dds); | |
1019 | 1019 | |||
*/ | 1020 | 1020 | */ | |
1021 | 1021 | |||
1022 | 1022 | |||
write_register(fd,0x06,Word_dphi_up>>24&0xFF,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up&0xFF); //dA_up | 1023 | 1023 | writeRegister(fd,0x06,Word_dphi_up>>24&0xFF,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up&0xFF); //dA_up | |
Send_IO_Update(f_dds); | 1024 | 1024 | sendIOUpdate(f_dds); | |
write_register(fd,0x07,Word_dphi_down>>24&0xFF,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down&0xFF);//dA_down | 1025 | 1025 | writeRegister(fd,0x07,Word_dphi_down>>24&0xFF,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down&0xFF);//dA_down | |
Send_IO_Update(f_dds); | 1026 | 1026 | sendIOUpdate(f_dds); | |
1027 | 1027 | |||
1028 | 1028 | |||
//4.3 dtUp et dtDown | 1029 | 1029 | //4.3 dtUp et dtDown | |
1030 | 1030 | |||
uint16_t Word_dt_up = rint(dtUp*fclk/24); | 1031 | 1031 | uint16_t Word_dt_up = rint(dtUp*fclk/24); | |
uint16_t Word_dt_down = rint(dtDown*fclk/24); | 1032 | 1032 | uint16_t Word_dt_down = rint(dtDown*fclk/24); | |
1033 | 1033 | |||
write_register(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | 1034 | 1034 | writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | |
Send_IO_Update(f_dds); | 1035 | 1035 | sendIOUpdate(f_dds); | |
1036 | 1036 | |||
//5 Start of the ramp | 1037 | 1037 | //5 Start of the ramp | |
1038 | 1038 | |||
write_register(fd,0x01,0x00,0x18,0x09,0x00); //rampe simple montante | 1039 | 1039 | writeRegister(fd,0x01,0x00,0x18,0x09,0x00); //rampe simple montante | |
Send_IO_Update(f_dds); | 1040 | 1040 | sendIOUpdate(f_dds); | |
1041 | 1041 | |||
return EXIT_SUCCESS; | 1042 | 1042 | return EXIT_SUCCESS; | |
} | 1043 | 1043 | } | |
1044 | 1044 | |||
int ContinuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown) | 1045 | 1045 | int continuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown) | |
{ | 1046 | 1046 | { | |
1047 | 1047 | |||
1048 | 1048 | |||
//calcul de N => N=Deltaphi/dphi = DeltaT/dt | 1049 | 1049 | //calcul de N => N=Deltaphi/dphi = DeltaT/dt | |
1050 | 1050 | |||
//1-phimax > phimin | 1051 | 1051 | //1-phimax > phimin | |
double DeltaPhi = PhiMax-PhiMin; | 1052 | 1052 | double DeltaPhi = PhiMax-PhiMin; | |
if(PhiMax<PhiMin) | 1053 | 1053 | if(PhiMax<PhiMin) | |
{ | 1054 | 1054 | { | |
printf("PhiMax should be > PhiMin\n"); | 1055 | 1055 | printf("PhiMax should be > PhiMin\n"); | |
printf("Can't Start the ramp\n"); | 1056 | 1056 | printf("Can't Start the ramp\n"); | |
return -1; | 1057 | 1057 | return -1; | |
} | 1058 | 1058 | } | |
1059 | 1059 | |||
1060 | 1060 | |||
//2- Calcul du nombre de points de la rampe | 1061 | 1061 | //2- Calcul du nombre de points de la rampe | |
int NumberPointsUp = DeltaPhi/dphiUp; | 1062 | 1062 | int NumberPointsUp = DeltaPhi/dphiUp; | |
int NumberPointsDown = DeltaPhi/dphiDown; | 1063 | 1063 | int NumberPointsDown = DeltaPhi/dphiDown; | |
1064 | 1064 | |||
printf("NumberPointsUp = %d\n",NumberPointsUp); | 1065 | 1065 | printf("NumberPointsUp = %d\n",NumberPointsUp); | |
printf("NumberPointsDown = %d\n",NumberPointsDown); | 1066 | 1066 | printf("NumberPointsDown = %d\n",NumberPointsDown); | |
1067 | 1067 | |||
//3- En déduire la valeur de dtUp et dtDown | 1068 | 1068 | //3- En déduire la valeur de dtUp et dtDown | |
double dtUp = DeltaTimeUp/NumberPointsUp; | 1069 | 1069 | double dtUp = DeltaTimeUp/NumberPointsUp; | |
double dtDown = DeltaTimeDown/NumberPointsDown; | 1070 | 1070 | double dtDown = DeltaTimeDown/NumberPointsDown; | |
1071 | 1071 | |||
double dtmin = 24/fclk; | 1072 | 1072 | double dtmin = 24/fclk; | |
double dtmax = dtmin*(pow(2.0,16.0)-1); | 1073 | 1073 | double dtmax = dtmin*(pow(2.0,16.0)-1); | |
1074 | 1074 | |||
//Check Up | 1075 | 1075 | //Check Up | |
if(dtUp<dtmin) | 1076 | 1076 | if(dtUp<dtmin) | |
{ | 1077 | 1077 | { | |
printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | 1078 | 1078 | printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 1079 | 1079 | printf("Can't start the ramp\n"); | |
return -1; | 1080 | 1080 | return -1; | |
} | 1081 | 1081 | } | |
1082 | 1082 | |||
if(dtUp>dtmax) | 1083 | 1083 | if(dtUp>dtmax) | |
{ | 1084 | 1084 | { | |
printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | 1085 | 1085 | printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
printf("Can't start the ramp\n"); | 1086 | 1086 | printf("Can't start the ramp\n"); | |
return -1; | 1087 | 1087 | return -1; | |
} | 1088 | 1088 | } | |
1089 | 1089 | |||
//Check Down | 1090 | 1090 | //Check Down | |
if(dtDown<dtmin) | 1091 | 1091 | if(dtDown<dtmin) | |
{ | 1092 | 1092 | { | |
printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | 1093 | 1093 | printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 1094 | 1094 | printf("Can't start the ramp\n"); | |
return -1; | 1095 | 1095 | return -1; | |
} | 1096 | 1096 | } | |
1097 | 1097 | |||
if(dtDown>dtmax) | 1098 | 1098 | if(dtDown>dtmax) | |
{ | 1099 | 1099 | { | |
printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | 1100 | 1100 | printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
printf("Can't start the ramp\n"); | 1101 | 1101 | printf("Can't start the ramp\n"); | |
return -1; | 1102 | 1102 | return -1; | |
} | 1103 | 1103 | } | |
1104 | 1104 | |||
1105 | 1105 | |||
1106 | 1106 | |||
//check if DeltaAmp is enouth | 1107 | 1107 | //check if DeltaAmp is enouth | |
/* | 1108 | 1108 | /* | |
double enouthUP=0.5*NumberPointsUp*100/4095; | 1109 | 1109 | double enouthUP=0.5*NumberPointsUp*100/4095; | |
double enouthDOWN=0.5*NumberPointsDown*100/4095; | 1110 | 1110 | double enouthDOWN=0.5*NumberPointsDown*100/4095; | |
1111 | 1111 | |||
int borneUP = rint(enouthUP); | 1112 | 1112 | int borneUP = rint(enouthUP); | |
int borneDown = rint(enouthDOWN); | 1113 | 1113 | int borneDown = rint(enouthDOWN); | |
1114 | 1114 | |||
if(DeltaAmp<=enouthUP) | 1115 | 1115 | if(DeltaAmp<=enouthUP) | |
{ | 1116 | 1116 | { | |
printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | 1117 | 1117 | printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | |
//return -1; | 1118 | 1118 | //return -1; | |
} | 1119 | 1119 | } | |
1120 | 1120 | |||
if(DeltaAmp<=enouthDOWN) | 1121 | 1121 | if(DeltaAmp<=enouthDOWN) | |
{ | 1122 | 1122 | { | |
printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | 1123 | 1123 | printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | |
//return -1; | 1124 | 1124 | //return -1; | |
} | 1125 | 1125 | } | |
1126 | 1126 | |||
*/ | 1127 | 1127 | */ | |
1128 | 1128 | |||
//4 - Put word in register | 1129 | 1129 | //4 - Put word in register | |
1130 | 1130 | |||
1131 | 1131 | |||
//4.1 Limit register | 1132 | 1132 | //4.1 Limit register | |
uint32_t WordPhimin = rint(PhiMin*65535/360); | 1133 | 1133 | uint32_t WordPhimin = rint(PhiMin*65535/360); | |
uint32_t WordPhimax= rint(PhiMax*65535/360); | 1134 | 1134 | uint32_t WordPhimax= rint(PhiMax*65535/360); | |
1135 | 1135 | |||
1136 | 1136 | |||
printf("WordPhimin = %.32x\n",WordPhimin); | 1137 | 1137 | printf("WordPhimin = %.32x\n",WordPhimin); | |
printf("WordPhimax = %.32x\n",WordPhimax); | 1138 | 1138 | printf("WordPhimax = %.32x\n",WordPhimax); | |
1139 | 1139 | |||
1140 | 1140 | |||
write_register(fd,0x04,WordPhimin>>24&0xFF,WordPhimin>>16&0xFF,WordPhimin>>8&0xFF,WordPhimin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | 1141 | 1141 | writeRegister(fd,0x04,WordPhimin>>24&0xFF,WordPhimin>>16&0xFF,WordPhimin>>8&0xFF,WordPhimin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | |
Send_IO_Update(f_dds); | 1142 | 1142 | sendIOUpdate(f_dds); | |
write_register(fd,0x05,WordPhimax>>24&0xFF,WordPhimax>>16&0xFF,WordPhimax>>8&0xFF,WordPhimax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | 1143 | 1143 | writeRegister(fd,0x05,WordPhimax>>24&0xFF,WordPhimax>>16&0xFF,WordPhimax>>8&0xFF,WordPhimax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | |
Send_IO_Update(f_dds); | 1144 | 1144 | sendIOUpdate(f_dds); | |
1145 | 1145 | |||
1146 | 1146 | |||
//4.2 dphiUP et dphiDown | 1147 | 1147 | //4.2 dphiUP et dphiDown | |
1148 | 1148 | |||
// uint32_t Word_dphi_up = rint(dphiUp*(pow(2.0,29.0)-1)/45); | 1149 | 1149 | // uint32_t Word_dphi_up = rint(dphiUp*(pow(2.0,29.0)-1)/45); | |
// uint32_t Word_dphi_down = rint(dphiDown*(pow(2.0,29.0)-1)/45); | 1150 | 1150 | // uint32_t Word_dphi_down = rint(dphiDown*(pow(2.0,29.0)-1)/45); | |
uint32_t Word_dphi_up = rint(dphiUp*(65535/360)); | 1151 | 1151 | uint32_t Word_dphi_up = rint(dphiUp*(65535/360)); | |
uint32_t Word_dphi_down = rint(dphiDown*(65535/360)); | 1152 | 1152 | uint32_t Word_dphi_down = rint(dphiDown*(65535/360)); | |
1153 | 1153 | |||
printf("Word_dphi_up = %.32x\n",Word_dphi_up); | 1154 | 1154 | printf("Word_dphi_up = %.32x\n",Word_dphi_up); | |
printf("Word_dphi_down = %.32x\n",Word_dphi_down); | 1155 | 1155 | printf("Word_dphi_down = %.32x\n",Word_dphi_down); | |
1156 | 1156 | |||
/* | 1157 | 1157 | /* | |
write_register(fd,0x06,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up>>0&0xFF,Word_dphi_up&0xFF); //dphi_up | 1158 | 1158 | writeRegister(fd,0x06,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up>>0&0xFF,Word_dphi_up&0xFF); //dphi_up | |
Send_IO_Update(f_dds); | 1159 | 1159 | sendIOUpdate(f_dds); | |
write_register(fd,0x07,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down>>0&0xFF,Word_dphi_down&0xFF);//dphi_down | 1160 | 1160 | writeRegister(fd,0x07,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down>>0&0xFF,Word_dphi_down&0xFF);//dphi_down | |
Send_IO_Update(f_dds); | 1161 | 1161 | sendIOUpdate(f_dds); | |
1162 | 1162 | |||
*/ | 1163 | 1163 | */ | |
1164 | 1164 | |||
1165 | 1165 | |||
write_register(fd,0x06,Word_dphi_up>>24&0xFF,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up&0xFF); //dA_up | 1166 | 1166 | writeRegister(fd,0x06,Word_dphi_up>>24&0xFF,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up&0xFF); //dA_up | |
Send_IO_Update(f_dds); | 1167 | 1167 | sendIOUpdate(f_dds); | |
write_register(fd,0x07,Word_dphi_down>>24&0xFF,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down&0xFF);//dA_down | 1168 | 1168 | writeRegister(fd,0x07,Word_dphi_down>>24&0xFF,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down&0xFF);//dA_down | |
Send_IO_Update(f_dds); | 1169 | 1169 | sendIOUpdate(f_dds); | |
1170 | 1170 | |||
1171 | 1171 | |||
//4.3 dtUp et dtDown | 1172 | 1172 | //4.3 dtUp et dtDown | |
1173 | 1173 | |||
uint16_t Word_dt_up = rint(dtUp*fclk/24); | 1174 | 1174 | uint16_t Word_dt_up = rint(dtUp*fclk/24); | |
uint16_t Word_dt_down = rint(dtDown*fclk/24); | 1175 | 1175 | uint16_t Word_dt_down = rint(dtDown*fclk/24); | |
1176 | 1176 | |||
write_register(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | 1177 | 1177 | writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt | |
Send_IO_Update(f_dds); | 1178 | 1178 | sendIOUpdate(f_dds); | |
1179 | 1179 | |||
//5 Start of the ramp | 1180 | 1180 | //5 Start of the ramp | |
1181 | 1181 | |||
write_register(fd,0x01,0x00,0x9E,0x29,0x00); //rampe simple montante | 1182 | 1182 | writeRegister(fd,0x01,0x00,0x9E,0x29,0x00); //rampe simple montante | |
Send_IO_Update(f_dds); | 1183 | 1183 | sendIOUpdate(f_dds); | |
1184 | 1184 | |||
return EXIT_SUCCESS; | 1185 | 1185 | return EXIT_SUCCESS; | |
} | 1186 | 1186 | } | |
1187 | 1187 | |||
1188 | 1188 | |||
//-------------------------FIN FONCTIONS RAMPES HARDWARES | 1189 | 1189 | //-------------------------FIN FONCTIONS RAMPES HARDWARES | |
1190 | 1190 | |||
//--------------------------FONCTIONS RAMPES SOFTWARES | 1191 | 1191 | //--------------------------FONCTIONS RAMPES SOFTWARES | |
1192 | 1192 | |||
int RampAmpFromSoft(int fd, int f_dds,double DeltaTimeUp,double AIni, double AFin) | 1193 | 1193 | int rampAmpFromSoft(int fd, int f_dds,double DeltaTimeUp,double AIni, double AFin) | |
{ | 1194 | 1194 | { | |
1195 | 1195 | |||
//On va plutôt fixé dA sinon trop de contrainte : => Besoin d'allocation dynamique | 1196 | 1196 | //On va plutôt fixé dA sinon trop de contrainte : => Besoin d'allocation dynamique | |
double dA=0.024;//en % | 1197 | 1197 | double dA=0.024;//en % | |
double DeltaAmp = AIni-AFin; | 1198 | 1198 | double DeltaAmp = AIni-AFin; | |
double AbsDeltaAmp = 0; | 1199 | 1199 | double AbsDeltaAmp = 0; | |
if(DeltaAmp>=0) | 1200 | 1200 | if(DeltaAmp>=0) | |
{ | 1201 | 1201 | { | |
AbsDeltaAmp = DeltaAmp; | 1202 | 1202 | AbsDeltaAmp = DeltaAmp; | |
} | 1203 | 1203 | } | |
else | 1204 | 1204 | else | |
{ | 1205 | 1205 | { | |
AbsDeltaAmp = -1*DeltaAmp; | 1206 | 1206 | AbsDeltaAmp = -1*DeltaAmp; | |
} | 1207 | 1207 | } | |
1208 | 1208 | |||
int NumberPoints = AbsDeltaAmp/dA; | 1209 | 1209 | int NumberPoints = AbsDeltaAmp/dA; | |
1210 | 1210 | |||
double dt=DeltaTimeUp/NumberPoints; | 1211 | 1211 | double dt=DeltaTimeUp/NumberPoints; | |
1212 | 1212 | |||
printf("Taille du tableau = %d\n", NumberPoints); | 1213 | 1213 | printf("Taille du tableau = %d\n", NumberPoints); | |
printf("dt = %f s\n",dt); | 1214 | 1214 | printf("dt = %f s\n",dt); | |
1215 | 1215 | |||
1216 | 1216 | |||
uint16_t* ArrayWordAmp= NULL; | 1217 | 1217 | uint16_t* ArrayWordAmp= NULL; | |
ArrayWordAmp = malloc(NumberPoints*sizeof(uint16_t)); | 1218 | 1218 | ArrayWordAmp = malloc(NumberPoints*sizeof(uint16_t)); | |
1219 | 1219 | |||
//extraction de la phase initiale et de l'amplitude | 1220 | 1220 | //extraction de la phase initiale et de l'amplitude | |
1221 | 1221 | |||
uint32_t ReadPhaseAmpWord = 0x00000000; | 1222 | 1222 | uint32_t ReadPhaseAmpWord = 0x00000000; | |
read_register(fd, 0x0c,&ReadPhaseAmpWord); | 1223 | 1223 | readRegister(fd, 0x0c,&ReadPhaseAmpWord); | |
printf("ReadPhaseAmpWord = %.8x \n", ReadPhaseAmpWord); | 1224 | 1224 | printf("ReadPhaseAmpWord = %.8x \n", ReadPhaseAmpWord); | |
1225 | 1225 | |||
uint16_t WordPhaseInitiale = ReadPhaseAmpWord&0xFFFF; | 1226 | 1226 | uint16_t WordPhaseInitiale = ReadPhaseAmpWord&0xFFFF; | |
printf("Phase = %.4x \n", WordPhaseInitiale); | 1227 | 1227 | printf("Phase = %.4x \n", WordPhaseInitiale); | |
1228 | 1228 | |||
1229 | 1229 | |||
// | 1230 | 1230 | // | |
for(int i=0;i<NumberPoints;i++) | 1231 | 1231 | for(int i=0;i<NumberPoints;i++) | |
{ | 1232 | 1232 | { | |
ArrayWordAmp[i]=rint((AIni+i*dA)*4096/100); | 1233 | 1233 | ArrayWordAmp[i]=rint((AIni+i*dA)*4096/100); | |
// printf("ArrayWordAmp[%d] = %.16x\n", i, ArrayWordAmp[i]); | 1234 | 1234 | // printf("ArrayWordAmp[%d] = %.16x\n", i, ArrayWordAmp[i]); | |
} | 1235 | 1235 | } |