Blame view
src/ad9915.c
38.3 KB
dfa91a3bc libad9915 : add i... |
1 2 3 4 5 6 7 8 9 |
/* SPI : initialisation du dds et communication SPI */ #include"ad9915.h" #include "spi.h" #include "ddsFreq.h" #define debug //fonction reset |
41fb442f6 ad9915.c et ad991... |
10 |
void sendReset(int f_dds) |
dfa91a3bc libad9915 : add i... |
11 12 13 14 15 16 17 |
{ char reset='2'; write(f_dds,&reset,sizeof(reset)); //reset sleep(0.1); } //fonction ioupdate |
41fb442f6 ad9915.c et ad991... |
18 |
void sendIOUpdate(int f_dds) |
dfa91a3bc libad9915 : add i... |
19 20 21 22 23 24 25 |
{ char update='1'; write(f_dds,&update,sizeof(update)); //reset sleep(0.1); } //fonction write register |
41fb442f6 ad9915.c et ad991... |
26 |
void writeRegister (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0) |
dfa91a3bc libad9915 : add i... |
27 28 29 30 31 32 33 34 35 36 37 38 |
{ 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); } |
09ecc607d mise a jour avec ... |
39 40 |
//fonction read register |
41fb442f6 ad9915.c et ad991... |
41 |
void readRegister (int fd,unsigned char addr, uint32_t *readword) |
09ecc607d mise a jour avec ... |
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
{ 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 ",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 |
41fb442f6 ad9915.c et ad991... |
58 |
void readRegisterIni (int fd, unsigned char addr) |
09ecc607d mise a jour avec ... |
59 60 61 62 63 64 65 66 |
{ 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 ",tx[0],rx[0],rx[1],rx[2],rx[3]); |
41fb442f6 ad9915.c et ad991... |
67 |
// sendIOUpdate (f_dds); //Send the update to set the control registers |
09ecc607d mise a jour avec ... |
68 69 |
} |
dfa91a3bc libad9915 : add i... |
70 |
//initialisation du dds |
41fb442f6 ad9915.c et ad991... |
71 |
void initializeDDS (int fd, int f_dds) |
dfa91a3bc libad9915 : add i... |
72 |
{ |
41fb442f6 ad9915.c et ad991... |
73 74 75 76 77 78 79 80 81 82 83 |
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); |
dfa91a3bc libad9915 : add i... |
84 85 86 |
} //calibration du dac |
41fb442f6 ad9915.c et ad991... |
87 |
void calibrateDAC (int fd, int f_dds) |
dfa91a3bc libad9915 : add i... |
88 |
{ |
41fb442f6 ad9915.c et ad991... |
89 90 91 92 |
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); |
dfa91a3bc libad9915 : add i... |
93 94 |
} |
41fb442f6 ad9915.c et ad991... |
95 |
void modulusSetup(int fd, int f_dds) |
dfa91a3bc libad9915 : add i... |
96 |
{ |
41fb442f6 ad9915.c et ad991... |
97 98 99 100 101 |
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); |
dfa91a3bc libad9915 : add i... |
102 103 |
} |
41fb442f6 ad9915.c et ad991... |
104 |
void basicSetup(int fd, int f_dds,uint16_t ampWord, uint16_t phaseWord) |
dfa91a3bc libad9915 : add i... |
105 |
{ |
41fb442f6 ad9915.c et ad991... |
106 107 108 109 110 111 112 113 114 115 116 117 118 |
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, 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) sendIOUpdate (f_dds); |
dfa91a3bc libad9915 : add i... |
119 120 121 122 123 124 125 126 127 |
} 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; |
41fb442f6 ad9915.c et ad991... |
128 129 130 131 132 133 134 135 136 137 138 139 |
//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); |
dfa91a3bc libad9915 : add i... |
140 141 142 143 |
} void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord) { |
41fb442f6 ad9915.c et ad991... |
144 145 |
writeRegister(fd,0x0c, phaseAmpWord>>24&0xFF, phaseAmpWord>>16&0xFF,phaseAmpWord>>8&0xFF,phaseAmpWord&0xFF); // amp (12b) ph(16) sendIOUpdate(f_dds); |
dfa91a3bc libad9915 : add i... |
146 147 |
} |
09ecc607d mise a jour avec ... |
148 149 150 151 152 |
/* void getAmpPhaseWord(int fd) { // unsigned char rx[5]={0}; unsigned char* pt; |
41fb442f6 ad9915.c et ad991... |
153 |
readRegister(fd,0x0c,rx); // amp (12b) ph(16) |
09ecc607d mise a jour avec ... |
154 155 156 157 158 159 160 161 162 163 164 165 166 |
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 ",sizeof(unsigned int)); } |
dfa91a3bc libad9915 : add i... |
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
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 ",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 ",device,gpio_update,f_clk,f_out,ampWord,phaseWord); int fd=configureSpi(device); //ex #define FILENAME2 "/dev/spidev0.0" printf("fd(funct)=%d ",fd); setMode(fd,SPI_MODE_0); if (fd <= 0){ printf("ERREUR : ouverture périphérique SPI %s ",device); return EXIT_FAILURE; } int f_dds=open(gpio_update,O_RDWR); //ex #define UPDATE2 "/sys/dds/gpio24/updateOn" printf("f_dds(funct)=%d ",f_dds); if (f_dds <= 0){ printf("ERREUR : ouverture ");printf(gpio_update);printf(" "); printf("Chargez le module ddsIOupdateX "); 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; } |
41fb442f6 ad9915.c et ad991... |
220 |
void sendCtrlUp(int fp) |
09ecc607d mise a jour avec ... |
221 222 223 224 225 226 |
{ char DRCTLOn='0';//pente positive write(fp,&DRCTLOn,sizeof(DRCTLOn)); // sleep(0.1); } |
41fb442f6 ad9915.c et ad991... |
227 |
void sendCtrlDown(int fp) |
09ecc607d mise a jour avec ... |
228 229 230 231 232 233 |
{ char DRCTLOn='2';//pente negative write(fp,&DRCTLOn,sizeof(DRCTLOn)); //reset sleep(0.1); } |
41fb442f6 ad9915.c et ad991... |
234 |
void sendHold(int fp) |
09ecc607d mise a jour avec ... |
235 236 237 238 239 240 |
{ char DRHOLDOn ='1';//rampe bloquée write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset sleep(0.1); } |
41fb442f6 ad9915.c et ad991... |
241 |
void sendUnhold(int fp) |
09ecc607d mise a jour avec ... |
242 243 244 245 246 247 248 249 250 251 252 253 |
{ char DRHOLDOn ='3';//rampe debloquée write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset sleep(0.1); } int testRampFreq(int fd, int f_dds, int fp) { //3-Rampe de pente positive + debloquage |
41fb442f6 ad9915.c et ad991... |
254 255 |
sendCtrlDown(fp);//rampe up sendUnhold(fp); |
09ecc607d mise a jour avec ... |
256 |
|
41fb442f6 ad9915.c et ad991... |
257 |
sendReset(f_dds); |
09ecc607d mise a jour avec ... |
258 259 260 |
//Initialize_DDS (fd, f_dds); //0- paramètre de bases |
41fb442f6 ad9915.c et ad991... |
261 262 263 |
writeRegister(fd,0x00,0x00,0x01,0x01,0x0a);//OSKenable+Read&write sendIOUpdate(f_dds); readRegisterIni(fd,0x00); |
09ecc607d mise a jour avec ... |
264 |
|
41fb442f6 ad9915.c et ad991... |
265 266 267 |
writeRegister(fd,0x01,0x00, 0x00, 0x09, 0x00); // enable amp ramp sendIOUpdate(f_dds); readRegisterIni(fd,0x00); |
09ecc607d mise a jour avec ... |
268 269 270 271 272 273 274 275 276 277 278 279 |
//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); |
41fb442f6 ad9915.c et ad991... |
280 281 282 283 |
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); |
09ecc607d mise a jour avec ... |
284 285 286 287 288 |
printf("Les mots de frequences, d'amplitudes et de phases sont envoyes "); printf("Lecture registre de frequence: 0x0b "); |
41fb442f6 ad9915.c et ad991... |
289 |
readRegisterIni(fd,0x0b); |
09ecc607d mise a jour avec ... |
290 291 |
printf("Lecture registre de amp et phase: 0x0c "); |
41fb442f6 ad9915.c et ad991... |
292 |
readRegisterIni(fd,0x0c); |
09ecc607d mise a jour avec ... |
293 294 295 296 297 298 299 300 301 302 303 304 |
Calibrate_DAC (fd,f_dds); printf(" ----------------------- "); /* //2- Taille des dt |
41fb442f6 ad9915.c et ad991... |
305 306 |
writeRegister(fd,0x08,0xFF,0xFF,0xFF,0xFF); //+dt max, -dt max (+dt = -dt) sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
307 308 309 310 311 |
printf("Les mots de dt sont envoyes "); printf("Lecture dans le registre 0x08 : taille dt "); |
41fb442f6 ad9915.c et ad991... |
312 |
readRegisterIni (fd,0x08); |
09ecc607d mise a jour avec ... |
313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
printf(" ----------------------- "); //3- STEP SIZE :dphi // en theorie dphi =2.25e-28 degrees |
41fb442f6 ad9915.c et ad991... |
327 328 |
writeRegister(fd,0x06,0x00,0x00,0x00,0x01); sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
329 |
|
41fb442f6 ad9915.c et ad991... |
330 331 |
writeRegister(fd,0x07,0x00,0x00,0x00,0x01); sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
332 333 334 335 336 337 338 339 340 341 |
//printf(" ----------------------- "); printf("Les mots de dphi sont envoyes "); printf("Lecture dans les registres 0x06 et 0x07 : taille dt "); |
41fb442f6 ad9915.c et ad991... |
342 343 |
readRegisterIni (fd,0x06); readRegisterIni (fd,0x07); |
09ecc607d mise a jour avec ... |
344 345 346 347 348 349 350 351 |
printf(" ----------------------- "); //4- Ecrire les extremums de la rampe |
41fb442f6 ad9915.c et ad991... |
352 353 354 355 |
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); |
09ecc607d mise a jour avec ... |
356 357 358 359 360 |
printf("Les mots des frontieres sont envoyes "); printf("Lecture dans les registres 0x04 et 0x05 : taille dt "); |
41fb442f6 ad9915.c et ad991... |
361 362 |
readRegisterIni (fd,0x04); readRegisterIni (fd,0x05); |
09ecc607d mise a jour avec ... |
363 364 365 366 367 368 369 |
//3-Rampe de pente positive ou négative // Send_CTRL_UP(fp);//rampe up //4-ecriture dans le registre 0x01 |
41fb442f6 ad9915.c et ad991... |
370 371 |
writeRegister(fd,0x01,0x00, 0xa8, 0x09, 0x00); // enable amp ramp sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
372 373 374 |
printf("Lecture dans le registre 0x01 : "); |
41fb442f6 ad9915.c et ad991... |
375 |
readRegisterIni (fd,0x01); |
09ecc607d mise a jour avec ... |
376 377 378 379 |
// printf("Les mots de dt sont envoyes "); printf("Lecture dans le registre 0x08 : taille dt "); |
41fb442f6 ad9915.c et ad991... |
380 |
readRegisterIni (fd,0x08); |
09ecc607d mise a jour avec ... |
381 382 383 384 385 386 387 388 |
*/ return EXIT_SUCCESS; } //---------------rajout 8/1 |
41fb442f6 ad9915.c et ad991... |
389 |
int putAmpWord(int fd, int f_dds, double amplitude) |
09ecc607d mise a jour avec ... |
390 391 392 393 394 395 396 |
{ uint16_t PhaseWord = 0x0000; uint16_t AmpWord = 0x0000; uint32_t ReadPhaseAmpWord=0x00000000; AmpWord = rint(amplitude*(pow(2.0,12.0)-1)/100); |
41fb442f6 ad9915.c et ad991... |
397 |
readRegister(fd,0x0c,&ReadPhaseAmpWord); |
09ecc607d mise a jour avec ... |
398 399 400 |
PhaseWord = ReadPhaseAmpWord&0xFFFF; |
41fb442f6 ad9915.c et ad991... |
401 402 |
writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
403 404 405 406 407 |
return 0; } |
41fb442f6 ad9915.c et ad991... |
408 |
int putPhaseWord(int fd, int f_dds, double phase) |
09ecc607d mise a jour avec ... |
409 410 411 412 413 414 415 |
{ uint16_t PhaseWord = 0x0000; uint16_t AmpWord = 0x0000; uint32_t ReadPhaseAmpWord=0x00000000; PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360); |
41fb442f6 ad9915.c et ad991... |
416 |
readRegister(fd,0x0c,&ReadPhaseAmpWord); |
09ecc607d mise a jour avec ... |
417 418 419 |
AmpWord = ReadPhaseAmpWord>>16&0xFFFF; |
41fb442f6 ad9915.c et ad991... |
420 421 |
writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
422 423 424 425 |
return 0; } |
41fb442f6 ad9915.c et ad991... |
426 |
int putFrequencyWord(int fd, int f_dds, double fclk,double fout)//Attention uniquement valable pour fclk = 1 GHz |
09ecc607d mise a jour avec ... |
427 428 429 |
{ uint32_t FTWR = 0x00000000; |
41fb442f6 ad9915.c et ad991... |
430 431 432 |
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); |
09ecc607d mise a jour avec ... |
433 434 435 436 437 |
return 0; } |
41fb442f6 ad9915.c et ad991... |
438 |
int putFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase)//n'existe pas dans le mode profile enable |
09ecc607d mise a jour avec ... |
439 440 441 442 443 444 |
{ uint32_t FTWR = 0x00000000; FTWR = rint((fout/fclk)*pow(2.0,32.0)); |
41fb442f6 ad9915.c et ad991... |
445 |
writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence |
09ecc607d mise a jour avec ... |
446 |
|
41fb442f6 ad9915.c et ad991... |
447 |
sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
448 |
|
41fb442f6 ad9915.c et ad991... |
449 450 |
// writeRegister(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle // sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
451 |
|
41fb442f6 ad9915.c et ad991... |
452 453 |
putPhaseWord(fd,f_dds,phase); putAmpWord(fd,f_dds,amp); |
09ecc607d mise a jour avec ... |
454 455 456 457 458 |
return 0; } |
41fb442f6 ad9915.c et ad991... |
459 |
int initialisationProfileMode (int fd,int f_dds) |
09ecc607d mise a jour avec ... |
460 461 |
{ |
41fb442f6 ad9915.c et ad991... |
462 463 464 465 466 467 468 469 470 471 472 |
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); |
09ecc607d mise a jour avec ... |
473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
return 0; } //------------------- FIN RAJOUT 8/1 //-------------------------FONCTIONS RAMPES HARDWARE //1-rampe de frequence //rampe simple de fréquence |
41fb442f6 ad9915.c et ad991... |
487 |
int frequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown) |
09ecc607d mise a jour avec ... |
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
{ //calcul de N => N=DeltaF/df = DeltaT/dt //1-fmax > fmin double DeltaFreq = FreqMax-FreqMin; if(FreqMax<FreqMin) { printf("FreqMax should be > FreqMin "); printf("Can't Start the ramp "); 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<dtmin) { printf("During of ramp UP should be > %f s ",dtmin*NumberPointsUp); printf("Can't start the ramp "); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f ",dtmax*NumberPointsUp); printf("Can't start the ramp "); return -1; } //Check Down if(dtDown<dtmin) { printf("During of ramp DOWN should be > %f s ",dtmin*NumberPointsDown); printf("Can't start the ramp "); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f ",dtmax*NumberPointsDown); printf("Can't start the ramp "); return -1; } //4 - Put word in register //4.1 Limit register uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); |
41fb442f6 ad9915.c et ad991... |
557 558 |
writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
559 560 |
uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); |
41fb442f6 ad9915.c et ad991... |
561 562 |
writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
563 564 565 566 567 568 569 570 571 |
//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); |
41fb442f6 ad9915.c et ad991... |
572 573 574 575 |
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); |
09ecc607d mise a jour avec ... |
576 577 578 579 580 581 582 583 584 585 |
//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); |
41fb442f6 ad9915.c et ad991... |
586 587 |
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); |
09ecc607d mise a jour avec ... |
588 589 590 |
//5 Start of the ramp |
41fb442f6 ad9915.c et ad991... |
591 592 |
writeRegister(fd,0x01,0x00,0x08,0x09,0x00); //rampe simple sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
593 594 595 596 597 598 599 600 601 602 |
return 0; return EXIT_SUCCESS; } //rampe continue de fréquence |
41fb442f6 ad9915.c et ad991... |
603 |
int continueFrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown) |
09ecc607d mise a jour avec ... |
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
{ //calcul de N => N=DeltaF/df = DeltaT/dt //1-fmax > fmin double DeltaFreq = FreqMax-FreqMin; if(FreqMax<FreqMin) { printf("FreqMax should be > FreqMin "); printf("Can't Start the ramp "); 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<dtmin) { printf("During of ramp UP should be > %f s ",dtmin*NumberPointsUp); printf("Can't start the ramp "); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f ",dtmax*NumberPointsUp); printf("Can't start the ramp "); return -1; } //Check Down if(dtDown<dtmin) { printf("During of ramp DOWN should be > %f s ",dtmin*NumberPointsDown); printf("Can't start the ramp "); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f ",dtmax*NumberPointsDown); printf("Can't start the ramp "); return -1; } //4 - Put word in register //4.1 Limit register uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); |
41fb442f6 ad9915.c et ad991... |
673 674 |
writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
675 676 |
uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); |
41fb442f6 ad9915.c et ad991... |
677 678 |
writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
679 680 681 682 683 684 685 686 687 |
//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); |
41fb442f6 ad9915.c et ad991... |
688 689 690 691 |
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); |
09ecc607d mise a jour avec ... |
692 693 694 695 696 697 698 699 700 701 |
//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); |
41fb442f6 ad9915.c et ad991... |
702 703 |
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); |
09ecc607d mise a jour avec ... |
704 705 706 |
//5 Start of the ramp |
41fb442f6 ad9915.c et ad991... |
707 708 |
writeRegister(fd,0x01,0x00,0x8e,0x29,0x00); //rampe triangulaire sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
709 710 711 712 713 714 715 716 717 718 |
return 0; return EXIT_SUCCESS; } //2-rampe d'amplitude |
41fb442f6 ad9915.c et ad991... |
719 |
int amplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) |
09ecc607d mise a jour avec ... |
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 |
{ //calcul de N => N=DeltaF/df = DeltaT/dt //1-Amax > Amin double DeltaAmp = AMax-AMin; if(AMax<AMin) { printf("AMax should be > AMin "); printf("Can't Start the ramp "); 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<dtmin) { printf("During of ramp UP should be > %f s ",dtmin*NumberPointsUp); printf("Can't start the ramp "); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f ",dtmax*NumberPointsUp); printf("Can't start the ramp "); return -1; } //Check Down if(dtDown<dtmin) { printf("During of ramp DOWN should be > %f s ",dtmin*NumberPointsDown); printf("Can't start the ramp "); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f ",dtmax*NumberPointsDown); printf("Can't start the ramp "); 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 , decrease Number Points for positive slope",borneUP); //return -1; } if(DeltaAmp<=enouthDOWN) { printf("The amplitude difference should be > %d , 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); |
41fb442f6 ad9915.c et ad991... |
817 818 819 820 |
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); |
09ecc607d mise a jour avec ... |
821 822 823 824 825 826 827 |
//4.2 dAUP et dADown uint32_t Word_dA_up = rint(dAUp*4095/100); uint32_t Word_dA_down = rint(dADown*4095/100); |
41fb442f6 ad9915.c et ad991... |
828 829 830 831 |
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); |
09ecc607d mise a jour avec ... |
832 833 834 835 836 837 838 |
//4.3 dtUp et dtDown uint16_t Word_dt_up = rint(dtUp*fclk/24); uint16_t Word_dt_down = rint(dtDown*fclk/24); |
41fb442f6 ad9915.c et ad991... |
839 840 |
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); |
09ecc607d mise a jour avec ... |
841 842 843 |
//5 Start of the ramp |
41fb442f6 ad9915.c et ad991... |
844 845 846 |
writeRegister(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante //writeRegister(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
847 848 849 850 |
return EXIT_SUCCESS; } |
41fb442f6 ad9915.c et ad991... |
851 |
int continueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) |
09ecc607d mise a jour avec ... |
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 |
{ //calcul de N => N=DeltaF/df = DeltaT/dt //1-Amax > Amin double DeltaAmp = AMax-AMin; if(AMax<AMin) { printf("AMax should be > AMin "); printf("Can't Start the ramp "); 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<dtmin) { printf("During of ramp UP should be > %f s ",dtmin*NumberPointsUp); printf("Can't start the ramp "); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f ",dtmax*NumberPointsUp); printf("Can't start the ramp "); return -1; } //Check Down if(dtDown<dtmin) { printf("During of ramp DOWN should be > %f s ",dtmin*NumberPointsDown); printf("Can't start the ramp "); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f ",dtmax*NumberPointsDown); printf("Can't start the ramp "); 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 , decrease Number Points for positive slope",borneUP); //return -1; } if(DeltaAmp<=enouthDOWN) { printf("The amplitude difference should be > %d , 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); |
41fb442f6 ad9915.c et ad991... |
949 950 951 952 |
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); |
09ecc607d mise a jour avec ... |
953 954 955 956 957 958 959 |
//4.2 dAUP et dADown uint32_t Word_dA_up = rint(dAUp*4095/100); uint32_t Word_dA_down = rint(dADown*4095/100); |
41fb442f6 ad9915.c et ad991... |
960 961 962 963 |
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); |
09ecc607d mise a jour avec ... |
964 965 966 967 968 969 970 |
//4.3 dtUp et dtDown uint16_t Word_dt_up = rint(dtUp*fclk/24); uint16_t Word_dt_down = rint(dtDown*fclk/24); |
41fb442f6 ad9915.c et ad991... |
971 972 |
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); |
09ecc607d mise a jour avec ... |
973 974 975 |
//5 Start of the ramp |
41fb442f6 ad9915.c et ad991... |
976 977 978 |
//writeRegister(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante writeRegister(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
979 980 981 982 983 984 985 |
return EXIT_SUCCESS; } //3-rampe de ĥase |
41fb442f6 ad9915.c et ad991... |
986 |
int phaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown) |
09ecc607d mise a jour avec ... |
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 |
{ //calcul de N => N=Deltaphi/dphi = DeltaT/dt //1-phimax > phimin double DeltaPhi = PhiMax-PhiMin; if(PhiMax<PhiMin) { printf("PhiMax should be > PhiMin "); printf("Can't Start the ramp "); return -1; } //2- Calcul du nombre de points de la rampe int NumberPointsUp = DeltaPhi/dphiUp; int NumberPointsDown = DeltaPhi/dphiDown; printf("NumberPointsUp = %d ",NumberPointsUp); printf("NumberPointsDown = %d ",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<dtmin) { printf("During of ramp UP should be > %f s ",dtmin*NumberPointsUp); printf("Can't start the ramp "); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f ",dtmax*NumberPointsUp); printf("Can't start the ramp "); return -1; } //Check Down if(dtDown<dtmin) { printf("During of ramp DOWN should be > %f s ",dtmin*NumberPointsDown); printf("Can't start the ramp "); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f ",dtmax*NumberPointsDown); printf("Can't start the ramp "); 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 , decrease Number Points for positive slope",borneUP); //return -1; } if(DeltaAmp<=enouthDOWN) { printf("The amplitude difference should be > %d , 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); printf("WordPhimin = %.32x ",WordPhimin); printf("WordPhimax = %.32x ",WordPhimax); |
41fb442f6 ad9915.c et ad991... |
1098 1099 1100 1101 |
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); |
09ecc607d mise a jour avec ... |
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 |
//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 ",Word_dphi_up); printf("Word_dphi_down = %.32x ",Word_dphi_down); /* |
41fb442f6 ad9915.c et ad991... |
1117 1118 1119 1120 |
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); |
09ecc607d mise a jour avec ... |
1121 1122 1123 1124 |
*/ |
41fb442f6 ad9915.c et ad991... |
1125 1126 1127 1128 |
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); |
09ecc607d mise a jour avec ... |
1129 1130 1131 1132 1133 1134 1135 |
//4.3 dtUp et dtDown uint16_t Word_dt_up = rint(dtUp*fclk/24); uint16_t Word_dt_down = rint(dtDown*fclk/24); |
41fb442f6 ad9915.c et ad991... |
1136 1137 |
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); |
09ecc607d mise a jour avec ... |
1138 1139 1140 |
//5 Start of the ramp |
41fb442f6 ad9915.c et ad991... |
1141 1142 |
writeRegister(fd,0x01,0x00,0x18,0x09,0x00); //rampe simple montante sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
1143 1144 1145 1146 |
return EXIT_SUCCESS; } |
41fb442f6 ad9915.c et ad991... |
1147 |
int continuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown) |
09ecc607d mise a jour avec ... |
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 |
{ //calcul de N => N=Deltaphi/dphi = DeltaT/dt //1-phimax > phimin double DeltaPhi = PhiMax-PhiMin; if(PhiMax<PhiMin) { printf("PhiMax should be > PhiMin "); printf("Can't Start the ramp "); return -1; } //2- Calcul du nombre de points de la rampe int NumberPointsUp = DeltaPhi/dphiUp; int NumberPointsDown = DeltaPhi/dphiDown; printf("NumberPointsUp = %d ",NumberPointsUp); printf("NumberPointsDown = %d ",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<dtmin) { printf("During of ramp UP should be > %f s ",dtmin*NumberPointsUp); printf("Can't start the ramp "); return -1; } if(dtUp>dtmax) { printf("During of ramp UP should be < %f ",dtmax*NumberPointsUp); printf("Can't start the ramp "); return -1; } //Check Down if(dtDown<dtmin) { printf("During of ramp DOWN should be > %f s ",dtmin*NumberPointsDown); printf("Can't start the ramp "); return -1; } if(dtDown>dtmax) { printf("During of ramp DOWN should be < %f ",dtmax*NumberPointsDown); printf("Can't start the ramp "); 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 , decrease Number Points for positive slope",borneUP); //return -1; } if(DeltaAmp<=enouthDOWN) { printf("The amplitude difference should be > %d , 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); printf("WordPhimin = %.32x ",WordPhimin); printf("WordPhimax = %.32x ",WordPhimax); |
41fb442f6 ad9915.c et ad991... |
1259 1260 1261 1262 |
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); |
09ecc607d mise a jour avec ... |
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 |
//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 ",Word_dphi_up); printf("Word_dphi_down = %.32x ",Word_dphi_down); /* |
41fb442f6 ad9915.c et ad991... |
1278 1279 1280 1281 |
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); |
09ecc607d mise a jour avec ... |
1282 1283 1284 1285 |
*/ |
41fb442f6 ad9915.c et ad991... |
1286 1287 1288 1289 |
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); |
09ecc607d mise a jour avec ... |
1290 1291 1292 1293 1294 1295 1296 |
//4.3 dtUp et dtDown uint16_t Word_dt_up = rint(dtUp*fclk/24); uint16_t Word_dt_down = rint(dtDown*fclk/24); |
41fb442f6 ad9915.c et ad991... |
1297 1298 |
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); |
09ecc607d mise a jour avec ... |
1299 1300 1301 |
//5 Start of the ramp |
41fb442f6 ad9915.c et ad991... |
1302 1303 |
writeRegister(fd,0x01,0x00,0x9E,0x29,0x00); //rampe simple montante sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
1304 1305 1306 1307 1308 1309 1310 1311 1312 |
return EXIT_SUCCESS; } //-------------------------FIN FONCTIONS RAMPES HARDWARES //--------------------------FONCTIONS RAMPES SOFTWARES |
41fb442f6 ad9915.c et ad991... |
1313 |
int rampAmpFromSoft(int fd, int f_dds,double DeltaTimeUp,double AIni, double AFin) |
09ecc607d mise a jour avec ... |
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 |
{ //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 ", NumberPoints); printf("dt = %f s ",dt); uint16_t* ArrayWordAmp= NULL; ArrayWordAmp = malloc(NumberPoints*sizeof(uint16_t)); //extraction de la phase initiale et de l'amplitude uint32_t ReadPhaseAmpWord = 0x00000000; |
41fb442f6 ad9915.c et ad991... |
1345 |
readRegister(fd, 0x0c,&ReadPhaseAmpWord); |
09ecc607d mise a jour avec ... |
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 |
printf("ReadPhaseAmpWord = %.8x ", ReadPhaseAmpWord); uint16_t WordPhaseInitiale = ReadPhaseAmpWord&0xFFFF; printf("Phase = %.4x ", WordPhaseInitiale); // for(int i=0;i<NumberPoints;i++) { ArrayWordAmp[i]=rint((AIni+i*dA)*4096/100); // printf("ArrayWordAmp[%d] = %.16x ", i, ArrayWordAmp[i]); } free(ArrayWordAmp); printf("Array calculated "); printf("Start of the ramp "); for(int i=0;i<NumberPoints;i++) { |
41fb442f6 ad9915.c et ad991... |
1370 1371 |
writeRegister(fd,0x0c,ArrayWordAmp[i]>>8&0xFF,ArrayWordAmp[i]&0xFF,WordPhaseInitiale>>8&0xFF,WordPhaseInitiale&0xFF); sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 |
usleep(1000000*dt); } /* uint16_t PhaseWord = 0x0000; uint16_t AmpWord = 0x0000; uint32_t ReadPhaseAmpWord=0x00000000; AmpWord = rint(amplitude*(pow(2.0,12.0)-1)/100); |
41fb442f6 ad9915.c et ad991... |
1384 |
readRegister(fd,0x0c,&ReadPhaseAmpWord); |
09ecc607d mise a jour avec ... |
1385 1386 1387 |
PhaseWord = ReadPhaseAmpWord&0xFFFF; |
41fb442f6 ad9915.c et ad991... |
1388 |
writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); |
09ecc607d mise a jour avec ... |
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 |
*/ /* //pas de durée dtUp et dtDown fixée au minimum à 1 ms if(DeltaTimeUp < 4.095) { printf("Use hardware fonctions for the ramp "); } // double DeltaAmp = AMax-AMin; double dA = DeltaAmp/TAILLETAB; printf("dA=%f ",dA); if(dA<0.024) { printf("Amplitude step should be > 0.024 pourcent "); printf("Impossible to start a ramp of amplitude "); return -1; } //extraction de la phase initiale et de l'amplitude uint32_t ReadPhaseAmpWord = 0x00000000; |
41fb442f6 ad9915.c et ad991... |
1423 |
readRegister(fd, 0x0c,&ReadPhaseAmpWord); |
09ecc607d mise a jour avec ... |
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 |
printf("ReadPhaseAmpWord = %.8x ", ReadPhaseAmpWord); uint16_t WordPhaseInitiale = ReadPhaseAmpWord&0xFFFF; printf("Phase = %.4x ", WordPhaseInitiale); uint16_t WordAmpInitiale = ReadPhaseAmpWord>>16&0xFFFF; printf("Amp = %.4x ", WordAmpInitiale); uint16_t Word_dA = rint(dA*4095/100); uint32_t ArrayWordAmp[TAILLETAB]; for(int i=0;i<TAILLETAB;i++) { ArrayWordAmp[i]=WordAmpInitiale+i*Word_dA; // printf("ArrayWordAmp[%d] = %.16x ", i, ArrayWordAmp[i]); } */ return EXIT_SUCCESS; } |
41fb442f6 ad9915.c et ad991... |
1451 |
int rampPhaseFromSoft(int fd, int f_dds,double DeltaTimeUp,double PhiIni, double PhiFin) |
09ecc607d mise a jour avec ... |
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 |
{ //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 ", NumberPoints); printf("dt = %f s ",dt); uint16_t* ArrayWordPhi= NULL; ArrayWordPhi = malloc(NumberPoints*sizeof(uint16_t)); //extraction de l'amplitude uint32_t ReadPhaseAmpWord = 0x00000000; |
41fb442f6 ad9915.c et ad991... |
1483 |
readRegister(fd, 0x0c,&ReadPhaseAmpWord); |
09ecc607d mise a jour avec ... |
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 |
printf("ReadPhaseAmpWord = %.8x ", ReadPhaseAmpWord); uint16_t WordAmpInitiale = ReadPhaseAmpWord>>16&0xFFFF; printf("Amp = %.4x ", WordAmpInitiale); for(int i=0;i<NumberPoints;i++) { ArrayWordPhi[i]=rint((PhiIni+i*dphi)*65536/360); } free(ArrayWordPhi); printf("Array calculated "); printf("Start of the ramp "); for(int i=0;i<NumberPoints;i++) { |
41fb442f6 ad9915.c et ad991... |
1505 1506 |
writeRegister(fd,0x0c,WordAmpInitiale>>8&0xFF,WordAmpInitiale&0xFF,ArrayWordPhi[i]>>8&0xFF,ArrayWordPhi[i]&0xFF); sendIOUpdate(f_dds); |
09ecc607d mise a jour avec ... |
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 |
usleep(1000000*dt); } return EXIT_SUCCESS; } //-------------------------FIN FONCTIONS RAMPES SOFTWARES |
dfa91a3bc libad9915 : add i... |
1521 1522 1523 1524 1525 1526 |
int receiveParameterFromPythonServer(char * device, double f_clk, double f_out){ printf("receiveParameterFromPythonServer::device=%s\tf_clk=%e\tf_out=%e ",device,f_clk,f_out); return 0; } |