changeset 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 3d63702b33c1
children 920ff733b43b
files ad9956.c dds.c dds.h
diffstat 3 files changed, 28 insertions(+), 33 deletions(-) [+]
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");
 }
--- 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 <stdarg.h>
 #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;
--- 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)