From e41d5220b5a139824483e540c0dbaf6473260c43 Mon Sep 17 00:00:00 2001 From: bachi Date: Fri, 5 Apr 2019 13:55:22 +0200 Subject: [PATCH] ad9915.c : nettoyage des commentaires et du superflu(initialisation a 0 etc --- src/ad9915.c | 289 +++++------------------------------------------------------ 1 file changed, 23 insertions(+), 266 deletions(-) diff --git a/src/ad9915.c b/src/ad9915.c index 6ed1d6e..9213645 100644 --- a/src/ad9915.c +++ b/src/ad9915.c @@ -9,17 +9,13 @@ //fonction reset void sendReset(int f_dds) { - char reset='2'; - write(f_dds,&reset,sizeof(reset)); //reset - sleep(0.1); + write(f_dds,"2",1); } //fonction ioupdate void sendIOUpdate(int f_dds) { - char update='1'; - write(f_dds,&update,sizeof(update)); //reset - sleep(0.1); + write(f_dds,"1",1); } //fonction write register @@ -93,7 +89,6 @@ void calibrateDAC (int fd, int f_dds) void modulusSetup(int fd, int f_dds) { writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x0a); //OSK enable //0x08 - //writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable de base sendIOUpdate (f_dds); writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp sendIOUpdate (f_dds); @@ -105,36 +100,24 @@ void basicSetup(int fd, int f_dds,uint16_t ampWord, uint16_t phaseWord) sendIOUpdate (f_dds); writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp sendIOUpdate (f_dds); - writeRegister(fd,0x04,0x19, 0x99, 0x99, 0x99); //ftw + writeRegister(fd,0x04,0x19, 0x99, 0x99, 0x99); //ftw sendIOUpdate (f_dds); - writeRegister(fd,0x05,0xC0, 0x00, 0x00, 0x00); //A + writeRegister(fd,0x05,0xC0, 0x00, 0x00, 0x00); //A sendIOUpdate (f_dds); - writeRegister(fd,0x06,0x00, 0x00, 0x00, 0x05); //B + writeRegister(fd,0x06,0x00, 0x00, 0x00, 0x05); //B sendIOUpdate (f_dds); - //writeRegister(fd,0x0c, 0x0F, 0xFF, 0x00, 0x00); // amp (12b) ph(16) - 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) + 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) sendIOUpdate (f_dds); } void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B) { - //uint16_t phaseWord = 0x7400; - //uint16_t ampWord = (uint16_t)strtol(argv[4],NULL,0) & 0x0FFF ; //masque en 2 - //uint16_t ampWord = 0x00000FFF; - //uint32_t phaseAmpWord = phaseWord | ampWord<<16; - - //writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable - //sendIOUpdate(f_dds); - //writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp - //sendIOUpdate(f_dds); writeRegister(fd,0x04,ftw>>24&0xFF, ftw>>16&0xFF, ftw>>8&0xFF, ftw&0xFF); //ftw sendIOUpdate(f_dds); writeRegister(fd,0x05,A>>24&0xFF,A>>16&0xFF, A>>8&0xFF, A&0xFF); //A sendIOUpdate(f_dds); writeRegister(fd,0x06,B>>24&0xFF,B>>16&0xFF, B>>8&0xFF, B&0xFF); //B sendIOUpdate(f_dds); - // writeRegister(fd,0x0c, phaseAmpWord>>24&0xFF, phaseAmpWord>>16&0xFF,phaseAmpWord>>8&0xFF,phaseAmpWord&0xFF); // amp (12b) ph(16) - //sendIOUpdate(f_dds); } void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord) @@ -143,20 +126,6 @@ void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord) sendIOUpdate(f_dds); } -/* -void getAmpPhaseWord(int fd) -{ - // unsigned char rx[5]={0}; - unsigned char* pt; - readRegister(fd,0x0c,rx); // amp (12b) ph(16) - rx[0]=*pt; - rx[1]=*(pt+1); - rx[2]=*(pt+2); - rx[3]=*(pt+3); - rx[4]=*(pt+4); - printf("%c %c %c %c %c", rx[0], rx[1], rx[2], rx[3], rx[4]); -} -*/ void checkSize(void) { printf("int : %d\n",sizeof(unsigned int)); @@ -207,30 +176,26 @@ int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t amp void sendCtrlUp(int fp) { - char DRCTLOn='0';//pente positive - write(fp,&DRCTLOn,sizeof(DRCTLOn)); // - sleep(0.1); + //pente positive + write(fp,"0",1); } void sendCtrlDown(int fp) { - char DRCTLOn='2';//pente negative - write(fp,&DRCTLOn,sizeof(DRCTLOn)); //reset - sleep(0.1); + //pente negative + write(fp,"2",1); } void sendHold(int fp) { - char DRHOLDOn ='1';//rampe bloquée - write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset - sleep(0.1); + //rampe bloquee + write(fp,"1",1); } void sendUnhold(int fp) { - char DRHOLDOn ='3';//rampe debloquée - write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset - sleep(0.1); + //rampe debloquee + write(fp,"3",1); //reset } @@ -254,16 +219,6 @@ int testRampFreq(int fd, int f_dds, int fp) sendIOUpdate(f_dds); readRegisterIni(fd,0x00); - //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³² - // FTW = 42949672.96 = 42 949 673. = 0x028f5c29 - // 1.1e7 =0x02d0e560 - -// 2d0e560 - - //Calibrate_DAC (fd,f_dds); - - writeRegister(fd,0x0b,0x02,0xd0,0xe5,0x60);//mot de frequence sendIOUpdate(f_dds); @@ -276,71 +231,10 @@ int testRampFreq(int fd, int f_dds, int fp) printf("Lecture registre de amp et phase: 0x0c\n"); readRegisterIni(fd,0x0c); - Calibrate_DAC (fd,f_dds); + calibrateDAC (fd,f_dds); printf("\n\n ----------------------- \n\n"); -/* - //2- Taille des dt - - writeRegister(fd,0x08,0xFF,0xFF,0xFF,0xFF); //+dt max, -dt max (+dt = -dt) - sendIOUpdate(f_dds); - - printf("Les mots de dt sont envoyes\n"); - printf("Lecture dans le registre 0x08 : taille dt\n"); - readRegisterIni (fd,0x08); - - - - - printf("\n\n ----------------------- \n\n"); - - - //3- STEP SIZE :dphi - - // en theorie dphi =2.25e-28 degrees - writeRegister(fd,0x06,0x00,0x00,0x00,0x01); - sendIOUpdate(f_dds); - - writeRegister(fd,0x07,0x00,0x00,0x00,0x01); - sendIOUpdate(f_dds); - - //printf("\n\n ----------------------- \n\n"); - printf("Les mots de dphi sont envoyes\n"); - printf("Lecture dans les registres 0x06 et 0x07 : taille dt\n"); - readRegisterIni (fd,0x06); - readRegisterIni (fd,0x07); - - printf("\n\n ----------------------- \n\n"); - //4- Ecrire les extremums de la rampe - - writeRegister(fd,0x04,0x00,0x00,0x00,0x01);//0 rad - sendIOUpdate(f_dds); - writeRegister(fd,0x05,0xFF,0xFF,0xFF,0xFF);//2*pi rad - sendIOUpdate(f_dds); - - printf("Les mots des frontieres sont envoyes\n"); - printf("Lecture dans les registres 0x04 et 0x05 : taille dt\n"); - readRegisterIni (fd,0x04); - readRegisterIni (fd,0x05); - - - //3-Rampe de pente positive ou négative -// Send_CTRL_UP(fp);//rampe up - - - //4-ecriture dans le registre 0x01 - writeRegister(fd,0x01,0x00, 0xa8, 0x09, 0x00); // enable amp ramp - sendIOUpdate(f_dds); - - printf("Lecture dans le registre 0x01 : \n"); - readRegisterIni (fd,0x01); -// printf("Les mots de dt sont envoyes\n"); - printf("Lecture dans le registre 0x08 : taille dt\n"); - readRegisterIni (fd,0x08); - - -*/ return EXIT_SUCCESS; } @@ -367,15 +261,15 @@ int putAmpWord(int fd, int f_dds, double amplitude) int putPhaseWord(int fd, int f_dds, double phase) { - uint16_t PhaseWord = 0x0000; - uint16_t AmpWord = 0x0000; + //uint16_t PhaseWord = 0x0000; + //uint16_t AmpWord = 0x0000; uint32_t ReadPhaseAmpWord=0x00000000; - PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360); + uint16_t PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360); readRegister(fd,0x0c,&ReadPhaseAmpWord); - AmpWord = ReadPhaseAmpWord>>16&0xFFFF; + uint16_t AmpWord = ReadPhaseAmpWord>>16&0xFFFF; writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); sendIOUpdate(f_dds); @@ -386,8 +280,8 @@ int putPhaseWord(int fd, int f_dds, double phase) int putFrequencyWord(int fd, int f_dds, double fclk,double fout)//Attention uniquement valable pour fclk = 1 GHz { - uint32_t FTWR = 0x00000000; - FTWR = rint((fout/fclk)*pow(2.0,32.0)); + //uint32_t FTWR = 0x00000000; + uint32_t FTWR = rint((fout/fclk)*pow(2.0,32.0)); writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence sendIOUpdate(f_dds); @@ -398,17 +292,14 @@ int putFrequencyWord(int fd, int f_dds, double fclk,double fout)//Attention uniq int putFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase)//n'existe pas dans le mode profile enable { - uint32_t FTWR = 0x00000000; + //uint32_t FTWR = 0x00000000; - FTWR = rint((fout/fclk)*pow(2.0,32.0)); + uint32_t FTWR = rint((fout/fclk)*pow(2.0,32.0)); writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence sendIOUpdate(f_dds); -// writeRegister(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle -// sendIOUpdate(f_dds); - putPhaseWord(fd,f_dds,phase); putAmpWord(fd,f_dds,amp); @@ -725,13 +616,11 @@ int amplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, do if(DeltaAmp<=enouthUP) { printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); - //return -1; } if(DeltaAmp<=enouthDOWN) { printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); - //return -1; } @@ -960,32 +849,6 @@ int phaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, do } - - //check if DeltaAmp is enouth -/* - double enouthUP=0.5*NumberPointsUp*100/4095; - double enouthDOWN=0.5*NumberPointsDown*100/4095; - - int borneUP = rint(enouthUP); - int borneDown = rint(enouthDOWN); - - if(DeltaAmp<=enouthUP) - { - printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); - //return -1; - } - - if(DeltaAmp<=enouthDOWN) - { - printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); - //return -1; - } - -*/ - - //4 - Put word in register - - //4.1 Limit register uint32_t WordPhimin = rint(PhiMin*65535/360); uint32_t WordPhimax= rint(PhiMax*65535/360); @@ -1003,22 +866,12 @@ int phaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, do //4.2 dphiUP et dphiDown -// 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); uint32_t Word_dphi_up = rint(dphiUp*(65535/360)); uint32_t Word_dphi_down = rint(dphiDown*(65535/360)); printf("Word_dphi_up = %.32x\n",Word_dphi_up); printf("Word_dphi_down = %.32x\n",Word_dphi_down); -/* - writeRegister(fd,0x06,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up>>0&0xFF,Word_dphi_up&0xFF); //dphi_up - sendIOUpdate(f_dds); - writeRegister(fd,0x07,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down>>0&0xFF,Word_dphi_down&0xFF);//dphi_down - sendIOUpdate(f_dds); - -*/ - writeRegister(fd,0x06,Word_dphi_up>>24&0xFF,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up&0xFF); //dA_up sendIOUpdate(f_dds); @@ -1103,29 +956,6 @@ int continuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphi } - - //check if DeltaAmp is enouth -/* - double enouthUP=0.5*NumberPointsUp*100/4095; - double enouthDOWN=0.5*NumberPointsDown*100/4095; - - int borneUP = rint(enouthUP); - int borneDown = rint(enouthDOWN); - - if(DeltaAmp<=enouthUP) - { - printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); - //return -1; - } - - if(DeltaAmp<=enouthDOWN) - { - printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); - //return -1; - } - -*/ - //4 - Put word in register @@ -1146,23 +976,12 @@ int continuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphi //4.2 dphiUP et dphiDown -// 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); uint32_t Word_dphi_up = rint(dphiUp*(65535/360)); uint32_t Word_dphi_down = rint(dphiDown*(65535/360)); printf("Word_dphi_up = %.32x\n",Word_dphi_up); printf("Word_dphi_down = %.32x\n",Word_dphi_down); -/* - writeRegister(fd,0x06,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up>>0&0xFF,Word_dphi_up&0xFF); //dphi_up - sendIOUpdate(f_dds); - writeRegister(fd,0x07,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down>>0&0xFF,Word_dphi_down&0xFF);//dphi_down - sendIOUpdate(f_dds); - -*/ - - writeRegister(fd,0x06,Word_dphi_up>>24&0xFF,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up&0xFF); //dA_up sendIOUpdate(f_dds); writeRegister(fd,0x07,Word_dphi_down>>24&0xFF,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down&0xFF);//dA_down @@ -1247,68 +1066,6 @@ int rampAmpFromSoft(int fd, int f_dds,double DeltaTimeUp,double AIni, double AFi -/* - uint16_t PhaseWord = 0x0000; - uint16_t AmpWord = 0x0000; - uint32_t ReadPhaseAmpWord=0x00000000; - - AmpWord = rint(amplitude*(pow(2.0,12.0)-1)/100); - - readRegister(fd,0x0c,&ReadPhaseAmpWord); - - PhaseWord = ReadPhaseAmpWord&0xFFFF; - - writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); - -*/ - - - -/* - - //pas de durée dtUp et dtDown fixée au minimum à 1 ms - if(DeltaTimeUp < 4.095) - { - printf("Use hardware fonctions for the ramp\n"); - } - - - // - double DeltaAmp = AMax-AMin; - double dA = DeltaAmp/TAILLETAB; - printf("dA=%f\n",dA); - - - if(dA<0.024) - { - printf("Amplitude step should be > 0.024 pourcent\n"); - printf("Impossible to start a ramp of amplitude\n"); - return -1; - } - - //extraction de la phase initiale et de l'amplitude - - uint32_t ReadPhaseAmpWord = 0x00000000; - readRegister(fd, 0x0c,&ReadPhaseAmpWord); - printf("ReadPhaseAmpWord = %.8x \n", ReadPhaseAmpWord); - - uint16_t WordPhaseInitiale = ReadPhaseAmpWord&0xFFFF; - printf("Phase = %.4x \n", WordPhaseInitiale); - - uint16_t WordAmpInitiale = ReadPhaseAmpWord>>16&0xFFFF; - printf("Amp = %.4x \n", WordAmpInitiale); - - uint16_t Word_dA = rint(dA*4095/100); - - uint32_t ArrayWordAmp[TAILLETAB]; - - for(int i=0;i