Mercurial > hg > fxanalyse
comparison ad9956.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 | c700a2d38fb8 |
children | 5296f3bcd160 |
comparison
equal
deleted
inserted
replaced
212:3d63702b33c1 | 213:fcc988c6f841 |
---|---|
24 int ad9956_init(struct ad9956 *d, const char *hostname, double clock) | 24 int ad9956_init(struct ad9956 *d, const char *hostname, double clock) |
25 { | 25 { |
26 int sock, n, r; | 26 int sock, n, r; |
27 char buffer[256]; | 27 char buffer[256]; |
28 struct sockaddr_in addr; | 28 struct sockaddr_in addr; |
29 struct hostent* host; | 29 struct hostent* host; |
30 uint64 value; | |
30 | 31 |
31 #ifdef _CVI_ | 32 #ifdef _CVI_ |
32 WSADATA wsdata; | 33 WSADATA wsdata; |
33 WSAStartup(MAKEWORD(2,2), &wsdata); | 34 WSAStartup(MAKEWORD(2,2), &wsdata); |
34 #endif | 35 #endif |
64 r = mrecv(d->fd, buffer, sizeof(buffer)); | 65 r = mrecv(d->fd, buffer, sizeof(buffer)); |
65 if (r < 0) | 66 if (r < 0) |
66 return r; | 67 return r; |
67 if (atoi(buffer) != REVISION) | 68 if (atoi(buffer) != REVISION) |
68 return -EINVAL; | 69 return -EINVAL; |
70 | |
71 /* disable clock divider */ | |
72 n = snprintf(buffer, sizeof(buffer), "GET CFR2"); | |
73 r = msend(d->fd, buffer, n); | |
74 if (r < 0) | |
75 return r; | |
76 r = mrecv(d->fd, buffer, sizeof(buffer)); | |
77 if (r < 0) | |
78 return r; | |
79 r = strtouint64(buffer, &value); | |
80 if (r < 0) | |
81 return r; | |
82 value = value | (1ULL << 16); | |
83 r = command(d->fd, "SET CFR2 0x%X", value); | |
84 if (r < 0) | |
85 return r; | |
69 | 86 |
70 return 0; | 87 return 0; |
71 } | 88 } |
72 | 89 |
73 | 90 |
114 } | 131 } |
115 | 132 |
116 | 133 |
117 int ad9956_set_sweep_rate(struct ad9956 *d, double rate) | 134 int ad9956_set_sweep_rate(struct ad9956 *d, double rate) |
118 { | 135 { |
119 int r; | 136 int64 value = (int64)ftw(d->clock, fabs(rate * 0.01)); |
120 uint64 value = ftw(d->clock, rate); | 137 if (rate < 0.0) |
121 | 138 value = -value; |
122 r = command(d->fd, "SWEEP SET DFTW %lld", d->profile, value); | 139 return command(d->fd, "SWEEP SET DFTW %lld", value); |
123 if (r < 0) | |
124 return r; | |
125 | |
126 return 0; | |
127 } | 140 } |
128 | 141 |
129 | 142 |
130 int ad9956_sweep_start(struct ad9956 *d) | 143 int ad9956_sweep_start(struct ad9956 *d) |
131 { | 144 { |
132 int r; | 145 return command(d->fd, "SWEEP START"); |
133 | |
134 r = command(d->fd, "SWEEP START"); | |
135 if (r < 0) | |
136 return r; | |
137 | |
138 return 0; | |
139 } | 146 } |
140 | 147 |
141 | 148 |
142 int ad9956_sweep_stop(struct ad9956 *d) | 149 int ad9956_sweep_stop(struct ad9956 *d) |
143 { | 150 { |
144 int r; | 151 return command(d->fd, "SWEEP STOP"); |
145 | |
146 r = command(d->fd, "SWEEP STOP"); | |
147 if (r < 0) | |
148 return r; | |
149 | |
150 return 0; | |
151 } | 152 } |