annotate DDS4xAD9912.c @ 183:791ca26fee6a

Rewrite data writing to file Fmt() uses by default truncation to conver double arguments to their text representation. Rounding must be used. Rewrite using standard C functions to get rid of this problem (and probably make it more efficient). Extend to handle arbitrary number of channels and to report errors on opening the data files.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 21 Feb 2014 18:42:30 +0100
parents d96f0b04f7fe
children 0e0282010be3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
1 #include <toolbox.h>
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
2 #include <ansi_c.h>
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3 #include <utility.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4 #include <userint.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5 #include <tcpsupp.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
6
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
7 #include "DDS4xAD9912.h"
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
8
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
10 void DDS4xAD9912_Init(DDS4xAD9912_Data *dds, const char *host, double clock)
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
11 {
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
12 memset(dds, 0, sizeof(DDS4xAD9912_Data));
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
13 dds->port[0] = 6665;
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
14 dds->port[1] = 6666;
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
15 dds->port[2] = 6667;
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
16 dds->port[3] = 6668;
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
17 dds->host = StrDup(host);
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
18 dds->clock = clock;
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
19 }
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
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 // DDS4xAD9912_SendCmd
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24 //
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25 // 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
26 // PARAM : DDSNum contient le numero de la DDS (1,2,3 ou 4)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
27 // PARAM : Buffer contenant la chaîne de caractères à envoyer
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
28 // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
29 //==============================================================================
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
30 static int DDS4xAD9912_SendCmd(DDS4xAD9912_Data *dds, int channel, char *buffer)
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
31 {
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
32 int rv;
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
33 unsigned int sock;
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
34
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
35 rv = ConnectToTCPServer(&sock, dds->port[channel - 1], dds->host, NULL, 0, 0);
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
36 if (rv < 0)
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
37 return rv;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
38
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
39 rv = ClientTCPWrite(sock, buffer, strlen(buffer) + 1, 0);
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
40
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
41 DisconnectFromTCPServer(sock);
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
42
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
43 return rv;
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
44 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
45
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
46
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
47 //==============================================================================
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
48 // DDS4xAD9912_Reset
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
49 //
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
50 // FUNC : reset des 4 DDS
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
51 // PARAM :
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
52 // 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
53 //==============================================================================
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
54 int DDS4xAD9912_Reset(DDS4xAD9912_Data *dds)
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
55 {
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
56 int channel, rv;
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
57 char request[256];
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
58
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
59 sprintf(request, "set;%i;%i", 1, 17);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
60
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
61 for (channel = 1; channel < 5; channel++) {
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
62 rv = DDS4xAD9912_SendCmd(dds, channel, request);
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
63 if (rv < 0) {
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
64 MessagePopup("DDS4xAD9912", "Reset failed");
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
65 return -1;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
66 }
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
67 dds->frequency[channel - 1] = 0.0;
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
68 }
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
69 return 0;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
70 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
71
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
72
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
73 /* convert 64 bit integer into 6 bytes array */
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
74 static inline void tobytes(unsigned long long x, unsigned char* bytes)
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
75 {
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
76 /* 64 bits integer */
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
77 for (int i = 0; i < 6; i++)
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
78 bytes[i] = (unsigned char)((x >> (i * 8)) & 0xFF);
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
79 }
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
80
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
81
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
82 #define WORD(freq, clock) ((double)(1ULL << 48) * (freq / clock))
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
83
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
84
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
85 //==============================================================================
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
86 // DDS4xAD9912_SetFreq
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
87 //
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
88 // FUNC : sort une fréquence sur la DDS1 ,DDS2, DDS3 ou DDS4
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
89 // PARAM : DDSNum contient le numero de la DDS (1, 2 , 3 ou 4)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
90 // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
91 //==============================================================================
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
92 int DDS4xAD9912_SetFrequency(DDS4xAD9912_Data *dds, int channel, double frequency)
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
93 {
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
94 int rv;
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
95 char request[256];
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
96 unsigned char b[6];
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
97 unsigned long long ftw = WORD(frequency, dds->clock);
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
98
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
99 tobytes(ftw, b);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
100
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
101 sprintf(request, "set;%i;%i;%i;%i;%i;%i;%i;%i", 0, 10, b[5], b[4], b[3], b[2], b[1], b[0]);
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
102 rv = DDS4xAD9912_SendCmd(dds, channel, request);
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
103 if (rv < 0) {
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
104 MessagePopup("DDS", "SetFrequency function failed");
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
105 return -1;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
106 }
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
107
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
108 sprintf(request, "set;%i;%i", 0, 18);
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
109 rv = DDS4xAD9912_SendCmd(dds, channel, request) ;
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
110 if (rv < 0) {
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
111 MessagePopup("DDS", "IOUpdate function failed");
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
112 return -1;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
113 }
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
114
174
d96f0b04f7fe Make DDS addres configurable in configuration file. Modernize AD9912 driver.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 142
diff changeset
115 dds->frequency[channel - 1] = (double)ftw * dds->clock / (double)(1ULL << 48);
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
116 return 0;
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
117 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
118
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
119
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
120 /*
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
121 * 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
122 * 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
123 */
118
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
124 int DDS4xAD9912_RampFrequency2(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep)
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
125 {
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
126 const double delay = 0.01;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
127
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
128 /* f2 > f1 */
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
129 while ((f2 - f1) > fstep) {
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
130 f1 += fstep;
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
131 DDS4xAD9912_SetFrequency(dds, channel, f1);
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
132 Delay(delay);
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
133 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
134
108
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
135 /* f2 < f1 */
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
136 while ((f1 - f2) > fstep) {
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
137 f1 -= fstep;
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
138 DDS4xAD9912_SetFrequency(dds, channel, f1);
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
139 Delay(delay);
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
140 }
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
141
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
142 /* final adjustment */
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
143 DDS4xAD9912_SetFrequency(dds, channel, f2);
54e7b129ecc2 Minimal cleanup of AD9912 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
144 return 0;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
145 }
118
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
146
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
147
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
148 /*
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
149 * 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
150 * 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
151 */
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
152 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
153 {
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
154 double f1 = DDS4xAD9912_GetFrequency(dds, channel);
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
155 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
156 }
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
157
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
158
43b35f4aae78 Fix N3 measurement. Simply frequnecy ramping functions.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 112
diff changeset
159 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
160 {
142
fd085d61e4ca Rework data logging
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 118
diff changeset
161 return dds->frequency[channel - 1];
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