Mercurial > hg > fxanalyse
diff 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 |
line wrap: on
line diff
--- a/ad9956.c Mon Mar 31 17:03:43 2014 +0200 +++ b/ad9956.c Mon Apr 14 12:43:25 2014 +0200 @@ -26,7 +26,8 @@ int sock, n, r; char buffer[256]; struct sockaddr_in addr; - struct hostent* host; + struct hostent* host; + uint64 value; #ifdef _CVI_ WSADATA wsdata; @@ -67,6 +68,22 @@ if (atoi(buffer) != REVISION) return -EINVAL; + /* disable clock divider */ + n = snprintf(buffer, sizeof(buffer), "GET CFR2"); + r = msend(d->fd, buffer, n); + if (r < 0) + return r; + r = mrecv(d->fd, buffer, sizeof(buffer)); + if (r < 0) + return r; + r = strtouint64(buffer, &value); + if (r < 0) + return r; + value = value | (1ULL << 16); + r = command(d->fd, "SET CFR2 0x%X", value); + if (r < 0) + return r; + return 0; } @@ -116,36 +133,20 @@ int ad9956_set_sweep_rate(struct ad9956 *d, double rate) { - int r; - uint64 value = ftw(d->clock, rate); - - r = command(d->fd, "SWEEP SET DFTW %lld", d->profile, value); - if (r < 0) - return r; - - return 0; + int64 value = (int64)ftw(d->clock, fabs(rate * 0.01)); + if (rate < 0.0) + value = -value; + return command(d->fd, "SWEEP SET DFTW %lld", value); } int ad9956_sweep_start(struct ad9956 *d) { - int r; - - r = command(d->fd, "SWEEP START"); - if (r < 0) - return r; - - return 0; + return command(d->fd, "SWEEP START"); } int ad9956_sweep_stop(struct ad9956 *d) { - int r; - - r = command(d->fd, "SWEEP STOP"); - if (r < 0) - return r; - - return 0; + return command(d->fd, "SWEEP STOP"); }