/* SPI : initialisation du dds et communication SPI */ #include"ad9915.h" #include "spi.h" #include "ddsFreq.h" #define debug //fonction reset void sendReset(int f_dds) { write(f_dds,"2",1); } //fonction ioupdate void sendIOUpdate(int f_dds) { write(f_dds,"1",1); } //fonction write register void writeRegister (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0) { unsigned char tx[5]={0}; tx[0]=addr; tx[1]=d3; tx[2]=d2; tx[3]=d1; tx[4]=d0; //spi_put_multiple envoie le vecteur dans cet ordre //[tx0]-[tx1]-[tx2] -> adresse->bit poids Fort->bit poids faible spi_put_multiple(fd,tx,5,NULL,0); } //fonction read register void readRegister (int fd,unsigned char addr, uint32_t *readword) { unsigned char tx[1] = {0}; unsigned char rx[4] = {0}; addr = addr|0x80;//instruction byte for the read : 1000 0000 | byte_adress tx[0]=addr; 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]); *readword = 0x00000000; *readword = *readword|(rx[0]<<24); *readword = *readword|(rx[1]<<16); *readword = *readword|(rx[2]<<8); *readword = *readword|rx[3]; } //fonction read register void readRegisterIni (int fd, unsigned char addr) { unsigned char tx[1] = {0}; unsigned char rx[4] = {0}; addr = addr|0x80; tx[0]=addr; 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]); // sendIOUpdate (f_dds); //Send the update to set the control registers } //initialisation du dds void initializeDDS (int fd, int f_dds) { sendReset(f_dds); writeRegister(fd,CFRAddress[0],CFR1Start[0], CFR1Start[1], CFR1Start[2], CFR1Start[3]); sendIOUpdate (f_dds); //Send the update to set the control registers writeRegister(fd,CFRAddress[1], CFR2Start[0], CFR2Start[1], CFR2Start[2], CFR2Start[3]); sendIOUpdate (f_dds); writeRegister(fd,CFRAddress[2], CFR3Start[0], CFR3Start[1], CFR3Start[2], CFR3Start[3]); sendIOUpdate (f_dds); writeRegister(fd,CFRAddress[3], CFR4Start[0], CFR4Start[1], CFR4Start[2], CFR4Start[3]); sendIOUpdate (f_dds); writeRegister(fd,USR0Address, 0xA2, 0x00, 0x08, 0x00); sendIOUpdate (f_dds); } //calibration du dac void calibrateDAC (int fd, int f_dds) { writeRegister(fd,CFRAddress[3], DACCalEnable[0], DACCalEnable[1], DACCalEnable[2], DACCalEnable[3]); sendIOUpdate (f_dds); writeRegister(fd,CFRAddress[3], CFR4Start[0], CFR4Start[1], CFR4Start[2], CFR4Start[3]); sendIOUpdate (f_dds); } void modulusSetup(int fd, int f_dds) { writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x0a); //OSK enable //0x08 sendIOUpdate (f_dds); writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp sendIOUpdate (f_dds); } void basicSetup(int fd, int f_dds,uint16_t ampWord, uint16_t phaseWord) { 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,0x19, 0x99, 0x99, 0x99); //ftw sendIOUpdate (f_dds); writeRegister(fd,0x05,0xC0, 0x00, 0x00, 0x00); //A sendIOUpdate (f_dds); writeRegister(fd,0x06,0x00, 0x00, 0x00, 0x05); //B sendIOUpdate (f_dds); 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) { 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); } void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord) { writeRegister(fd,0x0c, phaseAmpWord>>24&0xFF, phaseAmpWord>>16&0xFF,phaseAmpWord>>8&0xFF,phaseAmpWord&0xFF); // amp (12b) ph(16) sendIOUpdate(f_dds); } void checkSize(void) { printf("int : %d\n",sizeof(unsigned int)); } int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord) { #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); #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); int fd=configureSpi(device); //ex #define FILENAME2 "/dev/spidev0.0" printf("fd(funct)=%d\n",fd); setMode(fd,SPI_MODE_0); if (fd <= 0){ printf("ERREUR : ouverture périphérique SPI %s\n",device); return EXIT_FAILURE; } int f_dds=open(gpio_update,O_RDWR); //ex #define UPDATE2 "/sys/dds/gpio24/updateOn" printf("f_dds(funct)=%d\n",f_dds); if (f_dds <= 0){ printf("ERREUR : ouverture ");printf(gpio_update);printf("\n"); printf("Chargez le module ddsIOupdateX\n"); return EXIT_FAILURE; } setddsFreq(fd,f_dds,f_out,f_clk); //debug phaseWord = 0x0000; ampWord=0x0FFF; uint32_t phaseAmpWord = phaseWord | ampWord<<16; setAmpPhaseWord(fd, f_dds, phaseAmpWord); #endif return EXIT_SUCCESS; } int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord) { setddsFreq(fd,f_dds,f_out,f_clk); #ifdef debug phaseWord = 0x0000; ampWord=0x0FFF; #endif uint32_t phaseAmpWord = phaseWord | ampWord<<16; setAmpPhaseWord(fd, f_dds, phaseAmpWord); return EXIT_SUCCESS; } void sendCtrlUp(int fp) { //pente positive write(fp,"0",1); } void sendCtrlDown(int fp) { //pente negative write(fp,"2",1); } void sendHold(int fp) { //rampe bloquee write(fp,"1",1); } void sendUnhold(int fp) { //rampe debloquee write(fp,"3",1); //reset } int testRampFreq(int fd, int f_dds, int fp) { //3-Rampe de pente positive + debloquage sendCtrlDown(fp);//rampe up sendUnhold(fp); sendReset(f_dds); //Initialize_DDS (fd, f_dds); //0- paramètre de bases writeRegister(fd,0x00,0x00,0x01,0x01,0x0a);//OSKenable+Read&write sendIOUpdate(f_dds); readRegisterIni(fd,0x00); writeRegister(fd,0x01,0x00, 0x00, 0x09, 0x00); // enable amp ramp sendIOUpdate(f_dds); readRegisterIni(fd,0x00); writeRegister(fd,0x0b,0x02,0xd0,0xe5,0x60);//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); printf("Les mots de frequences, d'amplitudes et de phases sont envoyes\n"); printf("Lecture registre de frequence: 0x0b\n"); readRegisterIni(fd,0x0b); printf("Lecture registre de amp et phase: 0x0c\n"); readRegisterIni(fd,0x0c); calibrateDAC (fd,f_dds); printf("\n\n ----------------------- \n\n"); return EXIT_SUCCESS; } //---------------rajout 8/1 int putAmpWord(int fd, int f_dds, double amplitude) { 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); sendIOUpdate(f_dds); return 0; } int putPhaseWord(int fd, int f_dds, double phase) { //uint16_t PhaseWord = 0x0000; //uint16_t AmpWord = 0x0000; uint32_t ReadPhaseAmpWord=0x00000000; uint16_t PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360); readRegister(fd,0x0c,&ReadPhaseAmpWord); uint16_t AmpWord = ReadPhaseAmpWord>>16&0xFFFF; writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); sendIOUpdate(f_dds); return 0; } int putFrequencyWord(int fd, int f_dds, double fclk,double fout)//Attention uniquement valable pour fclk = 1 GHz { //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); return 0; } 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 = 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); putPhaseWord(fd,f_dds,phase); putAmpWord(fd,f_dds,amp); return 0; } int initialisationProfileMode (int fd,int f_dds) { sendReset(f_dds); //les registres sont maintenant par defaut writeRegister(fd,0x00,0x00,0x01,0x01,0x0a); //OSK+SDIO input only//ok sendIOUpdate(f_dds); writeRegister(fd,0x01,0x00,0x80,0x09,0x00); // profile mode enable very important sendIOUpdate(f_dds); writeRegister(fd,0x02,0x00,0x00,0x19,0x1c); // default sendIOUpdate(f_dds); writeRegister(fd,0x03,0x01,0x05,0x21,0x20); // calibration 1/2 :enable sendIOUpdate(f_dds); writeRegister(fd,0x03,0x00,0x05,0x21,0x20); // calibration 2/2 :desenable sendIOUpdate(f_dds); return 0; } //------------------- FIN RAJOUT 8/1 //-------------------------FONCTIONS RAMPES HARDWARE //1-rampe de frequence //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) { //calcul de N => N=DeltaF/df = DeltaT/dt //1-fmax > fmin double DeltaFreq = FreqMax-FreqMin; if(FreqMax FreqMin\n"); printf("Can't Start the ramp\n"); return -1; } //2- Calcul du nombre de points de la rampe int NumberPointsUp = DeltaFreq/dfUp; int NumberPointsDown = DeltaFreq/dfDown; //3- En déduire la valeur de dtUp et dtDown double dtUp = DeltaTimeUp/NumberPointsUp; double dtDown = DeltaTimeDown/NumberPointsDown; double dtmin = 24/fclk; double dtmax = dtmin*(pow(2.0,16.0)-1); //Check Up if(dtUp %f s\n",dtmin*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } //Check Down if(dtDown %f s\n",dtmin*NumberPointsDown); printf("Can't start the ramp\n"); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); printf("Can't start the ramp\n"); return -1; } //4 - Put word in register //4.1 Limit register uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence sendIOUpdate(f_dds); uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence sendIOUpdate(f_dds); //4.2 dfUP et dfDown double df_up = DeltaFreq/NumberPointsUp; double df_down = DeltaFreq/NumberPointsDown; 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); writeRegister(fd,0x06,Word_df_up>>24&0xFF,Word_df_up>>16&0xFF,Word_df_up>>8&0xFF,Word_df_up&0xFF); //df_up sendIOUpdate(f_dds); writeRegister(fd,0x07,Word_df_down>>24&0xFF,Word_df_down>>16&0xFF,Word_df_down>>8&0xFF,Word_df_down&0xFF);//df_down sendIOUpdate(f_dds); //4.3 dtUp et dtDown uint16_t Word_dt_up = 0x0000; uint16_t Word_dt_down = 0x0000; Word_dt_up = rint(dtUp*fclk/24); Word_dt_down = rint(dtDown*fclk/24); 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 sendIOUpdate(f_dds); //5 Start of the ramp writeRegister(fd,0x01,0x00,0x08,0x09,0x00); //rampe simple sendIOUpdate(f_dds); return 0; return EXIT_SUCCESS; } //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) { //calcul de N => N=DeltaF/df = DeltaT/dt //1-fmax > fmin double DeltaFreq = FreqMax-FreqMin; if(FreqMax FreqMin\n"); printf("Can't Start the ramp\n"); return -1; } //2- Calcul du nombre de points de la rampe int NumberPointsUp = DeltaFreq/dfUp; int NumberPointsDown = DeltaFreq/dfDown; //3- En déduire la valeur de dtUp et dtDown double dtUp = DeltaTimeUp/NumberPointsUp; double dtDown = DeltaTimeDown/NumberPointsDown; double dtmin = 24/fclk; double dtmax = dtmin*(pow(2.0,16.0)-1); //Check Up if(dtUp %f s\n",dtmin*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } //Check Down if(dtDown %f s\n",dtmin*NumberPointsDown); printf("Can't start the ramp\n"); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); printf("Can't start the ramp\n"); return -1; } //4 - Put word in register //4.1 Limit register uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence sendIOUpdate(f_dds); uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence sendIOUpdate(f_dds); //4.2 dfUP et dfDown double df_up = DeltaFreq/NumberPointsUp; double df_down = DeltaFreq/NumberPointsDown; 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); writeRegister(fd,0x06,Word_df_up>>24&0xFF,Word_df_up>>16&0xFF,Word_df_up>>8&0xFF,Word_df_up&0xFF); //df_up sendIOUpdate(f_dds); writeRegister(fd,0x07,Word_df_down>>24&0xFF,Word_df_down>>16&0xFF,Word_df_down>>8&0xFF,Word_df_down&0xFF);//df_down sendIOUpdate(f_dds); //4.3 dtUp et dtDown uint16_t Word_dt_up = 0x0000; uint16_t Word_dt_down = 0x0000; Word_dt_up = rint(dtUp*fclk/24); Word_dt_down = rint(dtDown*fclk/24); 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 sendIOUpdate(f_dds); //5 Start of the ramp writeRegister(fd,0x01,0x00,0x8e,0x29,0x00); //rampe triangulaire sendIOUpdate(f_dds); return 0; return EXIT_SUCCESS; } //2-rampe d'amplitude int amplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) { //calcul de N => N=DeltaF/df = DeltaT/dt //1-Amax > Amin double DeltaAmp = AMax-AMin; if(AMax AMin\n"); printf("Can't Start the ramp\n"); return -1; } //2- Calcul du nombre de points de la rampe int NumberPointsUp = DeltaAmp/dAUp; int NumberPointsDown = DeltaAmp/dADown; //3- En déduire la valeur de dtUp et dtDown double dtUp = DeltaTimeUp/NumberPointsUp; double dtDown = DeltaTimeDown/NumberPointsDown; double dtmin = 24/fclk; double dtmax = dtmin*(pow(2.0,16.0)-1); //Check Up if(dtUp %f s\n",dtmin*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } //Check Down if(dtDown %f s\n",dtmin*NumberPointsDown); printf("Can't start the ramp\n"); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); printf("Can't start the ramp\n"); return -1; } //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); } if(DeltaAmp<=enouthDOWN) { printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); } //4 - Put word in register //4.1 Limit register uint32_t WordAmin = rint(AMin*4095/100); uint32_t WordAmax= rint(AMax*4095/100); writeRegister(fd,0x04,WordAmin>>24&0xFF,WordAmin>>16&0xFF,WordAmin>>8&0xFF,WordAmin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 sendIOUpdate(f_dds); writeRegister(fd,0x05,WordAmax>>24&0xFF,WordAmax>>16&0xFF,WordAmax>>8&0xFF,WordAmax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 sendIOUpdate(f_dds); //4.2 dAUP et dADown uint32_t Word_dA_up = rint(dAUp*4095/100); uint32_t Word_dA_down = rint(dADown*4095/100); writeRegister(fd,0x06,Word_dA_up>>24&0xFF,Word_dA_up>>16&0xFF,Word_dA_up>>8&0xFF,Word_dA_up&0xFF); //dA_up sendIOUpdate(f_dds); writeRegister(fd,0x07,Word_dA_down>>24&0xFF,Word_dA_down>>16&0xFF,Word_dA_down>>8&0xFF,Word_dA_down&0xFF);//dA_down sendIOUpdate(f_dds); //4.3 dtUp et dtDown uint16_t Word_dt_up = rint(dtUp*fclk/24); uint16_t Word_dt_down = rint(dtDown*fclk/24); 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 sendIOUpdate(f_dds); //5 Start of the ramp writeRegister(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante //writeRegister(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue sendIOUpdate(f_dds); return EXIT_SUCCESS; } int continueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) { //calcul de N => N=DeltaF/df = DeltaT/dt //1-Amax > Amin double DeltaAmp = AMax-AMin; if(AMax AMin\n"); printf("Can't Start the ramp\n"); return -1; } //2- Calcul du nombre de points de la rampe int NumberPointsUp = DeltaAmp/dAUp; int NumberPointsDown = DeltaAmp/dADown; //3- En déduire la valeur de dtUp et dtDown double dtUp = DeltaTimeUp/NumberPointsUp; double dtDown = DeltaTimeDown/NumberPointsDown; double dtmin = 24/fclk; double dtmax = dtmin*(pow(2.0,16.0)-1); //Check Up if(dtUp %f s\n",dtmin*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } //Check Down if(dtDown %f s\n",dtmin*NumberPointsDown); printf("Can't start the ramp\n"); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); printf("Can't start the ramp\n"); return -1; } //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 WordAmin = rint(AMin*4095/100); uint32_t WordAmax= rint(AMax*4095/100); writeRegister(fd,0x04,WordAmin>>24&0xFF,WordAmin>>16&0xFF,WordAmin>>8&0xFF,WordAmin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 sendIOUpdate(f_dds); writeRegister(fd,0x05,WordAmax>>24&0xFF,WordAmax>>16&0xFF,WordAmax>>8&0xFF,WordAmax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 sendIOUpdate(f_dds); //4.2 dAUP et dADown uint32_t Word_dA_up = rint(dAUp*4095/100); uint32_t Word_dA_down = rint(dADown*4095/100); writeRegister(fd,0x06,Word_dA_up>>24&0xFF,Word_dA_up>>16&0xFF,Word_dA_up>>8&0xFF,Word_dA_up&0xFF); //dA_up sendIOUpdate(f_dds); writeRegister(fd,0x07,Word_dA_down>>24&0xFF,Word_dA_down>>16&0xFF,Word_dA_down>>8&0xFF,Word_dA_down&0xFF);//dA_down sendIOUpdate(f_dds); //4.3 dtUp et dtDown uint16_t Word_dt_up = rint(dtUp*fclk/24); uint16_t Word_dt_down = rint(dtDown*fclk/24); 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 sendIOUpdate(f_dds); //5 Start of the ramp //writeRegister(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante writeRegister(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue sendIOUpdate(f_dds); return EXIT_SUCCESS; } //3-rampe de ĥase int phaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown) { //calcul de N => N=Deltaphi/dphi = DeltaT/dt //1-phimax > phimin double DeltaPhi = PhiMax-PhiMin; if(PhiMax PhiMin\n"); printf("Can't Start the ramp\n"); return -1; } //2- Calcul du nombre de points de la rampe int NumberPointsUp = DeltaPhi/dphiUp; int NumberPointsDown = DeltaPhi/dphiDown; printf("NumberPointsUp = %d\n",NumberPointsUp); printf("NumberPointsDown = %d\n",NumberPointsDown); //3- En déduire la valeur de dtUp et dtDown double dtUp = DeltaTimeUp/NumberPointsUp; double dtDown = DeltaTimeDown/NumberPointsDown; double dtmin = 24/fclk; double dtmax = dtmin*(pow(2.0,16.0)-1); //Check Up if(dtUp %f s\n",dtmin*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } //Check Down if(dtDown %f s\n",dtmin*NumberPointsDown); printf("Can't start the ramp\n"); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); printf("Can't start the ramp\n"); return -1; } //4.1 Limit register uint32_t WordPhimin = rint(PhiMin*65535/360); uint32_t WordPhimax= rint(PhiMax*65535/360); printf("WordPhimin = %.32x\n",WordPhimin); printf("WordPhimax = %.32x\n",WordPhimax); writeRegister(fd,0x04,WordPhimin>>24&0xFF,WordPhimin>>16&0xFF,WordPhimin>>8&0xFF,WordPhimin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 sendIOUpdate(f_dds); writeRegister(fd,0x05,WordPhimax>>24&0xFF,WordPhimax>>16&0xFF,WordPhimax>>8&0xFF,WordPhimax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 sendIOUpdate(f_dds); //4.2 dphiUP et dphiDown 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>>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 sendIOUpdate(f_dds); //4.3 dtUp et dtDown uint16_t Word_dt_up = rint(dtUp*fclk/24); uint16_t Word_dt_down = rint(dtDown*fclk/24); 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 sendIOUpdate(f_dds); //5 Start of the ramp writeRegister(fd,0x01,0x00,0x18,0x09,0x00); //rampe simple montante sendIOUpdate(f_dds); return EXIT_SUCCESS; } int continuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown) { //calcul de N => N=Deltaphi/dphi = DeltaT/dt //1-phimax > phimin double DeltaPhi = PhiMax-PhiMin; if(PhiMax PhiMin\n"); printf("Can't Start the ramp\n"); return -1; } //2- Calcul du nombre de points de la rampe int NumberPointsUp = DeltaPhi/dphiUp; int NumberPointsDown = DeltaPhi/dphiDown; printf("NumberPointsUp = %d\n",NumberPointsUp); printf("NumberPointsDown = %d\n",NumberPointsDown); //3- En déduire la valeur de dtUp et dtDown double dtUp = DeltaTimeUp/NumberPointsUp; double dtDown = DeltaTimeDown/NumberPointsDown; double dtmin = 24/fclk; double dtmax = dtmin*(pow(2.0,16.0)-1); //Check Up if(dtUp %f s\n",dtmin*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); printf("Can't start the ramp\n"); return -1; } //Check Down if(dtDown %f s\n",dtmin*NumberPointsDown); printf("Can't start the ramp\n"); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); printf("Can't start the ramp\n"); 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); printf("WordPhimin = %.32x\n",WordPhimin); printf("WordPhimax = %.32x\n",WordPhimax); writeRegister(fd,0x04,WordPhimin>>24&0xFF,WordPhimin>>16&0xFF,WordPhimin>>8&0xFF,WordPhimin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 sendIOUpdate(f_dds); writeRegister(fd,0x05,WordPhimax>>24&0xFF,WordPhimax>>16&0xFF,WordPhimax>>8&0xFF,WordPhimax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 sendIOUpdate(f_dds); //4.2 dphiUP et dphiDown 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>>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 sendIOUpdate(f_dds); //4.3 dtUp et dtDown uint16_t Word_dt_up = rint(dtUp*fclk/24); uint16_t Word_dt_down = rint(dtDown*fclk/24); 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 sendIOUpdate(f_dds); //5 Start of the ramp writeRegister(fd,0x01,0x00,0x9E,0x29,0x00); //rampe simple montante sendIOUpdate(f_dds); return EXIT_SUCCESS; } //-------------------------FIN FONCTIONS RAMPES HARDWARES //--------------------------FONCTIONS RAMPES SOFTWARES int rampAmpFromSoft(int fd, int f_dds,double DeltaTimeUp,double AIni, double AFin) { //On va plutôt fixé dA sinon trop de contrainte : => Besoin d'allocation dynamique double dA=0.024;//en % double DeltaAmp = AIni-AFin; double AbsDeltaAmp = 0; if(DeltaAmp>=0) { AbsDeltaAmp = DeltaAmp; } else { AbsDeltaAmp = -1*DeltaAmp; } int NumberPoints = AbsDeltaAmp/dA; double dt=DeltaTimeUp/NumberPoints; printf("Taille du tableau = %d\n", NumberPoints); printf("dt = %f s\n",dt); uint16_t* ArrayWordAmp= NULL; ArrayWordAmp = malloc(NumberPoints*sizeof(uint16_t)); //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); // for(int i=0;i>8&0xFF,ArrayWordAmp[i]&0xFF,WordPhaseInitiale>>8&0xFF,WordPhaseInitiale&0xFF); sendIOUpdate(f_dds); usleep(1000000*dt); } return EXIT_SUCCESS; } int rampPhaseFromSoft(int fd, int f_dds,double DeltaTimeUp,double PhiIni, double PhiFin) { //On va plutôt fixé dphi : => Besoin d'allocation dynamique double dphi=0.06;//en ° double DeltaPhi = PhiIni-PhiFin; double AbsDeltaPhi = 0; if(DeltaPhi>=0) { AbsDeltaPhi = DeltaPhi; } else { AbsDeltaPhi = -1*DeltaPhi; } int NumberPoints = AbsDeltaPhi/dphi; double dt=DeltaTimeUp/NumberPoints; printf("Taille du tableau = %d\n", NumberPoints); printf("dt = %f s\n",dt); uint16_t* ArrayWordPhi= NULL; ArrayWordPhi = malloc(NumberPoints*sizeof(uint16_t)); //extraction de l'amplitude uint32_t ReadPhaseAmpWord = 0x00000000; readRegister(fd, 0x0c,&ReadPhaseAmpWord); printf("ReadPhaseAmpWord = %.8x \n", ReadPhaseAmpWord); uint16_t WordAmpInitiale = ReadPhaseAmpWord>>16&0xFFFF; printf("Amp = %.4x \n", WordAmpInitiale); for(int i=0;i>8&0xFF,WordAmpInitiale&0xFF,ArrayWordPhi[i]>>8&0xFF,ArrayWordPhi[i]&0xFF); sendIOUpdate(f_dds); usleep(1000000*dt); } return EXIT_SUCCESS; } //-------------------------FIN FONCTIONS RAMPES SOFTWARES int receiveParameterFromPythonServer(char * device, double f_clk, double f_out){ printf("receiveParameterFromPythonServer::device=%s\tf_clk=%e\tf_out=%e\n",device,f_clk,f_out); return 0; }