Blame view

src/ad9915.c 28.5 KB
dfa91a3bc   pyb   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   bachi   ad9915.c et ad991...
10
  void sendReset(int f_dds)
dfa91a3bc   pyb   libad9915 : add i...
11
  {
e41d5220b   bachi   ad9915.c : nettoy...
12
  		write(f_dds,"2",1); 
dfa91a3bc   pyb   libad9915 : add i...
13
14
15
  }
  
  //fonction ioupdate
41fb442f6   bachi   ad9915.c et ad991...
16
  void sendIOUpdate(int f_dds)
dfa91a3bc   pyb   libad9915 : add i...
17
  {
e41d5220b   bachi   ad9915.c : nettoy...
18
  		write(f_dds,"1",1);
dfa91a3bc   pyb   libad9915 : add i...
19
20
21
  }
  
  //fonction write register
41fb442f6   bachi   ad9915.c et ad991...
22
  void  writeRegister (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0)
dfa91a3bc   pyb   libad9915 : add i...
23
24
25
26
27
28
29
30
31
32
33
34
  {
  		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   bachi   mise a jour avec ...
35
36
  //fonction read register
  
41fb442f6   bachi   ad9915.c et ad991...
37
  void  readRegister (int fd,unsigned char addr, uint32_t *readword)
09ecc607d   bachi   mise a jour avec ...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  {
  		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   bachi   ad9915.c et ad991...
54
  void  readRegisterIni (int fd, unsigned char addr)
09ecc607d   bachi   mise a jour avec ...
55
56
57
58
59
60
61
62
  {
  		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   bachi   ad9915.c et ad991...
63
  	//	sendIOUpdate (f_dds);    //Send the update to set the control registers
09ecc607d   bachi   mise a jour avec ...
64
65
  }
  
dfa91a3bc   pyb   libad9915 : add i...
66
  //initialisation du dds
41fb442f6   bachi   ad9915.c et ad991...
67
  void initializeDDS (int fd, int f_dds)
dfa91a3bc   pyb   libad9915 : add i...
68
  {
41fb442f6   bachi   ad9915.c et ad991...
69
70
71
72
73
74
75
76
77
78
79
  	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   pyb   libad9915 : add i...
80
81
82
  }
  
  //calibration du dac
41fb442f6   bachi   ad9915.c et ad991...
83
  void calibrateDAC (int fd, int f_dds)
dfa91a3bc   pyb   libad9915 : add i...
84
  {		
41fb442f6   bachi   ad9915.c et ad991...
85
86
87
88
  	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   pyb   libad9915 : add i...
89
90
  }
  
41fb442f6   bachi   ad9915.c et ad991...
91
  void modulusSetup(int fd, int f_dds) 
dfa91a3bc   pyb   libad9915 : add i...
92
  {
41fb442f6   bachi   ad9915.c et ad991...
93
  	writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x0a); //OSK enable //0x08
41fb442f6   bachi   ad9915.c et ad991...
94
95
96
    	sendIOUpdate (f_dds);
  	writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp
    	sendIOUpdate (f_dds);
dfa91a3bc   pyb   libad9915 : add i...
97
98
  }
  
41fb442f6   bachi   ad9915.c et ad991...
99
  void basicSetup(int fd, int f_dds,uint16_t ampWord, uint16_t phaseWord)
dfa91a3bc   pyb   libad9915 : add i...
100
  {
41fb442f6   bachi   ad9915.c et ad991...
101
102
103
104
  	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);
e41d5220b   bachi   ad9915.c : nettoy...
105
  	writeRegister(fd,0x04,0x19, 0x99, 0x99, 0x99); //ftw
41fb442f6   bachi   ad9915.c et ad991...
106
    	sendIOUpdate (f_dds);
e41d5220b   bachi   ad9915.c : nettoy...
107
  	writeRegister(fd,0x05,0xC0, 0x00, 0x00, 0x00); //A
41fb442f6   bachi   ad9915.c et ad991...
108
    	sendIOUpdate (f_dds);
e41d5220b   bachi   ad9915.c : nettoy...
109
  	writeRegister(fd,0x06,0x00, 0x00, 0x00, 0x05);  //B
41fb442f6   bachi   ad9915.c et ad991...
110
    	sendIOUpdate (f_dds);
e41d5220b   bachi   ad9915.c : nettoy...
111
  	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)
41fb442f6   bachi   ad9915.c et ad991...
112
    	sendIOUpdate (f_dds);
dfa91a3bc   pyb   libad9915 : add i...
113
114
115
116
  }
  
  void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B)
  {
41fb442f6   bachi   ad9915.c et ad991...
117
118
119
120
121
122
      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);
dfa91a3bc   pyb   libad9915 : add i...
123
124
125
126
  }
  
  void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord)
  {
41fb442f6   bachi   ad9915.c et ad991...
127
128
     writeRegister(fd,0x0c, phaseAmpWord>>24&0xFF, phaseAmpWord>>16&0xFF,phaseAmpWord>>8&0xFF,phaseAmpWord&0xFF); // amp (12b) ph(16)
     sendIOUpdate(f_dds);
dfa91a3bc   pyb   libad9915 : add i...
129
130
  }
  
09ecc607d   bachi   mise a jour avec ...
131
132
133
134
135
  void checkSize(void)
  {	
  		printf("int : %d
  ",sizeof(unsigned int));
  }
dfa91a3bc   pyb   libad9915 : add i...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
  
  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   bachi   ad9915.c et ad991...
189
  void sendCtrlUp(int fp)
09ecc607d   bachi   mise a jour avec ...
190
  {
e41d5220b   bachi   ad9915.c : nettoy...
191
192
  		//pente positive
  		write(fp,"0",1); 
09ecc607d   bachi   mise a jour avec ...
193
194
  }
  
41fb442f6   bachi   ad9915.c et ad991...
195
  void sendCtrlDown(int fp)
09ecc607d   bachi   mise a jour avec ...
196
  {
e41d5220b   bachi   ad9915.c : nettoy...
197
198
  		//pente negative
  		write(fp,"2",1);
09ecc607d   bachi   mise a jour avec ...
199
200
  }
  
41fb442f6   bachi   ad9915.c et ad991...
201
  void sendHold(int fp)
09ecc607d   bachi   mise a jour avec ...
202
  {
e41d5220b   bachi   ad9915.c : nettoy...
203
204
  		//rampe bloquee
  		write(fp,"1",1); 
09ecc607d   bachi   mise a jour avec ...
205
206
  }
  
41fb442f6   bachi   ad9915.c et ad991...
207
  void sendUnhold(int fp)
09ecc607d   bachi   mise a jour avec ...
208
  {
e41d5220b   bachi   ad9915.c : nettoy...
209
210
  		//rampe debloquee
  		write(fp,"3",1); //reset
09ecc607d   bachi   mise a jour avec ...
211
212
213
214
215
216
217
218
  }
  
  
  int testRampFreq(int fd, int f_dds, int fp)
  {
  
  
  	//3-Rampe de pente positive + debloquage
41fb442f6   bachi   ad9915.c et ad991...
219
220
  	sendCtrlDown(fp);//rampe up
  	sendUnhold(fp);
09ecc607d   bachi   mise a jour avec ...
221
  
41fb442f6   bachi   ad9915.c et ad991...
222
  	sendReset(f_dds);
09ecc607d   bachi   mise a jour avec ...
223
224
225
  	//Initialize_DDS (fd, f_dds);
  
  	//0- paramètre de bases
41fb442f6   bachi   ad9915.c et ad991...
226
227
228
  	writeRegister(fd,0x00,0x00,0x01,0x01,0x0a);//OSKenable+Read&write
  	sendIOUpdate(f_dds);
  	readRegisterIni(fd,0x00);
09ecc607d   bachi   mise a jour avec ...
229
  
41fb442f6   bachi   ad9915.c et ad991...
230
231
232
  	writeRegister(fd,0x01,0x00, 0x00, 0x09, 0x00); // enable amp ramp
  	sendIOUpdate(f_dds);
  	readRegisterIni(fd,0x00);
09ecc607d   bachi   mise a jour avec ...
233
  
09ecc607d   bachi   mise a jour avec ...
234
  
41fb442f6   bachi   ad9915.c et ad991...
235
236
237
238
  	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   bachi   mise a jour avec ...
239
240
241
242
243
  
  	printf("Les mots de frequences, d'amplitudes et de phases sont envoyes
  ");
  	printf("Lecture registre de frequence: 0x0b
  ");
41fb442f6   bachi   ad9915.c et ad991...
244
  	readRegisterIni(fd,0x0b);
09ecc607d   bachi   mise a jour avec ...
245
246
  	printf("Lecture registre de amp et phase: 0x0c
  ");
41fb442f6   bachi   ad9915.c et ad991...
247
  	readRegisterIni(fd,0x0c);
09ecc607d   bachi   mise a jour avec ...
248
  
e41d5220b   bachi   ad9915.c : nettoy...
249
  	calibrateDAC (fd,f_dds);
09ecc607d   bachi   mise a jour avec ...
250
251
252
253
254
255
256
  	printf("
  
   ----------------------- 
  
  ");
  
  
09ecc607d   bachi   mise a jour avec ...
257
258
259
260
261
  	return EXIT_SUCCESS;
  }
  
  //---------------rajout 8/1
  
41fb442f6   bachi   ad9915.c et ad991...
262
  int putAmpWord(int fd, int f_dds, double amplitude)
09ecc607d   bachi   mise a jour avec ...
263
264
265
266
267
268
269
  {
          uint16_t PhaseWord = 0x0000;
          uint16_t AmpWord = 0x0000;
          uint32_t ReadPhaseAmpWord=0x00000000;
  
          AmpWord = rint(amplitude*(pow(2.0,12.0)-1)/100);
  
41fb442f6   bachi   ad9915.c et ad991...
270
          readRegister(fd,0x0c,&ReadPhaseAmpWord);
09ecc607d   bachi   mise a jour avec ...
271
272
273
  
          PhaseWord = ReadPhaseAmpWord&0xFFFF;
  
41fb442f6   bachi   ad9915.c et ad991...
274
275
          writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF);
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
276
277
278
279
280
  
          return 0;
  }
  
  
41fb442f6   bachi   ad9915.c et ad991...
281
  int putPhaseWord(int fd, int f_dds, double phase)
09ecc607d   bachi   mise a jour avec ...
282
  {
e41d5220b   bachi   ad9915.c : nettoy...
283
284
          //uint16_t PhaseWord = 0x0000;
          //uint16_t AmpWord = 0x0000;
09ecc607d   bachi   mise a jour avec ...
285
286
          uint32_t ReadPhaseAmpWord=0x00000000;
  
e41d5220b   bachi   ad9915.c : nettoy...
287
          uint16_t PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360);
09ecc607d   bachi   mise a jour avec ...
288
  
41fb442f6   bachi   ad9915.c et ad991...
289
          readRegister(fd,0x0c,&ReadPhaseAmpWord);
09ecc607d   bachi   mise a jour avec ...
290
  
e41d5220b   bachi   ad9915.c : nettoy...
291
          uint16_t AmpWord = ReadPhaseAmpWord>>16&0xFFFF;
09ecc607d   bachi   mise a jour avec ...
292
  
41fb442f6   bachi   ad9915.c et ad991...
293
294
          writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF);
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
295
296
297
298
  
          return 0;
  }
  
41fb442f6   bachi   ad9915.c et ad991...
299
  int putFrequencyWord(int fd, int f_dds, double fclk,double fout)//Attention uniquement valable pour fclk = 1 GHz
09ecc607d   bachi   mise a jour avec ...
300
301
  {
  
e41d5220b   bachi   ad9915.c : nettoy...
302
303
          //uint32_t FTWR = 0x00000000;
          uint32_t FTWR = rint((fout/fclk)*pow(2.0,32.0));
41fb442f6   bachi   ad9915.c et ad991...
304
305
          writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
306
307
308
309
310
  
          return 0;
  }
  
  
41fb442f6   bachi   ad9915.c et ad991...
311
  int putFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase)//n'existe pas dans le mode profile enable
09ecc607d   bachi   mise a jour avec ...
312
313
  {
  
e41d5220b   bachi   ad9915.c : nettoy...
314
          //uint32_t FTWR = 0x00000000;
09ecc607d   bachi   mise a jour avec ...
315
  
e41d5220b   bachi   ad9915.c : nettoy...
316
          uint32_t FTWR = rint((fout/fclk)*pow(2.0,32.0));
09ecc607d   bachi   mise a jour avec ...
317
  
41fb442f6   bachi   ad9915.c et ad991...
318
          writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence
09ecc607d   bachi   mise a jour avec ...
319
  
41fb442f6   bachi   ad9915.c et ad991...
320
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
321
  
41fb442f6   bachi   ad9915.c et ad991...
322
323
          putPhaseWord(fd,f_dds,phase);
          putAmpWord(fd,f_dds,amp);
09ecc607d   bachi   mise a jour avec ...
324
325
326
327
328
  
          return 0;
  }
  
  
41fb442f6   bachi   ad9915.c et ad991...
329
  int initialisationProfileMode (int fd,int f_dds)
09ecc607d   bachi   mise a jour avec ...
330
331
  {
  
41fb442f6   bachi   ad9915.c et ad991...
332
333
334
335
336
337
338
339
340
341
342
          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   bachi   mise a jour avec ...
343
344
345
346
347
348
349
350
351
352
353
354
355
356
  
          return 0;
  }
  
  
  
  //------------------- FIN RAJOUT 8/1
  
  
  //-------------------------FONCTIONS RAMPES HARDWARE
  
  //1-rampe de frequence
  
  //rampe simple de fréquence
41fb442f6   bachi   ad9915.c et ad991...
357
  int frequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown)
09ecc607d   bachi   mise a jour avec ...
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
  {
          //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   bachi   ad9915.c et ad991...
427
428
          writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
429
430
  
          uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0));
41fb442f6   bachi   ad9915.c et ad991...
431
432
          writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
433
434
435
436
437
438
439
440
441
  
  	
  	//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   bachi   ad9915.c et ad991...
442
443
444
445
          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   bachi   mise a jour avec ...
446
447
448
449
450
451
452
453
454
455
  
  
  	//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   bachi   ad9915.c et ad991...
456
457
          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   bachi   mise a jour avec ...
458
459
460
  
          //5 Start of the ramp
  
41fb442f6   bachi   ad9915.c et ad991...
461
462
          writeRegister(fd,0x01,0x00,0x08,0x09,0x00); //rampe simple
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
463
464
465
466
467
468
469
470
471
472
          return 0;
  
  
  
          return EXIT_SUCCESS;
  
  }
  
  
  //rampe continue de fréquence
41fb442f6   bachi   ad9915.c et ad991...
473
  int continueFrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown)
09ecc607d   bachi   mise a jour avec ...
474
475
476
477
478
479
480
481
482
483
484
485
486
487
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
  {
          //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   bachi   ad9915.c et ad991...
543
544
          writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
545
546
  
          uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0));
41fb442f6   bachi   ad9915.c et ad991...
547
548
          writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
549
550
551
552
553
554
555
556
557
  
  	
  	//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   bachi   ad9915.c et ad991...
558
559
560
561
          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   bachi   mise a jour avec ...
562
563
564
565
566
567
568
569
570
571
  
  
  	//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   bachi   ad9915.c et ad991...
572
573
          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   bachi   mise a jour avec ...
574
575
576
  
          //5 Start of the ramp
  
41fb442f6   bachi   ad9915.c et ad991...
577
578
          writeRegister(fd,0x01,0x00,0x8e,0x29,0x00); //rampe triangulaire
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
579
580
581
582
583
584
585
586
587
588
          return 0;
  
  
  
          return EXIT_SUCCESS;
  
  }
  
  //2-rampe d'amplitude
  
41fb442f6   bachi   ad9915.c et ad991...
589
  int amplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown)
09ecc607d   bachi   mise a jour avec ...
590
591
592
593
594
595
596
597
598
599
600
601
602
603
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
  {
  
  
          //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);
09ecc607d   bachi   mise a jour avec ...
669
670
671
672
673
674
          }
  
          if(DeltaAmp<=enouthDOWN)
          {
                  printf("The amplitude difference should be > %d
  , decrease Number Points for negative slope",borneDown);
09ecc607d   bachi   mise a jour avec ...
675
676
677
678
679
680
681
682
683
684
          }
  
  
  	//4 - Put word in register
  
  
  	//4.1 Limit register
  	uint32_t WordAmin = rint(AMin*4095/100);
  	uint32_t WordAmax= rint(AMax*4095/100);
         
41fb442f6   bachi   ad9915.c et ad991...
685
686
687
688
  	 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   bachi   mise a jour avec ...
689
690
691
692
693
694
695
  
  
  	//4.2 dAUP et dADown
  
  	uint32_t Word_dA_up = rint(dAUp*4095/100);
          uint32_t Word_dA_down = rint(dADown*4095/100);
  
41fb442f6   bachi   ad9915.c et ad991...
696
697
698
699
          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   bachi   mise a jour avec ...
700
701
702
703
704
705
706
  
  
  	//4.3 dtUp et dtDown
  
          uint16_t Word_dt_up = rint(dtUp*fclk/24);
          uint16_t Word_dt_down = rint(dtDown*fclk/24);
  
41fb442f6   bachi   ad9915.c et ad991...
707
708
          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   bachi   mise a jour avec ...
709
710
711
  
          //5 Start of the ramp
  
41fb442f6   bachi   ad9915.c et ad991...
712
713
714
  	writeRegister(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante
  	//writeRegister(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
715
716
717
718
  
          return EXIT_SUCCESS;
  }
  
41fb442f6   bachi   ad9915.c et ad991...
719
  int continueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown)
09ecc607d   bachi   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   bachi   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   bachi   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   bachi   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   bachi   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   bachi   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   bachi   mise a jour avec ...
841
842
843
  
          //5 Start of the ramp
  
41fb442f6   bachi   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   bachi   mise a jour avec ...
847
848
849
850
851
852
853
  
          return EXIT_SUCCESS;
  }
  
  
  //3-rampe de ĥase
  
41fb442f6   bachi   ad9915.c et ad991...
854
  int phaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown)
09ecc607d   bachi   mise a jour avec ...
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
  {
  
  
          //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;
  	}
  
  
09ecc607d   bachi   mise a jour avec ...
927
928
929
930
931
932
933
934
935
936
937
  	//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   bachi   ad9915.c et ad991...
938
939
940
941
  	 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   bachi   mise a jour avec ...
942
943
944
945
  
  
  	//4.2 dphiUP et dphiDown
  
09ecc607d   bachi   mise a jour avec ...
946
947
948
949
950
951
952
953
  	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);
  
09ecc607d   bachi   mise a jour avec ...
954
  
41fb442f6   bachi   ad9915.c et ad991...
955
956
957
958
  	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   bachi   mise a jour avec ...
959
960
961
962
963
964
965
  
  
  	//4.3 dtUp et dtDown
  
          uint16_t Word_dt_up = rint(dtUp*fclk/24);
          uint16_t Word_dt_down = rint(dtDown*fclk/24);
  
41fb442f6   bachi   ad9915.c et ad991...
966
967
          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   bachi   mise a jour avec ...
968
969
970
  
          //5 Start of the ramp
  
41fb442f6   bachi   ad9915.c et ad991...
971
972
  	writeRegister(fd,0x01,0x00,0x18,0x09,0x00); //rampe simple montante
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
973
974
975
976
  
          return EXIT_SUCCESS;
  }
  
41fb442f6   bachi   ad9915.c et ad991...
977
  int continuePhaseSweep (int fd, int f_dds,double fclk,double dphiUp, double dphiDown, double PhiMax,double PhiMin, double DeltaTimeUp, double DeltaTimeDown)
09ecc607d   bachi   mise a jour avec ...
978
979
980
981
982
983
984
985
986
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
  {
  
  
          //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;
  	}
  
  
09ecc607d   bachi   mise a jour avec ...
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
  	//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   bachi   ad9915.c et ad991...
1064
1065
1066
1067
  	 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   bachi   mise a jour avec ...
1068
1069
1070
1071
  
  
  	//4.2 dphiUP et dphiDown
  
09ecc607d   bachi   mise a jour avec ...
1072
1073
1074
1075
1076
1077
1078
1079
  	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   bachi   ad9915.c et ad991...
1080
1081
1082
1083
  	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   bachi   mise a jour avec ...
1084
1085
1086
1087
1088
1089
1090
  
  
  	//4.3 dtUp et dtDown
  
          uint16_t Word_dt_up = rint(dtUp*fclk/24);
          uint16_t Word_dt_down = rint(dtDown*fclk/24);
  
41fb442f6   bachi   ad9915.c et ad991...
1091
1092
          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   bachi   mise a jour avec ...
1093
1094
1095
  
          //5 Start of the ramp
  
41fb442f6   bachi   ad9915.c et ad991...
1096
1097
  	writeRegister(fd,0x01,0x00,0x9E,0x29,0x00); //rampe simple montante
          sendIOUpdate(f_dds);
09ecc607d   bachi   mise a jour avec ...
1098
1099
1100
1101
1102
1103
1104
  
          return EXIT_SUCCESS;
  }
  
  
  //-------------------------FIN FONCTIONS RAMPES HARDWARES
  
09ecc607d   bachi   mise a jour avec ...
1105
1106
  
  
dfa91a3bc   pyb   libad9915 : add i...
1107
1108
1109
1110
1111
1112
  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;
  }