Browse Source

Added three new functions to enable/disable clock output and save the current settings as default values to thr EEPROM. The firmware reads out those values on startup.

klaute 1 year ago
parent
commit
1e4e3d22d8
4 changed files with 192 additions and 7 deletions
  1. 80
    0
      firmware/command_ctrl.ino
  2. 93
    0
      firmware/firmware.ino
  3. 9
    0
      firmware/globals.h
  4. 10
    7
      tools/meas.py

+ 80
- 0
firmware/command_ctrl.ino View File

@@ -28,6 +28,9 @@ void cc_setFreqStep(void);
28 28
 void cc_setDriveStrength(void);
29 29
 void cc_startMeasurement(void);
30 30
 void cc_getConfig(void);
31
+void cc_enableClk(void);
32
+void cc_disableClk(void);
33
+void cc_saveDefaults(void);
31 34
 
32 35
 /*****************************************************************************/
33 36
 
@@ -45,6 +48,9 @@ uint8_t cc_commands[] = {
45 48
     CC_CMD_SET_FREQ_STEP,
46 49
     CC_CMD_START_MEASUREMENT,
47 50
     CC_CMD_GET_CONFIG,
51
+    CC_CMD_EN_CLK,
52
+    CC_CMD_DIS_CLK,
53
+    CC_CMD_SAV_DFLT,
48 54
   };
49 55
 
50 56
 void (*cc_cmd_functions[])() = {
@@ -55,6 +61,9 @@ void (*cc_cmd_functions[])() = {
55 61
     CC_CMD_SET_FREQ_STEP_FUNC,
56 62
     CC_CMD_START_MEASUREMENT_FUNC,
57 63
     CC_CMD_GET_CONFIG_FUNC,
64
+    CC_CMD_EN_CLK_FUNC,
65
+    CC_CMD_DIS_CLK_FUNC,
66
+    CC_CMD_SAV_DFLT_FUNC,
58 67
   };
59 68
 
60 69
 uint8_t cc_cmd_data_to_read[] = {
@@ -65,6 +74,9 @@ uint8_t cc_cmd_data_to_read[] = {
65 74
     CC_CMD_SET_FREQ_STEP_DATA_TO_READ,
66 75
     CC_CMD_START_MEASUREMENT_DATA_TO_READ,
67 76
     CC_CMD_GET_CONFIG_DATA_TO_READ,
77
+    CC_CMD_EN_CLK_DATA_TO_READ,
78
+    CC_CMD_DIS_CLK_DATA_TO_READ,
79
+    CC_CMD_SAV_DFLT_DATA_TO_READ,
68 80
   };
69 81
 
70 82
 uint8_t cc_read_data[CC_READ_DATA_MAX];
@@ -305,6 +317,74 @@ void cc_getConfig()
305 317
 
306 318
 /*****************************************************************************/
307 319
 
320
+void cc_enableClk(void)
321
+{
322
+  Serial.write(MSG_SOM1);
323
+  Serial.write(MSG_SOM2);
324
+  if (cc_read_data[0] == SI5351_CLK0)
325
+  {
326
+    si5351.output_enable(SI5351_CLK0, 1); // enable clock output 0
327
+    Serial.write(MSG_TYPE_ANSWER_OK);
328
+  }
329
+  else if (cc_read_data[0] == SI5351_CLK1)
330
+  {
331
+    si5351.output_enable(SI5351_CLK1, 1); // enable clock output 1
332
+    Serial.write(MSG_TYPE_ANSWER_OK);
333
+  }
334
+  else if (cc_read_data[0] == SI5351_CLK2)
335
+  {
336
+    si5351.output_enable(SI5351_CLK2, 1); // enable clock output 2
337
+    Serial.write(MSG_TYPE_ANSWER_OK);
338
+  } else {
339
+    Serial.write(MSG_TYPE_ANSWER_NOK);
340
+  }
341
+  Serial.write(MSG_EOM1);
342
+  Serial.write(MSG_EOM2);
343
+}
344
+
345
+/*****************************************************************************/
346
+
347
+void cc_disableClk(void)
348
+{
349
+  Serial.write(MSG_SOM1);
350
+  Serial.write(MSG_SOM2);
351
+  if (cc_read_data[0] == SI5351_CLK0)
352
+  {
353
+    si5351.output_enable(SI5351_CLK0, 0); // disable clock output 0
354
+    Serial.write(MSG_TYPE_ANSWER_OK);
355
+  }
356
+  else if (cc_read_data[0] == SI5351_CLK1)
357
+  {
358
+    si5351.output_enable(SI5351_CLK1, 0); // disable clock output 1
359
+    Serial.write(MSG_TYPE_ANSWER_OK);
360
+  }
361
+  else if (cc_read_data[0] == SI5351_CLK2)
362
+  {
363
+    si5351.output_enable(SI5351_CLK2, 0); // disable clock output 2
364
+    Serial.write(MSG_TYPE_ANSWER_OK);
365
+  } else {
366
+    Serial.write(MSG_TYPE_ANSWER_NOK);
367
+  }
368
+  Serial.write(MSG_EOM1);
369
+  Serial.write(MSG_EOM2);
370
+}
371
+
372
+/*****************************************************************************/
373
+
374
+void cc_saveDefaults(void)
375
+{
376
+  Serial.write(MSG_SOM1);
377
+  Serial.write(MSG_SOM2);
378
+
379
+  saveEEPValues();
380
+
381
+  Serial.write(MSG_TYPE_ANSWER_OK);
382
+  Serial.write(MSG_EOM1);
383
+  Serial.write(MSG_EOM2);
384
+}
385
+
386
+/*****************************************************************************/
387
+
308 388
 void cc_init()
309 389
 {
310 390
   cc_state                = CC_STATE_READ_SOM1;

+ 93
- 0
firmware/firmware.ino View File

@@ -4,13 +4,19 @@
4 4
  * License: GPLv3
5 5
  */
6 6
 
7
+/*****************************************************************************/
8
+
7 9
 #include <si5351.h>
8 10
 #include "Wire.h"
9 11
 
12
+#include <EEPROM.h>
13
+
10 14
 extern "C" {
11 15
   #include "globals.h"
12 16
 }
13 17
 
18
+/*****************************************************************************/
19
+
14 20
 Si5351 si5351;
15 21
 
16 22
 uint32_t start_freq = 10000;
@@ -19,6 +25,8 @@ uint32_t  step_freq = 1000000; // 1 MHz default step size
19 25
 uint16_t  intervall = 1000; // intervall to change the frequency as milli seconds
20 26
 enum si5351_drive drive_str = SI5351_DRIVE_2MA;
21 27
 
28
+/*****************************************************************************/
29
+
22 30
 void setup()
23 31
 {
24 32
   // manage the analog pins
@@ -51,8 +59,12 @@ void setup()
51 59
 
52 60
   analogReference(DEFAULT); // 5V reference
53 61
 
62
+  readEEPValues();
63
+
54 64
 }
55 65
 
66
+/*****************************************************************************/
67
+
56 68
 void loop()
57 69
 {
58 70
   // Read the Status Register and print it every 10 seconds
@@ -83,3 +95,84 @@ void loop()
83 95
   delay(100);
84 96
 }
85 97
 
98
+/*****************************************************************************/
99
+
100
+void saveEEPValues()
101
+{
102
+
103
+  EEPROM.write( 0, (uint8_t)((start_freq & 0xff000000) >> 24));
104
+  EEPROM.write( 1, (uint8_t)((start_freq & 0x00ff0000) >> 16));
105
+  EEPROM.write( 2, (uint8_t)((start_freq & 0x0000ff00) >>  8));
106
+  EEPROM.write( 3, (uint8_t) (start_freq & 0x000000ff));
107
+  EEPROM.write( 4, (uint8_t)((end_freq & 0xff000000) >> 24));
108
+  EEPROM.write( 5, (uint8_t)((end_freq & 0x00ff0000) >> 16));
109
+  EEPROM.write( 6, (uint8_t)((end_freq & 0x0000ff00) >>  8));
110
+  EEPROM.write( 7, (uint8_t) (end_freq & 0x000000ff));
111
+  EEPROM.write( 8, (uint8_t)((step_freq & 0xff000000) >> 24));
112
+  EEPROM.write( 9, (uint8_t)((step_freq & 0x00ff0000) >> 16));
113
+  EEPROM.write(10, (uint8_t)((step_freq & 0x0000ff00) >>  8));
114
+  EEPROM.write(11, (uint8_t) (step_freq & 0x000000ff));
115
+  EEPROM.write(12, (uint8_t)((intervall & 0xff00) >> 8));
116
+  EEPROM.write(13, (uint8_t) (intervall & 0x00ff));
117
+  EEPROM.write(14, (uint8_t) drive_str);
118
+
119
+}
120
+
121
+void readEEPValues()
122
+{
123
+  uint32_t tmp_start_freq  = (uint32_t)EEPROM.read(0) << 24;
124
+           tmp_start_freq += (uint32_t)EEPROM.read(1) << 16;
125
+           tmp_start_freq += (uint32_t)EEPROM.read(2) <<  8;
126
+           tmp_start_freq += (uint32_t)EEPROM.read(3);
127
+  if (tmp_start_freq < 1)
128
+    tmp_start_freq = 1;
129
+  if (tmp_start_freq > 150000000)
130
+    tmp_start_freq = 150000000;
131
+
132
+  start_freq = tmp_start_freq;
133
+
134
+  uint32_t tmp_end_freq  = (uint32_t)EEPROM.read(4) << 24;
135
+           tmp_end_freq += (uint32_t)EEPROM.read(5) << 16;
136
+           tmp_end_freq += (uint32_t)EEPROM.read(6) <<  8;
137
+           tmp_end_freq += (uint32_t)EEPROM.read(7);
138
+  if (tmp_end_freq < 1)
139
+    tmp_end_freq = 1;
140
+  if (tmp_end_freq > 150000000)
141
+    tmp_end_freq = 150000000;
142
+
143
+  end_freq = tmp_end_freq;
144
+
145
+  uint32_t tmp_step_freq  = (uint32_t)EEPROM.read( 8) << 24;
146
+           tmp_step_freq += (uint32_t)EEPROM.read( 9) << 16;
147
+           tmp_step_freq += (uint32_t)EEPROM.read(10) <<  8;
148
+           tmp_step_freq += (uint32_t)EEPROM.read(11);
149
+  if (tmp_step_freq < 1)
150
+    tmp_step_freq = 1;
151
+  if (tmp_step_freq > 150000000)
152
+    tmp_step_freq = 150000000;
153
+
154
+  step_freq = tmp_step_freq;
155
+
156
+  uint16_t tmp_intervall  = (uint16_t)EEPROM.read(12) << 8;
157
+           tmp_intervall += (uint16_t)EEPROM.read(13);
158
+  if (tmp_intervall < 1)
159
+    tmp_intervall = 1;
160
+  if (tmp_intervall > 150000000)
161
+    tmp_intervall = 150000000;
162
+
163
+  intervall = tmp_intervall;
164
+
165
+  enum si5351_drive tmp_ds  = (enum si5351_drive)EEPROM.read(14);
166
+  if (tmp_ds == SI5351_DRIVE_2MA ||
167
+      tmp_ds == SI5351_DRIVE_4MA ||
168
+      tmp_ds == SI5351_DRIVE_6MA ||
169
+      tmp_ds == SI5351_DRIVE_8MA)
170
+  {
171
+    drive_str = tmp_ds;
172
+  } else {
173
+    drive_str = SI5351_DRIVE_2MA;
174
+  }
175
+}
176
+
177
+/*****************************************************************************/
178
+

+ 9
- 0
firmware/globals.h View File

@@ -42,6 +42,9 @@
42 42
 #define CC_CMD_SET_FREQ_STEP        0x05
43 43
 #define CC_CMD_START_MEASUREMENT    0x06
44 44
 #define CC_CMD_GET_CONFIG           0x10
45
+#define CC_CMD_EN_CLK               0x20
46
+#define CC_CMD_DIS_CLK              0x21
47
+#define CC_CMD_SAV_DFLT             0x22
45 48
 
46 49
 /*****************************************************************************/
47 50
 
@@ -52,6 +55,9 @@
52 55
 #define CC_CMD_SET_FREQ_STEP_FUNC         &cc_setFreqStep
53 56
 #define CC_CMD_START_MEASUREMENT_FUNC     &cc_startMeasurement
54 57
 #define CC_CMD_GET_CONFIG_FUNC            &cc_getConfig
58
+#define CC_CMD_EN_CLK_FUNC                &cc_enableClk
59
+#define CC_CMD_DIS_CLK_FUNC               &cc_disableClk
60
+#define CC_CMD_SAV_DFLT_FUNC              &cc_saveDefaults
55 61
 
56 62
 /*****************************************************************************/
57 63
 
@@ -62,6 +68,9 @@
62 68
 #define CC_CMD_SET_FREQ_STEP_DATA_TO_READ       4
63 69
 #define CC_CMD_START_MEASUREMENT_DATA_TO_READ   0
64 70
 #define CC_CMD_GET_CONFIG_DATA_TO_READ          0
71
+#define CC_CMD_EN_CLK_DATA_TO_READ              1
72
+#define CC_CMD_DIS_CLK_DATA_TO_READ             1
73
+#define CC_CMD_SAV_DFLT_DATA_TO_READ            0
65 74
 
66 75
 /*****************************************************************************/
67 76
 

+ 10
- 7
tools/meas.py View File

@@ -32,7 +32,7 @@ parser.add_argument("-o", "--output_file", type=str, help="")
32 32
 # show graphical results
33 33
 parser.add_argument("-g", "--show_graph", default=False, help="", action='store_true')
34 34
 # get config
35
-#parser.add_argument("-c", "--get_config", default=False, help="", action='store_true')
35
+parser.add_argument("-c", "--get_config", default=False, help="", action='store_true')
36 36
 
37 37
 ###############################################################################
38 38
 
@@ -401,11 +401,6 @@ if __name__ == "__main__":
401 401
   time.sleep(1.5)
402 402
 
403 403
   # 3. get and process the commandline arguments/parameter
404
-  #if args.get_config == True and args.start_meas == False:
405
-  #  print "sent: GET_CONFIG"
406
-  #  sendSerialData([CC_CMD_GET_CONFIG])
407
-  #  dataSend = dataSend + 1
408
-
409 404
   if args.start_freq != None:
410 405
     print "Set start frequency to: " + user_friendly_freq(args.start_freq)
411 406
     sendSerialData([CC_CMD_SET_START_FREQ,
@@ -451,6 +446,11 @@ if __name__ == "__main__":
451 446
     sendSerialData([CC_CMD_START_MEASUREMENT])
452 447
     dataSend = dataSend + 1
453 448
 
449
+  if args.get_config == True and args.start_meas == False:
450
+    print "Read configuration values..."
451
+    sendSerialData([CC_CMD_GET_CONFIG])
452
+    dataSend = dataSend + 1
453
+
454 454
   # 4. start main loop
455 455
   while dataSend > 0 and timeout < TIMEOUT_CNT_MAX:
456 456
 
@@ -488,7 +488,10 @@ if __name__ == "__main__":
488 488
 
489 489
         elif e[1] == MSG_TYPE_CONFIG:
490 490
           #print "recv: CONFIG"
491
-          print "\nConfiguration used for measurement:"
491
+          if args.start_meas == True:
492
+            print "\nConfiguration used for measurement:"
493
+          else:
494
+            print "\nConfiguration:"
492 495
           start_freq  = e[3][0] << 24
493 496
           start_freq += e[3][1] << 16
494 497
           start_freq += e[3][2] <<  8