# HG changeset patch # User Daniele Nicolodi # Date 1397472205 -7200 # Node ID fcc988c6f8414c2ec348849b5396e57ef762a19c # Parent 3d63702b33c1c69ef99ef455a70c47d9e2cab74f Fix ad9956 sweep rate setting. Disable clock divider on init. Simplify diff -r 3d63702b33c1 -r fcc988c6f841 ad9956.c --- 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"); } diff -r 3d63702b33c1 -r fcc988c6f841 dds.c --- a/dds.c Mon Mar 31 17:03:43 2014 +0200 +++ b/dds.c Mon Apr 14 12:43:25 2014 +0200 @@ -17,20 +17,13 @@ #include #endif -#include "dds.h" int msend(int fd, char *buffer, int n) { - int r; - buffer[n++] = '\r'; buffer[n++] = '\n'; - r = send(fd, buffer, n, 0); - if (r < 0) - return r; - - return 0; + return send(fd, buffer, n, 0); } @@ -69,7 +62,7 @@ if (r < 0) return r; - if (! streq(buffer, "OK")) + if (strcmp(buffer, "OK") != 0) return -1; return 0; diff -r 3d63702b33c1 -r fcc988c6f841 dds.h --- a/dds.h Mon Mar 31 17:03:43 2014 +0200 +++ b/dds.h Mon Apr 14 12:43:25 2014 +0200 @@ -3,8 +3,9 @@ #define usleep(t) Delay((t) / 1000000.0) #define strdup(s) StrDup(s) -#define streq(x, y) (strcmp((x), (y)) == 0) + +typedef long long int64; typedef unsigned long long uint64; static inline uint64 ftw(double clock, double freq)