annotate DDS4xAD9912.c @ 164:211ea3950310

Read AD9956 configuration from configuration file
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 10 Feb 2014 15:19:34 +0100
parents fd085d61e4ca
children d96f0b04f7fe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
1 #include <ansi_c.h>
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2 #include <utility.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3 #include <userint.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4 #include <tcpsupp.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
6 #include "DDS4xAD9912.h"
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
7
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
8
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9 static int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData)
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
10 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
11 switch(xType)
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
12 {
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
13 case TCP_DISCONNECT:
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14 break;
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
15 case TCP_DATAREADY:
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
16 ClientTCPRead(handle, Response, sizeof(Response), 0);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
17 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
18 }
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
19 return 0;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
20 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
21
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
22
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
23 //==============================================================================
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24 // DDS4xAD9912_SendCmd
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25 //
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
26 // FUNC : envoie une chaine de caracteres sur un port du serveur TCP/IP de la foxboard
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
27 // PARAM : DDSNum contient le numero de la DDS (1,2,3 ou 4)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
28 // PARAM : Buffer contenant la chaîne de caractères à envoyer
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
29 // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
30 //==============================================================================
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
31 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
32 {
112
e501896c0e7c Avoid compilation warning
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 108
diff changeset
33 int port = 0;
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
34 int rv;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
35
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
36 switch (DDSNum) {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
37 case 1:
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
38 port = Port1;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
39 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
40 case 2:
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
41 port = Port2;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
42 break;
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
43 case 3:
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
44 port = Port3;
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
45 break;
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
46 case 4:
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
47 port = Port4;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
48 break;
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
49 default:
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
50 return -1;
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
51 }
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
52
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
53 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
54 if (rv < 0) {
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
55 MessagePopup("DDS4xAD9912", "Connection to server failed!");
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
56 return rv;
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
57 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
58
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
59 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
60 if (rv < 0) {
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
61 MessagePopup("DDS Serveur", "Write to server failed!");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
62 }
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
63
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
64 DisconnectFromTCPServer(hConv);
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
65
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
66 return rv;
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
67 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
68
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
69
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
70 //==============================================================================
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
71 // DDS4xAD9912_Reset
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
72 //
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
73 // FUNC : reset des 4 DDS
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
74 // PARAM :
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
75 // RETURN : 0 si le reset de la DDS 1 , DDS 2, DDS3 et DDS4 est OK
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
76 //==============================================================================
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
77 int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance)
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
78 {
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
79 int chan, rv;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
80
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
81 for (chan = 1; chan < 5; chan++) {
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
82 sprintf(Request, "set;%i;%i", 1, 17);
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
83 rv = DDS4xAD9912_SendCmd(chan, Request);
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
84 if (rv < 0) {
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
85 MessagePopup("DDS Serveur", "DDS4xAD9912 reset failed");
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
86 return -1;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
87 }
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
88 Instance->frequency[chan - 1] = 0.0;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
89 }
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
90 return 0;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
91 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
92
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
93
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
94 //==============================================================================
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
95 // DDS4xAD9912_SetFreq
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
96 //
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
97 // FUNC : sort une fréquence sur la DDS1 ,DDS2, DDS3 ou DDS4
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
98 // PARAM : DDSNum contient le numero de la DDS (1, 2 , 3 ou 4)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
99 // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
100 //==============================================================================
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
101 int DDS4xAD9912_SetFrequency(DDS4xAD9912_Data * Instance, int DDSNum, double Freq)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
102 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
103
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
104 double Word=WORD(Freq,Clk) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
105 double reste ;
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
106 int rv;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
107 unsigned char b5,b4,b3,b2,b1,b0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
108
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
109 b5=(unsigned char)(Word/E40);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
110 b4=(unsigned char)((Word - E40*b5)/E32);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
111 b3=(unsigned char)((Word - E40*b5 - E32*b4)/E24);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
112 b2=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3)/E16);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
113 b1=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3 - E16*b2)/E8);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
114 b0=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3 - E16*b2 - E8*b1)/1.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
115 reste = (Word - E40*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1-1.0*b0) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
116
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
117 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",0,10,b5,b4,b3,b2,b1,b0);
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
118 rv = DDS4xAD9912_SendCmd(DDSNum, Request) ;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
119 if (rv < 0) {
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
120 MessagePopup("DDS Serveur", "SetFrequency function failed !");
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
121 return -1;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
122 }
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
123
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
124 sprintf(Request,"set;%i;%i",0,18);
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
125 rv = DDS4xAD9912_SendCmd(DDSNum, Request) ;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
126 if (rv < 0) {
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
127 MessagePopup("DDS Serveur", "IO_Update function failed !");
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
128 return -1;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
129 }
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
130
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
131 Instance->frequency[DDSNum - 1] = Freq - reste * Clk / E48;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
132 return 0;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
133 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
134
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
135
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
136 /*
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
137 * 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
138 * 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
139 */
118
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
140 int DDS4xAD9912_RampFrequency2(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep)
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
141 {
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
142 const double delay = 0.01;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
143
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
144 /* f2 > f1 */
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
145 while ((f2 - f1) > fstep) {
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
146 f1 += fstep;
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
147 DDS4xAD9912_SetFrequency(dds, channel, f1);
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
148 Delay(delay);
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
149 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
150
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
151 /* f2 < f1 */
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
152 while ((f1 - f2) > fstep) {
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
153 f1 -= fstep;
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
154 DDS4xAD9912_SetFrequency(dds, channel, f1);
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
155 Delay(delay);
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
156 }
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
157
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
158 /* final adjustment */
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
159 DDS4xAD9912_SetFrequency(dds, channel, f2);
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
160 return 0;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
161 }
118
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
162
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
163
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
164 /*
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
165 * 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
166 * 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
167 */
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
168 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
169 {
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
170 double f1 = DDS4xAD9912_GetFrequency(dds, channel);
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
171 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
172 }
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
173
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
174
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
175 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
176 {
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
177 return dds->frequency[channel - 1];
118
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
178 }
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
179