changeset 257:8cbfce046d41

Try to read back the frequency values from AD9912 at startup Reset the AD9912 frequencies to the default value only as a fallback.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 05 Jun 2015 21:51:25 +0200
parents 708de02ef948
children 5296f3bcd160
files FXAnalyse.c
diffstat 1 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/FXAnalyse.c	Fri Jun 05 21:00:54 2015 +0200
+++ b/FXAnalyse.c	Fri Jun 05 21:51:25 2015 +0200
@@ -719,12 +719,11 @@
 
 int main (int argc, char *argv[])
 {
-	int rv;
-	int nchan;
-	double frequency;
+	int i, rv, nchan;
+	double frequency, clock;
 	char expr[1024];
 	char host[256];
-	double clock;
+	int PANEL_DDS[4] = { PANEL_DDS1, PANEL_DDS2, PANEL_DDS3, PANEL_DDS4 };
 
 	if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0)
 		return -1;
@@ -786,14 +785,16 @@
 	if (rv)
 		logmessage(ERROR, "ad9912 init erorr=%d", -rv);
 	
-	GetCtrlVal(MainPanel, PANEL_DDS1, &frequency);
-	ad9912_set_frequency_w(&ad9912, 0, frequency);
-	GetCtrlVal(MainPanel, PANEL_DDS2, &frequency);
-	ad9912_set_frequency_w(&ad9912, 1, frequency);
-	GetCtrlVal(MainPanel, PANEL_DDS3, &frequency);
-	ad9912_set_frequency_w(&ad9912, 2, frequency);
-	GetCtrlVal(MainPanel, PANEL_DDS4, &frequency);
-	ad9912_set_frequency_w(&ad9912, 3, frequency);
+	// try to read back current frequency from DDS
+	for (i = 0; i < 4; i++) {
+		rv = ad9912_get_frequency(&ad9912, i, &frequency);
+		if ((rv) || (frequency == 0.0)) {
+			logmessage(WARNING, "reset DDS%d frequency to default value", i + 1);
+			GetCtrlVal(MainPanel, PANEL_DDS[i], &frequency);
+			ad9912_set_frequency_w(&ad9912, i, frequency);
+		}
+		SetCtrlVal(MainPanel, PANEL_DDS[i], frequency);
+	}
 
 	// setup ZMQ pub socket
 	char *socket;