Mercurial > hg > fxanalyse
annotate DDS4xAD9912.c @ 118:43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Thu, 12 Sep 2013 15:49:27 +0200 |
parents | e501896c0e7c |
children | fd085d61e4ca |
rev | line source |
---|---|
0 | 1 #include <utility.h> |
2 | |
3 //============================================================================== | |
4 // | |
5 // Title: DDS4xAD9912.c | |
6 // Purpose: | |
7 // | |
8 // Created on: by Volodimer Laurent, modified by YLC | |
9 // Copyright: syrte. All Rights Reserved. | |
10 // | |
11 //============================================================================== | |
12 | |
13 //============================================================================== | |
14 // Include files | |
15 | |
16 #include "DDS4xAD9912.h" | |
17 #include <userint.h> | |
18 #include <tcpsupp.h> | |
19 #include <ansi_c.h> | |
20 | |
21 //============================================================================== | |
22 // Global functions | |
23 | |
24 static int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData) | |
25 { | |
26 switch(xType) | |
27 { | |
28 case TCP_DISCONNECT : | |
29 break; | |
30 case TCP_DATAREADY : | |
31 ClientTCPRead (handle, Response, sizeof(Response), 0); | |
32 break; | |
33 } | |
34 return 0; | |
35 } | |
36 | |
37 | |
38 //============================================================================== | |
39 // DDS4xAD9912_SendCmd | |
40 // | |
41 // FUNC : envoie une chaine de caracteres sur un port du serveur TCP/IP de la foxboard | |
42 // PARAM : DDSNum contient le numero de la DDS (1,2,3 ou 4) | |
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 | |
45 //============================================================================== | |
46 | |
47 | |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
48 static int DDS4xAD9912_SendCmd(int DDSNum, char * Buffer) |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
49 { |
112
e501896c0e7c
Avoid compilation warning
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
108
diff
changeset
|
50 int port = 0; |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
51 int rv; |
0 | 52 |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
53 switch (DDSNum) { |
0 | 54 case 1: |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
55 port = Port1; |
0 | 56 break; |
57 case 2: | |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
58 port = Port2; |
0 | 59 break; |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
60 case 3: |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
61 port = Port3; |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
62 break; |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
63 case 4: |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
64 port = Port4; |
0 | 65 break; |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
66 default: |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
67 return -1; |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
68 } |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
69 |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
70 rv = ConnectToTCPServer(&hConv, port, Adress, OnTCPEvent, 0, 0); |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
71 if (rv < 0) { |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
72 MessagePopup("DDS4xAD9912", "Connection to server failed!"); |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
73 return rv; |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
74 } |
0 | 75 |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
76 rv = ClientTCPWrite(hConv, Buffer, strlen(Buffer)+1, 0); |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
77 if (rv < 0) { |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
78 MessagePopup("DDS Serveur", "Write to server failed!"); |
0 | 79 } |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
80 |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
81 DisconnectFromTCPServer(hConv); |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
82 |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
83 return rv; |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
84 } |
0 | 85 |
86 | |
87 //============================================================================== | |
88 // DDS4xAD9912_Reset | |
89 // | |
90 // FUNC : reset des 4 DDS | |
91 // PARAM : | |
92 // RETURN : 0 si le reset de la DDS 1 , DDS 2, DDS3 et DDS4 est OK | |
93 //============================================================================== | |
94 | |
95 int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance) | |
96 { | |
97 int res_1,res_2; | |
98 | |
99 sprintf(Request,"set;%i;%i",1,17); | |
100 res_1 = DDS4xAD9912_SendCmd(1,Request) ; | |
101 if(res_1 <0) { | |
102 MessagePopup("DDS Serveur", "DDS4xAD9912_1 Reset failed !") ; | |
103 } | |
104 else Instance->Frequency1 = 0.0 ; | |
105 | |
106 sprintf(Request,"set;%i;%i",1,17); | |
107 res_2 = DDS4xAD9912_SendCmd(2,Request) ; | |
108 if(res_2 <0) { | |
109 MessagePopup("DDS Serveur", "DDS4xAD9912_2 Reset failed !") ; | |
110 } | |
111 else Instance->Frequency2 = 0.0; | |
112 | |
113 sprintf(Request,"set;%i;%i",1,17); | |
114 res_2 = DDS4xAD9912_SendCmd(3,Request) ; | |
115 if(res_2 <0) { | |
116 MessagePopup("DDS Serveur", "DDS4xAD9912_3 Reset failed !") ; | |
117 } | |
118 else Instance->Frequency3 = 0.0; | |
119 | |
120 sprintf(Request,"set;%i;%i",1,17); | |
121 res_2 = DDS4xAD9912_SendCmd(4,Request) ; | |
122 if(res_2 <0) { | |
123 MessagePopup("DDS Serveur", "DDS4xAD9912_4 Reset failed !") ; | |
124 } | |
125 else Instance->Frequency4 = 0.0; | |
126 | |
127 | |
128 return (res_1+res_2); | |
129 } | |
130 | |
131 | |
132 //============================================================================== | |
133 // DDS4xAD9912_SetFreq | |
134 // | |
135 // FUNC : sort une fréquence sur la DDS1 ,DDS2, DDS3 ou DDS4 | |
136 // PARAM : DDSNum contient le numero de la DDS (1, 2 , 3 ou 4) | |
137 // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK | |
138 //============================================================================== | |
139 int DDS4xAD9912_SetFrequency(DDS4xAD9912_Data * Instance, int DDSNum, double Freq) | |
140 { | |
141 | |
142 double Word=WORD(Freq,Clk) ; | |
143 double reste ; | |
144 int res_0 ; | |
145 unsigned char b5,b4,b3,b2,b1,b0 ; | |
146 | |
147 b5=(unsigned char)(Word/E40); | |
148 b4=(unsigned char)((Word - E40*b5)/E32); | |
149 b3=(unsigned char)((Word - E40*b5 - E32*b4)/E24); | |
150 b2=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3)/E16); | |
151 b1=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3 - E16*b2)/E8); | |
152 b0=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3 - E16*b2 - E8*b1)/1.0); | |
153 reste = (Word - E40*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1-1.0*b0) ; | |
154 | |
155 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",0,10,b5,b4,b3,b2,b1,b0); | |
156 res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; | |
157 if (res_0 <0) { | |
158 MessagePopup("DDS Serveur", "SetFrequency function failed !") ; | |
159 } | |
160 else { | |
161 if (DDSNum==1) Instance->Frequency1 = Freq - reste*Clk/E48 ; | |
162 if (DDSNum==2) Instance->Frequency2 = Freq - reste*Clk/E48 ; | |
163 if (DDSNum==3) Instance->Frequency3 = Freq - reste*Clk/E48 ; | |
164 if (DDSNum==4) Instance->Frequency4 = Freq - reste*Clk/E48 ; | |
165 } ; | |
166 | |
167 sprintf(Request,"set;%i;%i",0,18); // IO_Update logiciel | |
168 res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; | |
169 if (res_0 <0) { | |
170 MessagePopup("DDS Serveur", "IO_Update function failed !") ; | |
171 } | |
172 return(res_0) ; | |
173 | |
174 } | |
175 | |
176 | |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
177 /* |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
178 * ramp DDS frequency from `f1` to `f2` in steps of `fstep` |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
179 * with a delay of 0.01 seoconds after each step |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
180 */ |
118
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
181 int DDS4xAD9912_RampFrequency2(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep) |
0 | 182 { |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
183 const double delay = 0.01; |
0 | 184 |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
185 /* f2 > f1 */ |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
186 while ((f2 - f1) > fstep) { |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
187 f1 += fstep; |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
188 DDS4xAD9912_SetFrequency(dds, channel, f1); |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
189 Delay(delay); |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
190 } |
0 | 191 |
108
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
192 /* f2 < f1 */ |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
193 while ((f1 - f2) > fstep) { |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
194 f1 -= fstep; |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
195 DDS4xAD9912_SetFrequency(dds, channel, f1); |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
196 Delay(delay); |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
197 } |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
198 |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
199 /* final adjustment */ |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
200 DDS4xAD9912_SetFrequency(dds, channel, f2); |
54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
103
diff
changeset
|
201 return 0; |
0 | 202 } |
118
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
203 |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
204 |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
205 /* |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
206 * ramp DDS frequency from the current frequency to `f2` in steps |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
207 * of `fstep` with a delay of 0.01 seoconds after each step |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
208 */ |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
209 int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f2, double fstep) |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
210 { |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
211 double f1 = DDS4xAD9912_GetFrequency(dds, channel); |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
212 return DDS4xAD9912_RampFrequency2(dds, channel, f1, f2, fstep); |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
213 } |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
214 |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
215 |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
216 double DDS4xAD9912_GetFrequency(DDS4xAD9912_Data *dds, int channel) |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
217 { |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
218 switch (channel) { |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
219 case 1: |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
220 return dds->Frequency1; |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
221 case 2: |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
222 return dds->Frequency2; |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
223 case 3: |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
224 return dds->Frequency3; |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
225 case 4: |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
226 return dds->Frequency4; |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
227 default: |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
228 return 0.0; |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
229 } |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
230 } |
43b35f4aae78
Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
112
diff
changeset
|
231 |