Mercurial > hg > fxanalyse
annotate ad9912.c @ 213:fcc988c6f841
Fix ad9956 sweep rate setting. Disable clock divider on init. Simplify
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 14 Apr 2014 12:43:25 +0200 |
parents | 9e0c3541104b |
children | 5296f3bcd160 |
rev | line source |
---|---|
196
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
1 #ifdef _CVI_ |
207
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
2 #include <winsock2.h> |
196
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
3 #include <ansi_c.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
4 #include <toolbox.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
5 #else |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
6 #include <stdio.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
7 #include <stdlib.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
8 #include <unistd.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
9 #include <errno.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
10 #include <string.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
11 #include <sys/types.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
12 #include <sys/socket.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
13 #include <netinet/in.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
14 #include <arpa/inet.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
15 #include <netdb.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
16 #include <ctype.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
17 #include <stdarg.h> |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
18 #endif |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
19 |
207
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
20 #include "dds.h" |
196
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
21 #include "ad9912.h" |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
22 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
23 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
24 int ad9912_init(struct ad9912 *d, const char *hostname, double clock) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
25 { |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
26 int n, r; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
27 char buffer[256]; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
28 int sock; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
29 struct sockaddr_in addr; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
30 struct hostent* host; |
207
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
31 |
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
32 #ifdef _CVI_ |
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
33 WSADATA wsdata; |
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
34 WSAStartup(MAKEWORD(2,2), &wsdata); |
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
35 #endif |
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
36 |
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
37 d->hostname = strdup(hostname); |
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
38 d->port = 1234; |
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
39 d->clock = clock; |
196
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
40 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
41 host = gethostbyname(hostname); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
42 if (host == NULL) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
43 return -1; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
44 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
45 sock = socket(AF_INET, SOCK_STREAM, 0); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
46 if (sock < 0) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
47 return -2; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
48 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
49 addr.sin_family = host->h_addrtype; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
50 memcpy(&addr.sin_addr.s_addr, host->h_addr_list[0], host->h_length); |
207
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
51 addr.sin_port = htons(d->port); |
196
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
52 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
53 r = connect(sock, (struct sockaddr*)&addr, sizeof(addr)); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
54 if (r < 0) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
55 return -3; |
207
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
56 |
196
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
57 d->fd = sock; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
58 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
59 /* check compatibility */ |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
60 n = snprintf(buffer, sizeof(buffer), "REVISION"); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
61 r = msend(d->fd, buffer, n); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
62 if (r < 0) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
63 return r; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
64 r = mrecv(d->fd, buffer, sizeof(buffer)); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
65 if (r < 0) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
66 return r; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
67 if (atoi(buffer) != REVISION) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
68 return -1; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
69 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
70 return 0; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
71 } |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
72 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
73 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
74 int ad9912_set_frequency(struct ad9912 *d, unsigned channel, double f) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
75 { |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
76 int r; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
77 uint64 value = ftw(d->clock, f); |
207
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
78 |
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
79 /* ad9912 ignores ftw last bit */ |
9e0c3541104b
Move common AD99xx code to dds.{ch}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
201
diff
changeset
|
80 value = value & ~1ULL; |
196
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
81 |
201
f8118b90490e
Fix new AD9912 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
196
diff
changeset
|
82 r = command(d->fd, "SET CH%d:FTW0 0x%llX", channel, value); |
196
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
83 if (r < 0) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
84 return r; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
85 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
86 d->frequency[channel] = freq(d->clock, value); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
87 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
88 return 0; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
89 } |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
90 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
91 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
92 int ad9912_get_frequency(struct ad9912 *d, unsigned channel, double *f) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
93 { |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
94 int r, n; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
95 uint64 value; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
96 char buffer[256]; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
97 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
98 n = snprintf(buffer, sizeof(buffer), "GET CH%d:FTW0", channel); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
99 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
100 r = msend(d->fd, buffer, n); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
101 if (r < 0) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
102 return r; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
103 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
104 r = mrecv(d->fd, buffer, sizeof(buffer)); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
105 if (r < 0) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
106 return r; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
107 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
108 r = strtouint64(buffer, &value); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
109 if (r < 0) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
110 return r; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
111 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
112 d->frequency[channel] = freq(d->clock, value); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
113 if (f) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
114 *f = d->frequency[channel]; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
115 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
116 return 0; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
117 } |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
118 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
119 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
120 /** |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
121 * Ramp DDS frequency from @f1 to @f2 in steps @fstep with 0.01 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
122 * seconds delay after each step. |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
123 */ |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
124 int ad9912_ramp_frequency2(struct ad9912 *d, unsigned channel, double f1, double f2, double fstep) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
125 { |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
126 const int delay = 10000; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
127 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
128 /* f2 > f1 */ |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
129 while ((f2 - f1) > fstep) { |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
130 f1 += fstep; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
131 ad9912_set_frequency(d, channel, f1); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
132 usleep(delay); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
133 } |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
134 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
135 /* f2 < f1 */ |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
136 while ((f1 - f2) > fstep) { |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
137 f1 -= fstep; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
138 ad9912_set_frequency(d, channel, f1); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
139 usleep(delay); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
140 } |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
141 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
142 /* final adjustment */ |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
143 ad9912_set_frequency(d, channel, f2); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
144 return 0; |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
145 } |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
146 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
147 |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
148 int ad9912_ramp_frequency(struct ad9912 *d, unsigned channel, double f, double fstep) |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
149 { |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
150 return ad9912_ramp_frequency2(d, channel, d->frequency[channel], f, fstep); |
87dae6d62a61
New AD9912 client code to communicate with improved server code
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
151 } |