Mercurial > hg > fxanalyse
comparison DDS4xAD9912.c @ 108:54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 28 Jun 2013 14:45:12 +0200 |
parents | 0e9f95525a8f |
children | e501896c0e7c |
comparison
equal
deleted
inserted
replaced
107:6fd67aa13d10 | 108:54e7b129ecc2 |
---|---|
43 // PARAM : Buffer contenant la chaîne de caractères à envoyer | 43 // PARAM : Buffer contenant la chaîne de caractères à envoyer |
44 // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK | 44 // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK |
45 //============================================================================== | 45 //============================================================================== |
46 | 46 |
47 | 47 |
48 static int DDS4xAD9912_SendCmd(int DDSNum, char * Buffer) // essentially a private function | 48 static int DDS4xAD9912_SendCmd(int DDSNum, char * Buffer) |
49 { | 49 { |
50 int res_1,res_2; | 50 int port; |
51 | 51 int rv; |
52 switch(DDSNum) | 52 |
53 { | 53 switch (DDSNum) { |
54 case 1: | 54 case 1: |
55 res_1=ConnectToTCPServer (&hConv, Port1, Adress, OnTCPEvent, 0, 0); | 55 port = Port1; |
56 if(res_1 <0) MessagePopup("DDS4xAD9912_1 Serveur", "Connection to server failed !"); | |
57 break; | 56 break; |
58 case 2: | 57 case 2: |
59 res_1=ConnectToTCPServer (&hConv, Port2, Adress, OnTCPEvent, 0, 0); | 58 port = Port2; |
60 if(res_1 <0) MessagePopup("DDS4xAD9912_2 Serveur", "Connection to server failed !"); | 59 break; |
61 break; | 60 case 3: |
62 | 61 port = Port3; |
63 case 3: | 62 break; |
64 res_1=ConnectToTCPServer (&hConv, Port3, Adress, OnTCPEvent, 0, 0); | 63 case 4: |
65 if(res_1 <0) MessagePopup("DDS4xAD9912_3 Serveur", "Connection to server failed !"); | 64 port = Port4; |
66 break; | 65 break; |
67 | 66 default: |
68 case 4: | 67 return -1; |
69 res_1=ConnectToTCPServer (&hConv, Port4, Adress, OnTCPEvent, 0, 0); | 68 } |
70 if(res_1 <0) MessagePopup("DDS4xAD9912_4 Serveur", "Connection to server failed !"); | 69 |
71 break; | 70 rv = ConnectToTCPServer(&hConv, port, Adress, OnTCPEvent, 0, 0); |
72 | 71 if (rv < 0) { |
73 } | 72 MessagePopup("DDS4xAD9912", "Connection to server failed!"); |
74 | 73 return rv; |
75 res_2=ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0); | 74 } |
76 if(res_2 <0) MessagePopup("DDS Serveur", "Write to server failed !"); | 75 |
77 DisconnectFromTCPServer (hConv); | 76 rv = ClientTCPWrite(hConv, Buffer, strlen(Buffer)+1, 0); |
78 return (res_1+res_2) ; | 77 if (rv < 0) { |
79 } | 78 MessagePopup("DDS Serveur", "Write to server failed!"); |
79 } | |
80 | |
81 DisconnectFromTCPServer(hConv); | |
82 | |
83 return rv; | |
84 } | |
80 | 85 |
81 | 86 |
82 //============================================================================== | 87 //============================================================================== |
83 // DDS4xAD9912_Reset | 88 // DDS4xAD9912_Reset |
84 // | 89 // |
167 return(res_0) ; | 172 return(res_0) ; |
168 | 173 |
169 } | 174 } |
170 | 175 |
171 | 176 |
172 | 177 /* |
173 int DDS4xAD9912_FrequencyRampe ( DDS4xAD9912_Data * Instance, int DDSNum, double Frequin,double Frequout, double Step ) | 178 * ramp DDS frequency from `f1` to `f2` in steps of `fstep` |
179 * with a delay of 0.01 seoconds after each step | |
180 */ | |
181 int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep) | |
174 { | 182 { |
175 int i=0,imax=0; | 183 const double delay = 0.01; |
176 double Frequactu=0; | 184 |
177 double delaysecond=0.01; | 185 /* f2 > f1 */ |
178 | 186 while ((f2 - f1) > fstep) { |
179 | 187 f1 += fstep; |
180 if ( (Frequout - Frequin)>0) | 188 DDS4xAD9912_SetFrequency(dds, channel, f1); |
181 { | 189 Delay(delay); |
182 if ((Frequout-Frequin) > Step) | 190 } |
183 { | 191 |
184 imax= (Frequout-Frequin)/Step ; | 192 /* f2 < f1 */ |
185 for (i=0; i<imax;i++) | 193 while ((f1 - f2) > fstep) { |
186 { | 194 f1 -= fstep; |
187 Delay(delaysecond); | 195 DDS4xAD9912_SetFrequency(dds, channel, f1); |
188 Frequactu= Frequin+i*Step; | 196 Delay(delay); |
189 DDS4xAD9912_SetFrequency(Instance, DDSNum, Frequactu); | 197 } |
190 | 198 |
191 } | 199 /* final adjustment */ |
192 } | 200 DDS4xAD9912_SetFrequency(dds, channel, f2); |
193 } | 201 return 0; |
194 | |
195 else | |
196 { | |
197 if ((Frequin-Frequout) > Step) | |
198 { | |
199 imax= (Frequin-Frequout)/Step ; | |
200 for (i=0; i<imax;i++) | |
201 { | |
202 Delay(delaysecond); | |
203 Frequactu= Frequin-i*Step; | |
204 DDS4xAD9912_SetFrequency(Instance, DDSNum, Frequactu); | |
205 } | |
206 } | |
207 | |
208 } | |
209 | |
210 DDS4xAD9912_SetFrequency(Instance, DDSNum, Frequout); | |
211 return(0); | |
212 | |
213 } | 202 } |
214 | |
215 /*Word=WORD(Frequactu,Clk); | |
216 b5=(unsigned char)(Word/E48); | |
217 b4=(unsigned char)((Word - E48*b5)/E32); | |
218 b3=(unsigned char)((Word - E48*b5 -E32*b4)/E24); | |
219 b2=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3)/E16); | |
220 b1=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3 -E16*b2)/E8); | |
221 b0=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1)/1.0); | |
222 reste = (Word - E48*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1-1.0*b0) ; | |
223 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",0,10,b5,b4,b3,b2,b1,b0); | |
224 res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; | |
225 if (DDSNum==1) Instance->Frequency1 = Frequactu - reste*Clk/E48 ; | |
226 if (DDSNum==2) Instance->Frequency2 = Frequactu - reste*Clk/E48 ; | |
227 if (DDSNum==3) Instance->Frequency3 = Frequactu - reste*Clk/E48 ; | |
228 if (DDSNum==4) Instance->Frequency4 = Frequactu - reste*Clk/E48 ; | |
229 sprintf(Request,"set;%i;%i",0,18); | |
230 res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; */ | |
231 |