Commit e41d5220b5a139824483e540c0dbaf6473260c43

Authored by bachi
1 parent 6ebbf4da4d
Exists in master

ad9915.c : nettoyage des commentaires et du superflu(initialisation a 0 etc

Showing 1 changed file with 23 additions and 266 deletions Side-by-side Diff

... ... @@ -9,17 +9,13 @@
9 9 //fonction reset
10 10 void sendReset(int f_dds)
11 11 {
12   - char reset='2';
13   - write(f_dds,&reset,sizeof(reset)); //reset
14   - sleep(0.1);
  12 + write(f_dds,"2",1);
15 13 }
16 14  
17 15 //fonction ioupdate
18 16 void sendIOUpdate(int f_dds)
19 17 {
20   - char update='1';
21   - write(f_dds,&update,sizeof(update)); //reset
22   - sleep(0.1);
  18 + write(f_dds,"1",1);
23 19 }
24 20  
25 21 //fonction write register
... ... @@ -93,7 +89,6 @@
93 89 void modulusSetup(int fd, int f_dds)
94 90 {
95 91 writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x0a); //OSK enable //0x08
96   - //writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable de base
97 92 sendIOUpdate (f_dds);
98 93 writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp
99 94 sendIOUpdate (f_dds);
100 95  
101 96  
102 97  
103 98  
104 99  
... ... @@ -105,36 +100,24 @@
105 100 sendIOUpdate (f_dds);
106 101 writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp
107 102 sendIOUpdate (f_dds);
108   - writeRegister(fd,0x04,0x19, 0x99, 0x99, 0x99); //ftw
  103 + writeRegister(fd,0x04,0x19, 0x99, 0x99, 0x99); //ftw
109 104 sendIOUpdate (f_dds);
110   - writeRegister(fd,0x05,0xC0, 0x00, 0x00, 0x00); //A
  105 + writeRegister(fd,0x05,0xC0, 0x00, 0x00, 0x00); //A
111 106 sendIOUpdate (f_dds);
112   - writeRegister(fd,0x06,0x00, 0x00, 0x00, 0x05); //B
  107 + writeRegister(fd,0x06,0x00, 0x00, 0x00, 0x05); //B
113 108 sendIOUpdate (f_dds);
114   - //writeRegister(fd,0x0c, 0x0F, 0xFF, 0x00, 0x00); // amp (12b) ph(16)
115   - 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)
  109 + 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)
116 110 sendIOUpdate (f_dds);
117 111 }
118 112  
119 113 void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B)
120 114 {
121   - //uint16_t phaseWord = 0x7400;
122   - //uint16_t ampWord = (uint16_t)strtol(argv[4],NULL,0) & 0x0FFF ; //masque en 2
123   - //uint16_t ampWord = 0x00000FFF;
124   - //uint32_t phaseAmpWord = phaseWord | ampWord<<16;
125   -
126   - //writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable
127   - //sendIOUpdate(f_dds);
128   - //writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp
129   - //sendIOUpdate(f_dds);
130 115 writeRegister(fd,0x04,ftw>>24&0xFF, ftw>>16&0xFF, ftw>>8&0xFF, ftw&0xFF); //ftw
131 116 sendIOUpdate(f_dds);
132 117 writeRegister(fd,0x05,A>>24&0xFF,A>>16&0xFF, A>>8&0xFF, A&0xFF); //A
133 118 sendIOUpdate(f_dds);
134 119 writeRegister(fd,0x06,B>>24&0xFF,B>>16&0xFF, B>>8&0xFF, B&0xFF); //B
135 120 sendIOUpdate(f_dds);
136   - // writeRegister(fd,0x0c, phaseAmpWord>>24&0xFF, phaseAmpWord>>16&0xFF,phaseAmpWord>>8&0xFF,phaseAmpWord&0xFF); // amp (12b) ph(16)
137   - //sendIOUpdate(f_dds);
138 121 }
139 122  
140 123 void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord)
... ... @@ -143,20 +126,6 @@
143 126 sendIOUpdate(f_dds);
144 127 }
145 128  
146   -/*
147   -void getAmpPhaseWord(int fd)
148   -{
149   - // unsigned char rx[5]={0};
150   - unsigned char* pt;
151   - readRegister(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 129 void checkSize(void)
161 130 {
162 131 printf("int : %d\n",sizeof(unsigned int));
163 132  
164 133  
165 134  
... ... @@ -207,30 +176,26 @@
207 176  
208 177 void sendCtrlUp(int fp)
209 178 {
210   - char DRCTLOn='0';//pente positive
211   - write(fp,&DRCTLOn,sizeof(DRCTLOn)); //
212   - sleep(0.1);
  179 + //pente positive
  180 + write(fp,"0",1);
213 181 }
214 182  
215 183 void sendCtrlDown(int fp)
216 184 {
217   - char DRCTLOn='2';//pente negative
218   - write(fp,&DRCTLOn,sizeof(DRCTLOn)); //reset
219   - sleep(0.1);
  185 + //pente negative
  186 + write(fp,"2",1);
220 187 }
221 188  
222 189 void sendHold(int fp)
223 190 {
224   - char DRHOLDOn ='1';//rampe bloquée
225   - write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset
226   - sleep(0.1);
  191 + //rampe bloquee
  192 + write(fp,"1",1);
227 193 }
228 194  
229 195 void sendUnhold(int fp)
230 196 {
231   - char DRHOLDOn ='3';//rampe debloquée
232   - write(fp,&DRHOLDOn,sizeof(DRHOLDOn)); //reset
233   - sleep(0.1);
  197 + //rampe debloquee
  198 + write(fp,"3",1); //reset
234 199 }
235 200  
236 201  
237 202  
... ... @@ -254,17 +219,7 @@
254 219 sendIOUpdate(f_dds);
255 220 readRegisterIni(fd,0x00);
256 221  
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 222  
262   -// 2d0e560
263   -
264   - //Calibrate_DAC (fd,f_dds);
265   -
266   -
267   -
268 223 writeRegister(fd,0x0b,0x02,0xd0,0xe5,0x60);//mot de frequence
269 224 sendIOUpdate(f_dds);
270 225 writeRegister(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle
271 226  
... ... @@ -276,71 +231,10 @@
276 231 printf("Lecture registre de amp et phase: 0x0c\n");
277 232 readRegisterIni(fd,0x0c);
278 233  
279   - Calibrate_DAC (fd,f_dds);
  234 + calibrateDAC (fd,f_dds);
280 235 printf("\n\n ----------------------- \n\n");
281 236  
282 237  
283   -/*
284   - //2- Taille des dt
285   -
286   - writeRegister(fd,0x08,0xFF,0xFF,0xFF,0xFF); //+dt max, -dt max (+dt = -dt)
287   - sendIOUpdate(f_dds);
288   -
289   - printf("Les mots de dt sont envoyes\n");
290   - printf("Lecture dans le registre 0x08 : taille dt\n");
291   - readRegisterIni (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   - writeRegister(fd,0x06,0x00,0x00,0x00,0x01);
303   - sendIOUpdate(f_dds);
304   -
305   - writeRegister(fd,0x07,0x00,0x00,0x00,0x01);
306   - sendIOUpdate(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   - readRegisterIni (fd,0x06);
312   - readRegisterIni (fd,0x07);
313   -
314   - printf("\n\n ----------------------- \n\n");
315   - //4- Ecrire les extremums de la rampe
316   -
317   - writeRegister(fd,0x04,0x00,0x00,0x00,0x01);//0 rad
318   - sendIOUpdate(f_dds);
319   - writeRegister(fd,0x05,0xFF,0xFF,0xFF,0xFF);//2*pi rad
320   - sendIOUpdate(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   - readRegisterIni (fd,0x04);
325   - readRegisterIni (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   - writeRegister(fd,0x01,0x00, 0xa8, 0x09, 0x00); // enable amp ramp
334   - sendIOUpdate(f_dds);
335   -
336   - printf("Lecture dans le registre 0x01 : \n");
337   - readRegisterIni (fd,0x01);
338   -// printf("Les mots de dt sont envoyes\n");
339   - printf("Lecture dans le registre 0x08 : taille dt\n");
340   - readRegisterIni (fd,0x08);
341   -
342   -
343   -*/
344 238 return EXIT_SUCCESS;
345 239 }
346 240  
347 241  
348 242  
... ... @@ -367,15 +261,15 @@
367 261  
368 262 int putPhaseWord(int fd, int f_dds, double phase)
369 263 {
370   - uint16_t PhaseWord = 0x0000;
371   - uint16_t AmpWord = 0x0000;
  264 + //uint16_t PhaseWord = 0x0000;
  265 + //uint16_t AmpWord = 0x0000;
372 266 uint32_t ReadPhaseAmpWord=0x00000000;
373 267  
374   - PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360);
  268 + uint16_t PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360);
375 269  
376 270 readRegister(fd,0x0c,&ReadPhaseAmpWord);
377 271  
378   - AmpWord = ReadPhaseAmpWord>>16&0xFFFF;
  272 + uint16_t AmpWord = ReadPhaseAmpWord>>16&0xFFFF;
379 273  
380 274 writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF);
381 275 sendIOUpdate(f_dds);
... ... @@ -386,8 +280,8 @@
386 280 int putFrequencyWord(int fd, int f_dds, double fclk,double fout)//Attention uniquement valable pour fclk = 1 GHz
387 281 {
388 282  
389   - uint32_t FTWR = 0x00000000;
390   - FTWR = rint((fout/fclk)*pow(2.0,32.0));
  283 + //uint32_t FTWR = 0x00000000;
  284 + uint32_t FTWR = rint((fout/fclk)*pow(2.0,32.0));
391 285 writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence
392 286 sendIOUpdate(f_dds);
393 287  
394 288  
395 289  
... ... @@ -398,17 +292,14 @@
398 292 int putFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase)//n'existe pas dans le mode profile enable
399 293 {
400 294  
401   - uint32_t FTWR = 0x00000000;
  295 + //uint32_t FTWR = 0x00000000;
402 296  
403   - FTWR = rint((fout/fclk)*pow(2.0,32.0));
  297 + uint32_t FTWR = rint((fout/fclk)*pow(2.0,32.0));
404 298  
405 299 writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence
406 300  
407 301 sendIOUpdate(f_dds);
408 302  
409   -// writeRegister(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle
410   -// sendIOUpdate(f_dds);
411   -
412 303 putPhaseWord(fd,f_dds,phase);
413 304 putAmpWord(fd,f_dds,amp);
414 305  
415 306  
... ... @@ -725,13 +616,11 @@
725 616 if(DeltaAmp<=enouthUP)
726 617 {
727 618 printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP);
728   - //return -1;
729 619 }
730 620  
731 621 if(DeltaAmp<=enouthDOWN)
732 622 {
733 623 printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown);
734   - //return -1;
735 624 }
736 625  
737 626  
... ... @@ -960,32 +849,6 @@
960 849 }
961 850  
962 851  
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 852 //4.1 Limit register
990 853 uint32_t WordPhimin = rint(PhiMin*65535/360);
991 854 uint32_t WordPhimax= rint(PhiMax*65535/360);
992 855  
993 856  
... ... @@ -1003,23 +866,13 @@
1003 866  
1004 867 //4.2 dphiUP et dphiDown
1005 868  
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 869 uint32_t Word_dphi_up = rint(dphiUp*(65535/360));
1009 870 uint32_t Word_dphi_down = rint(dphiDown*(65535/360));
1010 871  
1011 872 printf("Word_dphi_up = %.32x\n",Word_dphi_up);
1012 873 printf("Word_dphi_down = %.32x\n",Word_dphi_down);
1013 874  
1014   -/*
1015   - writeRegister(fd,0x06,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up>>0&0xFF,Word_dphi_up&0xFF); //dphi_up
1016   - sendIOUpdate(f_dds);
1017   - writeRegister(fd,0x07,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down>>0&0xFF,Word_dphi_down&0xFF);//dphi_down
1018   - sendIOUpdate(f_dds);
1019 875  
1020   -*/
1021   -
1022   -
1023 876 writeRegister(fd,0x06,Word_dphi_up>>24&0xFF,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up&0xFF); //dA_up
1024 877 sendIOUpdate(f_dds);
1025 878 writeRegister(fd,0x07,Word_dphi_down>>24&0xFF,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down&0xFF);//dA_down
... ... @@ -1103,29 +956,6 @@
1103 956 }
1104 957  
1105 958  
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 959 //4 - Put word in register
1130 960  
1131 961  
1132 962  
... ... @@ -1146,23 +976,12 @@
1146 976  
1147 977 //4.2 dphiUP et dphiDown
1148 978  
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 979 uint32_t Word_dphi_up = rint(dphiUp*(65535/360));
1152 980 uint32_t Word_dphi_down = rint(dphiDown*(65535/360));
1153 981  
1154 982 printf("Word_dphi_up = %.32x\n",Word_dphi_up);
1155 983 printf("Word_dphi_down = %.32x\n",Word_dphi_down);
1156 984  
1157   -/*
1158   - writeRegister(fd,0x06,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up>>0&0xFF,Word_dphi_up&0xFF); //dphi_up
1159   - sendIOUpdate(f_dds);
1160   - writeRegister(fd,0x07,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down>>0&0xFF,Word_dphi_down&0xFF);//dphi_down
1161   - sendIOUpdate(f_dds);
1162   -
1163   -*/
1164   -
1165   -
1166 985 writeRegister(fd,0x06,Word_dphi_up>>24&0xFF,Word_dphi_up>>16&0xFF,Word_dphi_up>>8&0xFF,Word_dphi_up&0xFF); //dA_up
1167 986 sendIOUpdate(f_dds);
1168 987 writeRegister(fd,0x07,Word_dphi_down>>24&0xFF,Word_dphi_down>>16&0xFF,Word_dphi_down>>8&0xFF,Word_dphi_down&0xFF);//dA_down
... ... @@ -1247,68 +1066,6 @@
1247 1066  
1248 1067  
1249 1068  
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   - readRegister(fd,0x0c,&ReadPhaseAmpWord);
1258   -
1259   - PhaseWord = ReadPhaseAmpWord&0xFFFF;
1260   -
1261   - writeRegister(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   - readRegister(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 1069  
1313 1070 return EXIT_SUCCESS;
1314 1071 }