Commit 09ecc607dab6561abeb414705310f22a061517de
1 parent
dfa91a3bc3
Exists in
master
mise a jour avec la lib dans paulo bachir/lib
Showing 3 changed files with 1268 additions and 3 deletions Side-by-side Diff
include/ad9915.h
... | ... | @@ -25,8 +25,10 @@ |
25 | 25 | //static const char CFR1Start[] ={0x00, 0x01, 0x01, 0x08}; //with osk enable |
26 | 26 | static const char CFR2Start[] ={0x00, 0x80, 0x09, 0x00}; //0x80 enable prof mode |
27 | 27 | static const char CFR3Start[] = {0x00, 0x00, 0x19, 0x1C}; |
28 | -static const char CFR4Start[] = {0x00, 0x05, 0x21, 0x20}; | |
28 | +static const char CFR4Start[] = {0x00, 0x05, 0x21, 0x20}; | |
29 | +//static const char CFR4Start[] = {0x20, 0x21, 0x05, 0x00}; | |
29 | 30 | |
31 | + | |
30 | 32 | static const char USR0Address = 0x1B; |
31 | 33 | static const char FTW0Address = 0x0b; //profile 0 ftw |
32 | 34 | static const char PA0Address = 0x0c; //profile 0 |
33 | 35 | |
34 | 36 | |
... | ... | @@ -37,14 +39,57 @@ |
37 | 39 | void Send_Reset(int f_dds); |
38 | 40 | void Send_IO_Update (int f_dds); //Send the update to set the control registers |
39 | 41 | void write_register (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0); |
42 | +void read_register (int fd, unsigned char addr, uint32_t *readword); | |
43 | +void read_register_ini (int fd,unsigned char addr); | |
40 | 44 | void Initialize_DDS (int fd, int f_dds); |
41 | 45 | void Calibrate_DAC(int fd, int f_dds); |
42 | 46 | void basic_setup(int fd, int f_dds, uint16_t ampWord, uint16_t phaseWord); |
43 | 47 | void modulus_setup(int fd, int f_dds); |
44 | 48 | void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B); |
45 | 49 | void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord); |
50 | +void checkSize(void); | |
46 | 51 | int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord); |
47 | 52 | int receiveParameterFromPythonServer(char * device, double f_clk, double f_out); |
48 | 53 | int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord); |
54 | + | |
55 | +//------------ DRCTL | |
56 | + | |
57 | +void Send_CTRL_UP(int fp); | |
58 | +void Send_CTRL_DOWN(int fp); | |
59 | +void Send_HOLD(int fp); | |
60 | +void Send_UNHOLD(int fp); | |
61 | +int testRampFreq(int fd, int f_dds, int fp); | |
62 | + | |
63 | +//-------Profile register mode | |
64 | + | |
65 | +int InitialisationProfile (int fd,int f_dds); | |
66 | +int PutFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase); | |
67 | + | |
68 | + | |
69 | +int PutFrequencyWord(int fd, int f_dds, double freq);//Attention uniquement valable pour fclk = 1 GHz | |
70 | +int PutPhaseWord(int fd, int f_dds, double phase); | |
71 | +int PutAmpWord(int fd, int f_dds, double amplitude); | |
72 | + | |
73 | +//fonctions rampes hardwres | |
74 | + | |
75 | +int FrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown); | |
76 | +int ContinueFrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown); | |
77 | +int AmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown); | |
78 | +int ContinueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown); | |
79 | +int PhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown); | |
80 | +int ContinuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown); | |
81 | + | |
82 | +//fin fonctions rampes hardwares | |
83 | + | |
84 | +// fonctions rampes softwares | |
85 | + | |
86 | +int RampAmpFromSoft(int fd, int f_dds,double DeltaTimeUp,double AIni, double AFin); | |
87 | + | |
88 | +int RampPhaseFromSoft(int fd, int f_dds,double DeltaTimeUp,double PhiIni, double PhiFin); | |
89 | + | |
90 | +// fin fonctoins rampes softwares | |
91 | + | |
92 | + | |
93 | + | |
49 | 94 |
src/ad9915.c
Diff suppressed. Click to show
... | ... | @@ -36,6 +36,35 @@ |
36 | 36 | spi_put_multiple(fd,tx,5,NULL,0); |
37 | 37 | } |
38 | 38 | |
39 | +//fonction read register | |
40 | + | |
41 | +void read_register (int fd,unsigned char addr, uint32_t *readword) | |
42 | +{ | |
43 | + unsigned char tx[1] = {0}; | |
44 | + unsigned char rx[4] = {0}; | |
45 | + addr = addr|0x80;//instruction byte for the read : 1000 0000 | byte_adress | |
46 | + tx[0]=addr; | |
47 | + spi_put_multiple(fd,tx,1,rx,4); | |
48 | + //printf("TX:%x RX:%x %x %x %x\n",tx[0],rx[0],rx[1],rx[2],rx[3]); | |
49 | + *readword = 0x00000000; | |
50 | + *readword = *readword|(rx[0]<<24); | |
51 | + *readword = *readword|(rx[1]<<16); | |
52 | + *readword = *readword|(rx[2]<<8); | |
53 | + *readword = *readword|rx[3]; | |
54 | +} | |
55 | + | |
56 | +//fonction read register | |
57 | +void read_register_ini (int fd, unsigned char addr) | |
58 | +{ | |
59 | + unsigned char tx[1] = {0}; | |
60 | + unsigned char rx[4] = {0}; | |
61 | + addr = addr|0x80; | |
62 | + tx[0]=addr; | |
63 | + spi_put_multiple(fd,tx,1,rx,4); | |
64 | + printf("TX:%x RX:%x %x %x %x\n",tx[0],rx[0],rx[1],rx[2],rx[3]); | |
65 | + // Send_IO_Update (f_dds); //Send the update to set the control registers | |
66 | +} | |
67 | + | |
39 | 68 | //initialisation du dds |
40 | 69 | void Initialize_DDS (int fd, int f_dds) |
41 | 70 | { |
... | ... | @@ -63,7 +92,8 @@ |
63 | 92 | |
64 | 93 | void modulus_setup(int fd, int f_dds) |
65 | 94 | { |
66 | - write_register(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable | |
95 | + write_register(fd,0x00,0x00, 0x01, 0x01, 0x0a); //OSK enable //0x08 | |
96 | + //write_register(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable de base | |
67 | 97 | Send_IO_Update (f_dds); |
68 | 98 | write_register(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp |
69 | 99 | Send_IO_Update (f_dds); |
... | ... | @@ -113,6 +143,24 @@ |
113 | 143 | Send_IO_Update(f_dds); |
114 | 144 | } |
115 | 145 | |
146 | +/* | |
147 | +void getAmpPhaseWord(int fd) | |
148 | +{ | |
149 | + // unsigned char rx[5]={0}; | |
150 | + unsigned char* pt; | |
151 | + read_register(fd,0x0c,rx); // amp (12b) ph(16) | |
152 | + rx[0]=*pt; | |
153 | + rx[1]=*(pt+1); | |
154 | + rx[2]=*(pt+2); | |
155 | + rx[3]=*(pt+3); | |
156 | + rx[4]=*(pt+4); | |
157 | + printf("%c %c %c %c %c", rx[0], rx[1], rx[2], rx[3], rx[4]); | |
158 | +} | |
159 | +*/ | |
160 | +void checkSize(void) | |
161 | +{ | |
162 | + printf("int : %d\n",sizeof(unsigned int)); | |
163 | +} | |
116 | 164 | |
117 | 165 | int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord) |
118 | 166 | { |
... | ... | @@ -156,6 +204,1178 @@ |
156 | 204 | |
157 | 205 | return EXIT_SUCCESS; |
158 | 206 | } |
207 | + | |
208 | +void Send_CTRL_UP(int fp) | |
209 | +{ | |
210 | + char DRCTLOn='0';//pente positive | |
211 | + write(fp,&DRCTLOn,sizeof(DRCTLOn)); // | |
212 | + sleep(0.1); | |
213 | +} | |
214 | + | |
215 | +void Send_CTRL_DOWN(int fp) | |
216 | +{ | |
217 | + char DRCTLOn='2';//pente negative | |
218 | + write(fp,&DRCTLOn,sizeof(DRCTLOn)); //reset | |
219 | + sleep(0.1); | |
220 | +} | |
221 | + | |
222 | +void Send_HOLD(int fp) | |
223 | +{ | |
224 | + char DRHOLDOn ='1';//rampe bloquรฉe | |
225 | + write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset | |
226 | + sleep(0.1); | |
227 | +} | |
228 | + | |
229 | +void Send_UNHOLD(int fp) | |
230 | +{ | |
231 | + char DRHOLDOn ='3';//rampe debloquรฉe | |
232 | + write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset | |
233 | + sleep(0.1); | |
234 | +} | |
235 | + | |
236 | + | |
237 | +int testRampFreq(int fd, int f_dds, int fp) | |
238 | +{ | |
239 | + | |
240 | + | |
241 | + //3-Rampe de pente positive + debloquage | |
242 | + Send_CTRL_DOWN(fp);//rampe up | |
243 | + Send_UNHOLD(fp); | |
244 | + | |
245 | + Send_Reset(f_dds); | |
246 | + //Initialize_DDS (fd, f_dds); | |
247 | + | |
248 | + //0- paramรจtre de bases | |
249 | + write_register(fd,0x00,0x00,0x01,0x01,0x0a);//OSKenable+Read&write | |
250 | + Send_IO_Update(f_dds); | |
251 | + read_register_ini(fd,0x00); | |
252 | + | |
253 | + write_register(fd,0x01,0x00, 0x00, 0x09, 0x00); // enable amp ramp | |
254 | + Send_IO_Update(f_dds); | |
255 | + read_register_ini(fd,0x00); | |
256 | + | |
257 | + //1- Donner une frequence f_dds de 1.1e7 Hz sachant que f_clk=1e9 Hz; | |
258 | + // => Le mot a donner est (p.19) : FTW=(f_dds/f_clk)*2ยณยฒ | |
259 | + // FTW = 42949672.96 = 42 949 673. = 0x028f5c29 | |
260 | + // 1.1e7 =0x02d0e560 | |
261 | + | |
262 | +// 2d0e560 | |
263 | + | |
264 | + //Calibrate_DAC (fd,f_dds); | |
265 | + | |
266 | + | |
267 | + | |
268 | + write_register(fd,0x0b,0x02,0xd0,0xe5,0x60);//mot de frequence | |
269 | + Send_IO_Update(f_dds); | |
270 | + write_register(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle | |
271 | + Send_IO_Update(f_dds); | |
272 | + | |
273 | + printf("Les mots de frequences, d'amplitudes et de phases sont envoyes\n"); | |
274 | + printf("Lecture registre de frequence: 0x0b\n"); | |
275 | + read_register_ini(fd,0x0b); | |
276 | + printf("Lecture registre de amp et phase: 0x0c\n"); | |
277 | + read_register_ini(fd,0x0c); | |
278 | + | |
279 | + Calibrate_DAC (fd,f_dds); | |
280 | + printf("\n\n ----------------------- \n\n"); | |
281 | + | |
282 | + | |
283 | +/* | |
284 | + //2- Taille des dt | |
285 | + | |
286 | + write_register(fd,0x08,0xFF,0xFF,0xFF,0xFF); //+dt max, -dt max (+dt = -dt) | |
287 | + Send_IO_Update(f_dds); | |
288 | + | |
289 | + printf("Les mots de dt sont envoyes\n"); | |
290 | + printf("Lecture dans le registre 0x08 : taille dt\n"); | |
291 | + read_register_ini (fd,0x08); | |
292 | + | |
293 | + | |
294 | + | |
295 | + | |
296 | + printf("\n\n ----------------------- \n\n"); | |
297 | + | |
298 | + | |
299 | + //3- STEP SIZE :dphi | |
300 | + | |
301 | + // en theorie dphi =2.25e-28 degrees | |
302 | + write_register(fd,0x06,0x00,0x00,0x00,0x01); | |
303 | + Send_IO_Update(f_dds); | |
304 | + | |
305 | + write_register(fd,0x07,0x00,0x00,0x00,0x01); | |
306 | + Send_IO_Update(f_dds); | |
307 | + | |
308 | + //printf("\n\n ----------------------- \n\n"); | |
309 | + printf("Les mots de dphi sont envoyes\n"); | |
310 | + printf("Lecture dans les registres 0x06 et 0x07 : taille dt\n"); | |
311 | + read_register_ini (fd,0x06); | |
312 | + read_register_ini (fd,0x07); | |
313 | + | |
314 | + printf("\n\n ----------------------- \n\n"); | |
315 | + //4- Ecrire les extremums de la rampe | |
316 | + | |
317 | + write_register(fd,0x04,0x00,0x00,0x00,0x01);//0 rad | |
318 | + Send_IO_Update(f_dds); | |
319 | + write_register(fd,0x05,0xFF,0xFF,0xFF,0xFF);//2*pi rad | |
320 | + Send_IO_Update(f_dds); | |
321 | + | |
322 | + printf("Les mots des frontieres sont envoyes\n"); | |
323 | + printf("Lecture dans les registres 0x04 et 0x05 : taille dt\n"); | |
324 | + read_register_ini (fd,0x04); | |
325 | + read_register_ini (fd,0x05); | |
326 | + | |
327 | + | |
328 | + //3-Rampe de pente positive ou nรฉgative | |
329 | +// Send_CTRL_UP(fp);//rampe up | |
330 | + | |
331 | + | |
332 | + //4-ecriture dans le registre 0x01 | |
333 | + write_register(fd,0x01,0x00, 0xa8, 0x09, 0x00); // enable amp ramp | |
334 | + Send_IO_Update(f_dds); | |
335 | + | |
336 | + printf("Lecture dans le registre 0x01 : \n"); | |
337 | + read_register_ini (fd,0x01); | |
338 | +// printf("Les mots de dt sont envoyes\n"); | |
339 | + printf("Lecture dans le registre 0x08 : taille dt\n"); | |
340 | + read_register_ini (fd,0x08); | |
341 | + | |
342 | + | |
343 | +*/ | |
344 | + return EXIT_SUCCESS; | |
345 | +} | |
346 | + | |
347 | +//---------------rajout 8/1 | |
348 | + | |
349 | +int PutAmpWord(int fd, int f_dds, double amplitude) | |
350 | +{ | |
351 | + uint16_t PhaseWord = 0x0000; | |
352 | + uint16_t AmpWord = 0x0000; | |
353 | + uint32_t ReadPhaseAmpWord=0x00000000; | |
354 | + | |
355 | + AmpWord = rint(amplitude*(pow(2.0,12.0)-1)/100); | |
356 | + | |
357 | + read_register(fd,0x0c,&ReadPhaseAmpWord); | |
358 | + | |
359 | + PhaseWord = ReadPhaseAmpWord&0xFFFF; | |
360 | + | |
361 | + write_register(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); | |
362 | + Send_IO_Update(f_dds); | |
363 | + | |
364 | + return 0; | |
365 | +} | |
366 | + | |
367 | + | |
368 | +int PutPhaseWord(int fd, int f_dds, double phase) | |
369 | +{ | |
370 | + uint16_t PhaseWord = 0x0000; | |
371 | + uint16_t AmpWord = 0x0000; | |
372 | + uint32_t ReadPhaseAmpWord=0x00000000; | |
373 | + | |
374 | + PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360); | |
375 | + | |
376 | + read_register(fd,0x0c,&ReadPhaseAmpWord); | |
377 | + | |
378 | + AmpWord = ReadPhaseAmpWord>>16&0xFFFF; | |
379 | + | |
380 | + write_register(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); | |
381 | + Send_IO_Update(f_dds); | |
382 | + | |
383 | + return 0; | |
384 | +} | |
385 | + | |
386 | +int PutFrequencyWord(int fd, int f_dds, double fout)//Attention uniquement valable pour fclk = 1 GHz | |
387 | +{ | |
388 | + | |
389 | + uint32_t FTWR = 0x00000000; | |
390 | + FTWR = rint((fout/1e9)*pow(2.0,32.0)); | |
391 | + write_register(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence | |
392 | + Send_IO_Update(f_dds); | |
393 | + | |
394 | + return 0; | |
395 | +} | |
396 | + | |
397 | + | |
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 | +{ | |
400 | + | |
401 | + uint32_t FTWR = 0x00000000; | |
402 | + | |
403 | + FTWR = rint((fout/fclk)*pow(2.0,32.0)); | |
404 | + | |
405 | + write_register(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence | |
406 | + | |
407 | + Send_IO_Update(f_dds); | |
408 | + | |
409 | +// write_register(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle | |
410 | +// Send_IO_Update(f_dds); | |
411 | + | |
412 | + PutPhaseWord(fd,f_dds,phase); | |
413 | + PutAmpWord(fd,f_dds,amp); | |
414 | + | |
415 | + return 0; | |
416 | +} | |
417 | + | |
418 | + | |
419 | +int InitialisationProfile (int fd,int f_dds) | |
420 | +{ | |
421 | + | |
422 | + Send_Reset(f_dds); //les registres sont maintenant par defaut | |
423 | + write_register(fd,0x00,0x00,0x01,0x01,0x0a); //OSK+SDIO input only//ok | |
424 | + Send_IO_Update(f_dds); | |
425 | + write_register(fd,0x01,0x00,0x80,0x09,0x00); // profile mode enable very important | |
426 | + Send_IO_Update(f_dds); | |
427 | + write_register(fd,0x02,0x00,0x00,0x19,0x1c); // default | |
428 | + Send_IO_Update(f_dds); | |
429 | + write_register(fd,0x03,0x01,0x05,0x21,0x20); // calibration 1/2 :enable | |
430 | + Send_IO_Update(f_dds); | |
431 | + write_register(fd,0x03,0x00,0x05,0x21,0x20); // calibration 2/2 :desenable | |
432 | + Send_IO_Update(f_dds); | |
433 | + | |
434 | + return 0; | |
435 | +} | |
436 | + | |
437 | + | |
438 | + | |
439 | +//------------------- FIN RAJOUT 8/1 | |
440 | + | |
441 | + | |
442 | +//-------------------------FONCTIONS RAMPES HARDWARE | |
443 | + | |
444 | +//1-rampe de frequence | |
445 | + | |
446 | +//rampe simple de frรฉquence | |
447 | +int FrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown) | |
448 | +{ | |
449 | + //calcul de N => N=DeltaF/df = DeltaT/dt | |
450 | + | |
451 | + //1-fmax > fmin | |
452 | + double DeltaFreq = FreqMax-FreqMin; | |
453 | + if(FreqMax<FreqMin) | |
454 | + { | |
455 | + printf("FreqMax should be > FreqMin\n"); | |
456 | + printf("Can't Start the ramp\n"); | |
457 | + return -1; | |
458 | + } | |
459 | + | |
460 | + //2- Calcul du nombre de points de la rampe | |
461 | + int NumberPointsUp = DeltaFreq/dfUp; | |
462 | + int NumberPointsDown = DeltaFreq/dfDown; | |
463 | + | |
464 | + //3- En dรฉduire la valeur de dtUp et dtDown | |
465 | + double dtUp = DeltaTimeUp/NumberPointsUp; | |
466 | + double dtDown = DeltaTimeDown/NumberPointsDown; | |
467 | + | |
468 | + double dtmin = 24/fclk; | |
469 | + double dtmax = dtmin*(pow(2.0,16.0)-1); | |
470 | + | |
471 | + //Check Up | |
472 | + if(dtUp<dtmin) | |
473 | + { | |
474 | + printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
475 | + printf("Can't start the ramp\n"); | |
476 | + return -1; | |
477 | + } | |
478 | + | |
479 | + if(dtUp>dtmax) | |
480 | + { | |
481 | + printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
482 | + printf("Can't start the ramp\n"); | |
483 | + return -1; | |
484 | + } | |
485 | + | |
486 | + //Check Down | |
487 | + if(dtDown<dtmin) | |
488 | + { | |
489 | + printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
490 | + printf("Can't start the ramp\n"); | |
491 | + return -1; | |
492 | + } | |
493 | + | |
494 | + if(dtDown>dtmax) | |
495 | + { | |
496 | + printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
497 | + printf("Can't start the ramp\n"); | |
498 | + return -1; | |
499 | + } | |
500 | + | |
501 | + | |
502 | + //4 - Put word in register | |
503 | + | |
504 | + | |
505 | + //4.1 Limit register | |
506 | + uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); | |
507 | + write_register(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence | |
508 | + Send_IO_Update(f_dds); | |
509 | + | |
510 | + uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); | |
511 | + write_register(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence | |
512 | + Send_IO_Update(f_dds); | |
513 | + | |
514 | + | |
515 | + //4.2 dfUP et dfDown | |
516 | + double df_up = DeltaFreq/NumberPointsUp; | |
517 | + double df_down = DeltaFreq/NumberPointsDown; | |
518 | + | |
519 | + uint32_t Word_df_up = rint(df_up*pow(2.0,32.0)/fclk); | |
520 | + uint32_t Word_df_down = rint(df_down*pow(2.0,32.0)/fclk); | |
521 | + | |
522 | + 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 | |
523 | + Send_IO_Update(f_dds); | |
524 | + 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 | |
525 | + Send_IO_Update(f_dds); | |
526 | + | |
527 | + | |
528 | + //4.3 dtUp et dtDown | |
529 | + | |
530 | + uint16_t Word_dt_up = 0x0000; | |
531 | + uint16_t Word_dt_down = 0x0000; | |
532 | + | |
533 | + Word_dt_up = rint(dtUp*fclk/24); | |
534 | + Word_dt_down = rint(dtDown*fclk/24); | |
535 | + | |
536 | + 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 | |
537 | + Send_IO_Update(f_dds); | |
538 | + | |
539 | + //5 Start of the ramp | |
540 | + | |
541 | + write_register(fd,0x01,0x00,0x08,0x09,0x00); //rampe simple | |
542 | + Send_IO_Update(f_dds); | |
543 | + return 0; | |
544 | + | |
545 | + | |
546 | + | |
547 | + return EXIT_SUCCESS; | |
548 | + | |
549 | +} | |
550 | + | |
551 | + | |
552 | +//rampe continue de frรฉquence | |
553 | +int ContinueFrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown) | |
554 | +{ | |
555 | + //calcul de N => N=DeltaF/df = DeltaT/dt | |
556 | + | |
557 | + //1-fmax > fmin | |
558 | + double DeltaFreq = FreqMax-FreqMin; | |
559 | + if(FreqMax<FreqMin) | |
560 | + { | |
561 | + printf("FreqMax should be > FreqMin\n"); | |
562 | + printf("Can't Start the ramp\n"); | |
563 | + return -1; | |
564 | + } | |
565 | + | |
566 | + //2- Calcul du nombre de points de la rampe | |
567 | + int NumberPointsUp = DeltaFreq/dfUp; | |
568 | + int NumberPointsDown = DeltaFreq/dfDown; | |
569 | + | |
570 | + //3- En dรฉduire la valeur de dtUp et dtDown | |
571 | + double dtUp = DeltaTimeUp/NumberPointsUp; | |
572 | + double dtDown = DeltaTimeDown/NumberPointsDown; | |
573 | + | |
574 | + double dtmin = 24/fclk; | |
575 | + double dtmax = dtmin*(pow(2.0,16.0)-1); | |
576 | + | |
577 | + //Check Up | |
578 | + if(dtUp<dtmin) | |
579 | + { | |
580 | + printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
581 | + printf("Can't start the ramp\n"); | |
582 | + return -1; | |
583 | + } | |
584 | + | |
585 | + if(dtUp>dtmax) | |
586 | + { | |
587 | + printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
588 | + printf("Can't start the ramp\n"); | |
589 | + return -1; | |
590 | + } | |
591 | + | |
592 | + //Check Down | |
593 | + if(dtDown<dtmin) | |
594 | + { | |
595 | + printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
596 | + printf("Can't start the ramp\n"); | |
597 | + return -1; | |
598 | + } | |
599 | + | |
600 | + if(dtDown>dtmax) | |
601 | + { | |
602 | + printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
603 | + printf("Can't start the ramp\n"); | |
604 | + return -1; | |
605 | + } | |
606 | + | |
607 | + | |
608 | + //4 - Put word in register | |
609 | + | |
610 | + | |
611 | + //4.1 Limit register | |
612 | + uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); | |
613 | + write_register(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence | |
614 | + Send_IO_Update(f_dds); | |
615 | + | |
616 | + uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); | |
617 | + write_register(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence | |
618 | + Send_IO_Update(f_dds); | |
619 | + | |
620 | + | |
621 | + //4.2 dfUP et dfDown | |
622 | + double df_up = DeltaFreq/NumberPointsUp; | |
623 | + double df_down = DeltaFreq/NumberPointsDown; | |
624 | + | |
625 | + uint32_t Word_df_up = rint(df_up*pow(2.0,32.0)/fclk); | |
626 | + uint32_t Word_df_down = rint(df_down*pow(2.0,32.0)/fclk); | |
627 | + | |
628 | + 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 | |
629 | + Send_IO_Update(f_dds); | |
630 | + 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 | |
631 | + Send_IO_Update(f_dds); | |
632 | + | |
633 | + | |
634 | + //4.3 dtUp et dtDown | |
635 | + | |
636 | + uint16_t Word_dt_up = 0x0000; | |
637 | + uint16_t Word_dt_down = 0x0000; | |
638 | + | |
639 | + Word_dt_up = rint(dtUp*fclk/24); | |
640 | + Word_dt_down = rint(dtDown*fclk/24); | |
641 | + | |
642 | + 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 | |
643 | + Send_IO_Update(f_dds); | |
644 | + | |
645 | + //5 Start of the ramp | |
646 | + | |
647 | + write_register(fd,0x01,0x00,0x8e,0x29,0x00); //rampe triangulaire | |
648 | + Send_IO_Update(f_dds); | |
649 | + return 0; | |
650 | + | |
651 | + | |
652 | + | |
653 | + return EXIT_SUCCESS; | |
654 | + | |
655 | +} | |
656 | + | |
657 | +//2-rampe d'amplitude | |
658 | + | |
659 | +int AmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) | |
660 | +{ | |
661 | + | |
662 | + | |
663 | + //calcul de N => N=DeltaF/df = DeltaT/dt | |
664 | + | |
665 | + //1-Amax > Amin | |
666 | + double DeltaAmp = AMax-AMin; | |
667 | + if(AMax<AMin) | |
668 | + { | |
669 | + printf("AMax should be > AMin\n"); | |
670 | + printf("Can't Start the ramp\n"); | |
671 | + return -1; | |
672 | + } | |
673 | + | |
674 | + | |
675 | + //2- Calcul du nombre de points de la rampe | |
676 | + int NumberPointsUp = DeltaAmp/dAUp; | |
677 | + int NumberPointsDown = DeltaAmp/dADown; | |
678 | + | |
679 | + //3- En dรฉduire la valeur de dtUp et dtDown | |
680 | + double dtUp = DeltaTimeUp/NumberPointsUp; | |
681 | + double dtDown = DeltaTimeDown/NumberPointsDown; | |
682 | + | |
683 | + double dtmin = 24/fclk; | |
684 | + double dtmax = dtmin*(pow(2.0,16.0)-1); | |
685 | + | |
686 | + //Check Up | |
687 | + if(dtUp<dtmin) | |
688 | + { | |
689 | + printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
690 | + printf("Can't start the ramp\n"); | |
691 | + return -1; | |
692 | + } | |
693 | + | |
694 | + if(dtUp>dtmax) | |
695 | + { | |
696 | + printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
697 | + printf("Can't start the ramp\n"); | |
698 | + return -1; | |
699 | + } | |
700 | + | |
701 | + //Check Down | |
702 | + if(dtDown<dtmin) | |
703 | + { | |
704 | + printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
705 | + printf("Can't start the ramp\n"); | |
706 | + return -1; | |
707 | + } | |
708 | + | |
709 | + if(dtDown>dtmax) | |
710 | + { | |
711 | + printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
712 | + printf("Can't start the ramp\n"); | |
713 | + return -1; | |
714 | + } | |
715 | + | |
716 | + | |
717 | + | |
718 | + //check if DeltaAmp is enouth | |
719 | + double enouthUP=0.5*NumberPointsUp*100/4095; | |
720 | + double enouthDOWN=0.5*NumberPointsDown*100/4095; | |
721 | + | |
722 | + int borneUP = rint(enouthUP); | |
723 | + int borneDown = rint(enouthDOWN); | |
724 | + | |
725 | + if(DeltaAmp<=enouthUP) | |
726 | + { | |
727 | + printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | |
728 | + //return -1; | |
729 | + } | |
730 | + | |
731 | + if(DeltaAmp<=enouthDOWN) | |
732 | + { | |
733 | + printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | |
734 | + //return -1; | |
735 | + } | |
736 | + | |
737 | + | |
738 | + //4 - Put word in register | |
739 | + | |
740 | + | |
741 | + //4.1 Limit register | |
742 | + uint32_t WordAmin = rint(AMin*4095/100); | |
743 | + uint32_t WordAmax= rint(AMax*4095/100); | |
744 | + | |
745 | + write_register(fd,0x04,WordAmin>>24&0xFF,WordAmin>>16&0xFF,WordAmin>>8&0xFF,WordAmin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | |
746 | + Send_IO_Update(f_dds); | |
747 | + write_register(fd,0x05,WordAmax>>24&0xFF,WordAmax>>16&0xFF,WordAmax>>8&0xFF,WordAmax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | |
748 | + Send_IO_Update(f_dds); | |
749 | + | |
750 | + | |
751 | + //4.2 dAUP et dADown | |
752 | + | |
753 | + uint32_t Word_dA_up = rint(dAUp*4095/100); | |
754 | + uint32_t Word_dA_down = rint(dADown*4095/100); | |
755 | + | |
756 | + 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 | |
757 | + Send_IO_Update(f_dds); | |
758 | + 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 | |
759 | + Send_IO_Update(f_dds); | |
760 | + | |
761 | + | |
762 | + //4.3 dtUp et dtDown | |
763 | + | |
764 | + uint16_t Word_dt_up = rint(dtUp*fclk/24); | |
765 | + uint16_t Word_dt_down = rint(dtDown*fclk/24); | |
766 | + | |
767 | + 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 | |
768 | + Send_IO_Update(f_dds); | |
769 | + | |
770 | + //5 Start of the ramp | |
771 | + | |
772 | + write_register(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante | |
773 | + //write_register(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue | |
774 | + Send_IO_Update(f_dds); | |
775 | + | |
776 | + return EXIT_SUCCESS; | |
777 | +} | |
778 | + | |
779 | +int ContinueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) | |
780 | +{ | |
781 | + | |
782 | + | |
783 | + //calcul de N => N=DeltaF/df = DeltaT/dt | |
784 | + | |
785 | + //1-Amax > Amin | |
786 | + double DeltaAmp = AMax-AMin; | |
787 | + if(AMax<AMin) | |
788 | + { | |
789 | + printf("AMax should be > AMin\n"); | |
790 | + printf("Can't Start the ramp\n"); | |
791 | + return -1; | |
792 | + } | |
793 | + | |
794 | + | |
795 | + //2- Calcul du nombre de points de la rampe | |
796 | + int NumberPointsUp = DeltaAmp/dAUp; | |
797 | + int NumberPointsDown = DeltaAmp/dADown; | |
798 | + | |
799 | + //3- En dรฉduire la valeur de dtUp et dtDown | |
800 | + double dtUp = DeltaTimeUp/NumberPointsUp; | |
801 | + double dtDown = DeltaTimeDown/NumberPointsDown; | |
802 | + | |
803 | + double dtmin = 24/fclk; | |
804 | + double dtmax = dtmin*(pow(2.0,16.0)-1); | |
805 | + | |
806 | + //Check Up | |
807 | + if(dtUp<dtmin) | |
808 | + { | |
809 | + printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
810 | + printf("Can't start the ramp\n"); | |
811 | + return -1; | |
812 | + } | |
813 | + | |
814 | + if(dtUp>dtmax) | |
815 | + { | |
816 | + printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
817 | + printf("Can't start the ramp\n"); | |
818 | + return -1; | |
819 | + } | |
820 | + | |
821 | + //Check Down | |
822 | + if(dtDown<dtmin) | |
823 | + { | |
824 | + printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
825 | + printf("Can't start the ramp\n"); | |
826 | + return -1; | |
827 | + } | |
828 | + | |
829 | + if(dtDown>dtmax) | |
830 | + { | |
831 | + printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
832 | + printf("Can't start the ramp\n"); | |
833 | + return -1; | |
834 | + } | |
835 | + | |
836 | + | |
837 | + | |
838 | + //check if DeltaAmp is enouth | |
839 | + double enouthUP=0.5*NumberPointsUp*100/4095; | |
840 | + double enouthDOWN=0.5*NumberPointsDown*100/4095; | |
841 | + | |
842 | + int borneUP = rint(enouthUP); | |
843 | + int borneDown = rint(enouthDOWN); | |
844 | + | |
845 | + if(DeltaAmp<=enouthUP) | |
846 | + { | |
847 | + printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | |
848 | + //return -1; | |
849 | + } | |
850 | + | |
851 | + if(DeltaAmp<=enouthDOWN) | |
852 | + { | |
853 | + printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | |
854 | + //return -1; | |
855 | + } | |
856 | + | |
857 | + | |
858 | + //4 - Put word in register | |
859 | + | |
860 | + | |
861 | + //4.1 Limit register | |
862 | + uint32_t WordAmin = rint(AMin*4095/100); | |
863 | + uint32_t WordAmax= rint(AMax*4095/100); | |
864 | + | |
865 | + write_register(fd,0x04,WordAmin>>24&0xFF,WordAmin>>16&0xFF,WordAmin>>8&0xFF,WordAmin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | |
866 | + Send_IO_Update(f_dds); | |
867 | + write_register(fd,0x05,WordAmax>>24&0xFF,WordAmax>>16&0xFF,WordAmax>>8&0xFF,WordAmax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | |
868 | + Send_IO_Update(f_dds); | |
869 | + | |
870 | + | |
871 | + //4.2 dAUP et dADown | |
872 | + | |
873 | + uint32_t Word_dA_up = rint(dAUp*4095/100); | |
874 | + uint32_t Word_dA_down = rint(dADown*4095/100); | |
875 | + | |
876 | + 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 | |
877 | + Send_IO_Update(f_dds); | |
878 | + 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 | |
879 | + Send_IO_Update(f_dds); | |
880 | + | |
881 | + | |
882 | + //4.3 dtUp et dtDown | |
883 | + | |
884 | + uint16_t Word_dt_up = rint(dtUp*fclk/24); | |
885 | + uint16_t Word_dt_down = rint(dtDown*fclk/24); | |
886 | + | |
887 | + 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 | |
888 | + Send_IO_Update(f_dds); | |
889 | + | |
890 | + //5 Start of the ramp | |
891 | + | |
892 | + //write_register(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante | |
893 | + write_register(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue | |
894 | + Send_IO_Update(f_dds); | |
895 | + | |
896 | + return EXIT_SUCCESS; | |
897 | +} | |
898 | + | |
899 | + | |
900 | +//3-rampe de ฤฅase | |
901 | + | |
902 | +int PhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown) | |
903 | +{ | |
904 | + | |
905 | + | |
906 | + //calcul de N => N=Deltaphi/dphi = DeltaT/dt | |
907 | + | |
908 | + //1-phimax > phimin | |
909 | + double DeltaPhi = PhiMax-PhiMin; | |
910 | + if(PhiMax<PhiMin) | |
911 | + { | |
912 | + printf("PhiMax should be > PhiMin\n"); | |
913 | + printf("Can't Start the ramp\n"); | |
914 | + return -1; | |
915 | + } | |
916 | + | |
917 | + | |
918 | + //2- Calcul du nombre de points de la rampe | |
919 | + int NumberPointsUp = DeltaPhi/dphiUp; | |
920 | + int NumberPointsDown = DeltaPhi/dphiDown; | |
921 | + | |
922 | + printf("NumberPointsUp = %d\n",NumberPointsUp); | |
923 | + printf("NumberPointsDown = %d\n",NumberPointsDown); | |
924 | + | |
925 | + //3- En dรฉduire la valeur de dtUp et dtDown | |
926 | + double dtUp = DeltaTimeUp/NumberPointsUp; | |
927 | + double dtDown = DeltaTimeDown/NumberPointsDown; | |
928 | + | |
929 | + double dtmin = 24/fclk; | |
930 | + double dtmax = dtmin*(pow(2.0,16.0)-1); | |
931 | + | |
932 | + //Check Up | |
933 | + if(dtUp<dtmin) | |
934 | + { | |
935 | + printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
936 | + printf("Can't start the ramp\n"); | |
937 | + return -1; | |
938 | + } | |
939 | + | |
940 | + if(dtUp>dtmax) | |
941 | + { | |
942 | + printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
943 | + printf("Can't start the ramp\n"); | |
944 | + return -1; | |
945 | + } | |
946 | + | |
947 | + //Check Down | |
948 | + if(dtDown<dtmin) | |
949 | + { | |
950 | + printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
951 | + printf("Can't start the ramp\n"); | |
952 | + return -1; | |
953 | + } | |
954 | + | |
955 | + if(dtDown>dtmax) | |
956 | + { | |
957 | + printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
958 | + printf("Can't start the ramp\n"); | |
959 | + return -1; | |
960 | + } | |
961 | + | |
962 | + | |
963 | + | |
964 | + //check if DeltaAmp is enouth | |
965 | +/* | |
966 | + double enouthUP=0.5*NumberPointsUp*100/4095; | |
967 | + double enouthDOWN=0.5*NumberPointsDown*100/4095; | |
968 | + | |
969 | + int borneUP = rint(enouthUP); | |
970 | + int borneDown = rint(enouthDOWN); | |
971 | + | |
972 | + if(DeltaAmp<=enouthUP) | |
973 | + { | |
974 | + printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | |
975 | + //return -1; | |
976 | + } | |
977 | + | |
978 | + if(DeltaAmp<=enouthDOWN) | |
979 | + { | |
980 | + printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | |
981 | + //return -1; | |
982 | + } | |
983 | + | |
984 | +*/ | |
985 | + | |
986 | + //4 - Put word in register | |
987 | + | |
988 | + | |
989 | + //4.1 Limit register | |
990 | + uint32_t WordPhimin = rint(PhiMin*65535/360); | |
991 | + uint32_t WordPhimax= rint(PhiMax*65535/360); | |
992 | + | |
993 | + | |
994 | + printf("WordPhimin = %.32x\n",WordPhimin); | |
995 | + printf("WordPhimax = %.32x\n",WordPhimax); | |
996 | + | |
997 | + | |
998 | + write_register(fd,0x04,WordPhimin>>24&0xFF,WordPhimin>>16&0xFF,WordPhimin>>8&0xFF,WordPhimin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | |
999 | + Send_IO_Update(f_dds); | |
1000 | + write_register(fd,0x05,WordPhimax>>24&0xFF,WordPhimax>>16&0xFF,WordPhimax>>8&0xFF,WordPhimax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | |
1001 | + Send_IO_Update(f_dds); | |
1002 | + | |
1003 | + | |
1004 | + //4.2 dphiUP et dphiDown | |
1005 | + | |
1006 | +// uint32_t Word_dphi_up = rint(dphiUp*(pow(2.0,29.0)-1)/45); | |
1007 | +// uint32_t Word_dphi_down = rint(dphiDown*(pow(2.0,29.0)-1)/45); | |
1008 | + uint32_t Word_dphi_up = rint(dphiUp*(65535/360)); | |
1009 | + uint32_t Word_dphi_down = rint(dphiDown*(65535/360)); | |
1010 | + | |
1011 | + printf("Word_dphi_up = %.32x\n",Word_dphi_up); | |
1012 | + printf("Word_dphi_down = %.32x\n",Word_dphi_down); | |
1013 | + | |
1014 | +/* | |
1015 | + 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 | |
1016 | + Send_IO_Update(f_dds); | |
1017 | + 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 | |
1018 | + Send_IO_Update(f_dds); | |
1019 | + | |
1020 | +*/ | |
1021 | + | |
1022 | + | |
1023 | + 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 | |
1024 | + Send_IO_Update(f_dds); | |
1025 | + 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 | |
1026 | + Send_IO_Update(f_dds); | |
1027 | + | |
1028 | + | |
1029 | + //4.3 dtUp et dtDown | |
1030 | + | |
1031 | + uint16_t Word_dt_up = rint(dtUp*fclk/24); | |
1032 | + uint16_t Word_dt_down = rint(dtDown*fclk/24); | |
1033 | + | |
1034 | + 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 | |
1035 | + Send_IO_Update(f_dds); | |
1036 | + | |
1037 | + //5 Start of the ramp | |
1038 | + | |
1039 | + write_register(fd,0x01,0x00,0x18,0x09,0x00); //rampe simple montante | |
1040 | + Send_IO_Update(f_dds); | |
1041 | + | |
1042 | + return EXIT_SUCCESS; | |
1043 | +} | |
1044 | + | |
1045 | +int ContinuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown) | |
1046 | +{ | |
1047 | + | |
1048 | + | |
1049 | + //calcul de N => N=Deltaphi/dphi = DeltaT/dt | |
1050 | + | |
1051 | + //1-phimax > phimin | |
1052 | + double DeltaPhi = PhiMax-PhiMin; | |
1053 | + if(PhiMax<PhiMin) | |
1054 | + { | |
1055 | + printf("PhiMax should be > PhiMin\n"); | |
1056 | + printf("Can't Start the ramp\n"); | |
1057 | + return -1; | |
1058 | + } | |
1059 | + | |
1060 | + | |
1061 | + //2- Calcul du nombre de points de la rampe | |
1062 | + int NumberPointsUp = DeltaPhi/dphiUp; | |
1063 | + int NumberPointsDown = DeltaPhi/dphiDown; | |
1064 | + | |
1065 | + printf("NumberPointsUp = %d\n",NumberPointsUp); | |
1066 | + printf("NumberPointsDown = %d\n",NumberPointsDown); | |
1067 | + | |
1068 | + //3- En dรฉduire la valeur de dtUp et dtDown | |
1069 | + double dtUp = DeltaTimeUp/NumberPointsUp; | |
1070 | + double dtDown = DeltaTimeDown/NumberPointsDown; | |
1071 | + | |
1072 | + double dtmin = 24/fclk; | |
1073 | + double dtmax = dtmin*(pow(2.0,16.0)-1); | |
1074 | + | |
1075 | + //Check Up | |
1076 | + if(dtUp<dtmin) | |
1077 | + { | |
1078 | + printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); | |
1079 | + printf("Can't start the ramp\n"); | |
1080 | + return -1; | |
1081 | + } | |
1082 | + | |
1083 | + if(dtUp>dtmax) | |
1084 | + { | |
1085 | + printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); | |
1086 | + printf("Can't start the ramp\n"); | |
1087 | + return -1; | |
1088 | + } | |
1089 | + | |
1090 | + //Check Down | |
1091 | + if(dtDown<dtmin) | |
1092 | + { | |
1093 | + printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); | |
1094 | + printf("Can't start the ramp\n"); | |
1095 | + return -1; | |
1096 | + } | |
1097 | + | |
1098 | + if(dtDown>dtmax) | |
1099 | + { | |
1100 | + printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); | |
1101 | + printf("Can't start the ramp\n"); | |
1102 | + return -1; | |
1103 | + } | |
1104 | + | |
1105 | + | |
1106 | + | |
1107 | + //check if DeltaAmp is enouth | |
1108 | +/* | |
1109 | + double enouthUP=0.5*NumberPointsUp*100/4095; | |
1110 | + double enouthDOWN=0.5*NumberPointsDown*100/4095; | |
1111 | + | |
1112 | + int borneUP = rint(enouthUP); | |
1113 | + int borneDown = rint(enouthDOWN); | |
1114 | + | |
1115 | + if(DeltaAmp<=enouthUP) | |
1116 | + { | |
1117 | + printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); | |
1118 | + //return -1; | |
1119 | + } | |
1120 | + | |
1121 | + if(DeltaAmp<=enouthDOWN) | |
1122 | + { | |
1123 | + printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); | |
1124 | + //return -1; | |
1125 | + } | |
1126 | + | |
1127 | +*/ | |
1128 | + | |
1129 | + //4 - Put word in register | |
1130 | + | |
1131 | + | |
1132 | + //4.1 Limit register | |
1133 | + uint32_t WordPhimin = rint(PhiMin*65535/360); | |
1134 | + uint32_t WordPhimax= rint(PhiMax*65535/360); | |
1135 | + | |
1136 | + | |
1137 | + printf("WordPhimin = %.32x\n",WordPhimin); | |
1138 | + printf("WordPhimax = %.32x\n",WordPhimax); | |
1139 | + | |
1140 | + | |
1141 | + write_register(fd,0x04,WordPhimin>>24&0xFF,WordPhimin>>16&0xFF,WordPhimin>>8&0xFF,WordPhimin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 | |
1142 | + Send_IO_Update(f_dds); | |
1143 | + write_register(fd,0x05,WordPhimax>>24&0xFF,WordPhimax>>16&0xFF,WordPhimax>>8&0xFF,WordPhimax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 | |
1144 | + Send_IO_Update(f_dds); | |
1145 | + | |
1146 | + | |
1147 | + //4.2 dphiUP et dphiDown | |
1148 | + | |
1149 | +// uint32_t Word_dphi_up = rint(dphiUp*(pow(2.0,29.0)-1)/45); | |
1150 | +// uint32_t Word_dphi_down = rint(dphiDown*(pow(2.0,29.0)-1)/45); | |
1151 | + uint32_t Word_dphi_up = rint(dphiUp*(65535/360)); | |
1152 | + uint32_t Word_dphi_down = rint(dphiDown*(65535/360)); | |
1153 | + | |
1154 | + printf("Word_dphi_up = %.32x\n",Word_dphi_up); | |
1155 | + printf("Word_dphi_down = %.32x\n",Word_dphi_down); | |
1156 | + | |
1157 | +/* | |
1158 | + 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 | |
1159 | + Send_IO_Update(f_dds); | |
1160 | + 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 | |
1161 | + Send_IO_Update(f_dds); | |
1162 | + | |
1163 | +*/ | |
1164 | + | |
1165 | + | |
1166 | + 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 | |
1167 | + Send_IO_Update(f_dds); | |
1168 | + 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 | |
1169 | + Send_IO_Update(f_dds); | |
1170 | + | |
1171 | + | |
1172 | + //4.3 dtUp et dtDown | |
1173 | + | |
1174 | + uint16_t Word_dt_up = rint(dtUp*fclk/24); | |
1175 | + uint16_t Word_dt_down = rint(dtDown*fclk/24); | |
1176 | + | |
1177 | + 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 | |
1178 | + Send_IO_Update(f_dds); | |
1179 | + | |
1180 | + //5 Start of the ramp | |
1181 | + | |
1182 | + write_register(fd,0x01,0x00,0x9E,0x29,0x00); //rampe simple montante | |
1183 | + Send_IO_Update(f_dds); | |
1184 | + | |
1185 | + return EXIT_SUCCESS; | |
1186 | +} | |
1187 | + | |
1188 | + | |
1189 | +//-------------------------FIN FONCTIONS RAMPES HARDWARES | |
1190 | + | |
1191 | +//--------------------------FONCTIONS RAMPES SOFTWARES | |
1192 | + | |
1193 | +int RampAmpFromSoft(int fd, int f_dds,double DeltaTimeUp,double AIni, double AFin) | |
1194 | +{ | |
1195 | + | |
1196 | + //On va plutรดt fixรฉ dA sinon trop de contrainte : => Besoin d'allocation dynamique | |
1197 | + double dA=0.024;//en % | |
1198 | + double DeltaAmp = AIni-AFin; | |
1199 | + double AbsDeltaAmp = 0; | |
1200 | + if(DeltaAmp>=0) | |
1201 | + { | |
1202 | + AbsDeltaAmp = DeltaAmp; | |
1203 | + } | |
1204 | + else | |
1205 | + { | |
1206 | + AbsDeltaAmp = -1*DeltaAmp; | |
1207 | + } | |
1208 | + | |
1209 | + int NumberPoints = AbsDeltaAmp/dA; | |
1210 | + | |
1211 | + double dt=DeltaTimeUp/NumberPoints; | |
1212 | + | |
1213 | + printf("Taille du tableau = %d\n", NumberPoints); | |
1214 | + printf("dt = %f s\n",dt); | |
1215 | + | |
1216 | + | |
1217 | + uint16_t* ArrayWordAmp= NULL; | |
1218 | + ArrayWordAmp = malloc(NumberPoints*sizeof(uint16_t)); | |
1219 | + | |
1220 | + //extraction de la phase initiale et de l'amplitude | |
1221 | + | |
1222 | + uint32_t ReadPhaseAmpWord = 0x00000000; | |
1223 | + read_register(fd, 0x0c,&ReadPhaseAmpWord); | |
1224 | + printf("ReadPhaseAmpWord = %.8x \n", ReadPhaseAmpWord); | |
1225 | + | |
1226 | + uint16_t WordPhaseInitiale = ReadPhaseAmpWord&0xFFFF; | |
1227 | + printf("Phase = %.4x \n", WordPhaseInitiale); | |
1228 | + | |
1229 | + | |
1230 | + // | |
1231 | + for(int i=0;i<NumberPoints;i++) | |
1232 | + { | |
1233 | + ArrayWordAmp[i]=rint((AIni+i*dA)*4096/100); | |
1234 | + // printf("ArrayWordAmp[%d] = %.16x\n", i, ArrayWordAmp[i]); | |
1235 | + } | |
1236 | + free(ArrayWordAmp); | |
1237 | + | |
1238 | + printf("Array calculated\n"); | |
1239 | + | |
1240 | + printf("Start of the ramp\n"); | |
1241 | + for(int i=0;i<NumberPoints;i++) | |
1242 | + { | |
1243 | + write_register(fd,0x0c,ArrayWordAmp[i]>>8&0xFF,ArrayWordAmp[i]&0xFF,WordPhaseInitiale>>8&0xFF,WordPhaseInitiale&0xFF); | |
1244 | + Send_IO_Update(f_dds); | |
1245 | + usleep(1000000*dt); | |
1246 | + } | |
1247 | + | |
1248 | + | |
1249 | + | |
1250 | +/* | |
1251 | + uint16_t PhaseWord = 0x0000; | |
1252 | + uint16_t AmpWord = 0x0000; | |
1253 | + uint32_t ReadPhaseAmpWord=0x00000000; | |
1254 | + | |
1255 | + AmpWord = rint(amplitude*(pow(2.0,12.0)-1)/100); | |
1256 | + | |
1257 | + read_register(fd,0x0c,&ReadPhaseAmpWord); | |
1258 | + | |
1259 | + PhaseWord = ReadPhaseAmpWord&0xFFFF; | |
1260 | + | |
1261 | + write_register(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); | |
1262 | + | |
1263 | +*/ | |
1264 | + | |
1265 | + | |
1266 | + | |
1267 | +/* | |
1268 | + | |
1269 | + //pas de durรฉe dtUp et dtDown fixรฉe au minimum ร 1 ms | |
1270 | + if(DeltaTimeUp < 4.095) | |
1271 | + { | |
1272 | + printf("Use hardware fonctions for the ramp\n"); | |
1273 | + } | |
1274 | + | |
1275 | + | |
1276 | + // | |
1277 | + double DeltaAmp = AMax-AMin; | |
1278 | + double dA = DeltaAmp/TAILLETAB; | |
1279 | + printf("dA=%f\n",dA); | |
1280 | + | |
1281 | + | |
1282 | + if(dA<0.024) | |
1283 | + { | |
1284 | + printf("Amplitude step should be > 0.024 pourcent\n"); | |
1285 | + printf("Impossible to start a ramp of amplitude\n"); | |
1286 | + return -1; | |
1287 | + } | |
1288 | + | |
1289 | + //extraction de la phase initiale et de l'amplitude | |
1290 | + | |
1291 | + uint32_t ReadPhaseAmpWord = 0x00000000; | |
1292 | + read_register(fd, 0x0c,&ReadPhaseAmpWord); | |
1293 | + printf("ReadPhaseAmpWord = %.8x \n", ReadPhaseAmpWord); | |
1294 | + | |
1295 | + uint16_t WordPhaseInitiale = ReadPhaseAmpWord&0xFFFF; | |
1296 | + printf("Phase = %.4x \n", WordPhaseInitiale); | |
1297 | + | |
1298 | + uint16_t WordAmpInitiale = ReadPhaseAmpWord>>16&0xFFFF; | |
1299 | + printf("Amp = %.4x \n", WordAmpInitiale); | |
1300 | + | |
1301 | + uint16_t Word_dA = rint(dA*4095/100); | |
1302 | + | |
1303 | + uint32_t ArrayWordAmp[TAILLETAB]; | |
1304 | + | |
1305 | + for(int i=0;i<TAILLETAB;i++) | |
1306 | + { | |
1307 | + ArrayWordAmp[i]=WordAmpInitiale+i*Word_dA; | |
1308 | +// printf("ArrayWordAmp[%d] = %.16x\n", i, ArrayWordAmp[i]); | |
1309 | + } | |
1310 | + | |
1311 | +*/ | |
1312 | + | |
1313 | + return EXIT_SUCCESS; | |
1314 | +} | |
1315 | + | |
1316 | +int RampPhaseFromSoft(int fd, int f_dds,double DeltaTimeUp,double PhiIni, double PhiFin) | |
1317 | +{ | |
1318 | + | |
1319 | + //On va plutรดt fixรฉ dphi : => Besoin d'allocation dynamique | |
1320 | + double dphi=0.06;//en ยฐ | |
1321 | + double DeltaPhi = PhiIni-PhiFin; | |
1322 | + double AbsDeltaPhi = 0; | |
1323 | + if(DeltaPhi>=0) | |
1324 | + { | |
1325 | + AbsDeltaPhi = DeltaPhi; | |
1326 | + } | |
1327 | + else | |
1328 | + { | |
1329 | + AbsDeltaPhi = -1*DeltaPhi; | |
1330 | + } | |
1331 | + | |
1332 | + int NumberPoints = AbsDeltaPhi/dphi; | |
1333 | + | |
1334 | + double dt=DeltaTimeUp/NumberPoints; | |
1335 | + | |
1336 | + printf("Taille du tableau = %d\n", NumberPoints); | |
1337 | + printf("dt = %f s\n",dt); | |
1338 | + | |
1339 | + | |
1340 | + uint16_t* ArrayWordPhi= NULL; | |
1341 | + ArrayWordPhi = malloc(NumberPoints*sizeof(uint16_t)); | |
1342 | + | |
1343 | + //extraction de l'amplitude | |
1344 | + | |
1345 | + uint32_t ReadPhaseAmpWord = 0x00000000; | |
1346 | + read_register(fd, 0x0c,&ReadPhaseAmpWord); | |
1347 | + printf("ReadPhaseAmpWord = %.8x \n", ReadPhaseAmpWord); | |
1348 | + | |
1349 | + uint16_t WordAmpInitiale = ReadPhaseAmpWord>>16&0xFFFF; | |
1350 | + printf("Amp = %.4x \n", WordAmpInitiale); | |
1351 | + | |
1352 | + | |
1353 | + for(int i=0;i<NumberPoints;i++) | |
1354 | + { | |
1355 | + ArrayWordPhi[i]=rint((PhiIni+i*dphi)*65536/360); | |
1356 | + } | |
1357 | + free(ArrayWordPhi); | |
1358 | + | |
1359 | + printf("Array calculated\n"); | |
1360 | + | |
1361 | + printf("Start of the ramp\n"); | |
1362 | + for(int i=0;i<NumberPoints;i++) | |
1363 | + { | |
1364 | + write_register(fd,0x0c,WordAmpInitiale>>8&0xFF,WordAmpInitiale&0xFF,ArrayWordPhi[i]>>8&0xFF,ArrayWordPhi[i]&0xFF); | |
1365 | + Send_IO_Update(f_dds); | |
1366 | + usleep(1000000*dt); | |
1367 | + } | |
1368 | + | |
1369 | + | |
1370 | + return EXIT_SUCCESS; | |
1371 | +} | |
1372 | + | |
1373 | + | |
1374 | + | |
1375 | +//-------------------------FIN FONCTIONS RAMPES SOFTWARES | |
1376 | + | |
1377 | + | |
1378 | + | |
159 | 1379 | |
160 | 1380 | int receiveParameterFromPythonServer(char * device, double f_clk, double f_out){ |
161 | 1381 |