From 5d0ce16007f96dc9256cfdc334bd7f474c7f3aeb Mon Sep 17 00:00:00 2001
From: TUD278427 <TUD278427@tudelft.net>
Date: Thu, 4 Jun 2020 11:50:34 +0200
Subject: [PATCH] Generalized the firmware loader. Just copy the paths to a
 station specific file (pulse_lib e.g.) and import from there and supply as
 argument to the loader. Also av_mode now needs to be specified explicitly

---
 core_tools/drivers/M3102_firmware_loader.py | 49 ++++++++-------------
 core_tools/utility/dig_utility.py           | 36 +++++++--------
 2 files changed, 36 insertions(+), 49 deletions(-)

diff --git a/core_tools/drivers/M3102_firmware_loader.py b/core_tools/drivers/M3102_firmware_loader.py
index b864d4a7..1c21ee48 100644
--- a/core_tools/drivers/M3102_firmware_loader.py
+++ b/core_tools/drivers/M3102_firmware_loader.py
@@ -1,33 +1,22 @@
-"""
-Standard firmware files for the digitizer of the V2 setup.
+from projects.keysight_measurement.M3102A import MODES
 
-CLEAN : normal image, revert to the normal AWG.
-AVG : special image with MAV and interator. A custom qcodes driver needs to be used for that.
-"""
-M3102A_CLEAN = "C:/V2_code/FPGA_Bitstreams/Digitizer_FW1.41/clean_4_41.sbp"
-M3102A_AVG = "C:/V2_code/FPGA_Bitstreams/Digitizer_FW1.41/averaging_firmware_1_41.sbp"
+def firmware_loader(dig, file, av_mode):
+    """
+    load a custom firmware image on board of the digitizer
 
-from core_tools.drivers.M3102A import MODES
+    Args:
+        dig <SD_dig (qcodes instrument) : digitzer object
+        file (string) : location where to find the new firmware
+    """
+    err = dig.SD_AIN.FPGAload(file)
+    if av_mode == 'normal':
+        dig.set_aquisition_mode(MODES.NORMAL)
+    elif av_mode == 'average':
+        dig.set_aquisition_mode(MODES.AVERAGE)
+    else:
+        raise ValueError("Average mode must be normal or average")
 
-def firmware_loader(dig, file):
-	"""
-	load a custom firmware image on board of the digitizer
-
-	Args:
-		dig <SD_dig (qcodes instrument) : digitzer object
-		file (string) : location where to find the new firmware
-	"""
-	err = dig.SD_AIN.FPGAload(file)
-	if file == M3102A_CLEAN:
-		dig.set_aquisition_mode(MODES.NORMAL)
-	else:
-		dig.set_aquisition_mode(MODES.AVERAGE)
-
-
-	if err == 0 :
-		print("Succesful upload of the firmware")
-	else:
-		print("upload failed, error code {} (see keysight manual for instructions)".format(err))
-
-if __name__ == '__main__':
-	firmware_loader(dig, M3102A_CLEAN)
\ No newline at end of file
+    if err == 0 :
+        print("Succesful upload of the firmware")
+    else:
+        print("upload failed, error code {} (see keysight manual for instructions)".format(err))
\ No newline at end of file
diff --git a/core_tools/utility/dig_utility.py b/core_tools/utility/dig_utility.py
index f608bd69..3eeaec1c 100644
--- a/core_tools/utility/dig_utility.py
+++ b/core_tools/utility/dig_utility.py
@@ -1,23 +1,21 @@
-from core_tools.drivers.M3102A import SD_DIG, MODES, DATA_MODE
-from core_tools.drivers.M3102_firmware_loader import firmware_loader, M3102A_CLEAN, M3102A_AVG
-import qcodes as qc
+from projects.keysight_measurement.M3102A import SD_DIG, MODES, DATA_MODE
+from core_tools.drivers.M3102_firmware_loader import firmware_loader
 
-def autoconfig_digitizer(firmware = M3102A_AVG):
-	station = qc.Station.default
-	#dig = SD_DIG(name ="M3102A_digitizer_", chassis = 0, slot = 6)
-	if firmware is not None:
-		firmware_loader(station.dig, firmware)
+def autoconfig_digitizer(digitizer, firmware = None, av_mode = None):
+    if firmware is not None:
+        if av_mode is None:
+            raise ValueError('Please specify average mode (normal or average) when specifying firmware')
+        firmware_loader(digitizer, firmware, av_mode)
 
-	#set digitzer to use software triggering and return 1 point per channel --> average the full trace.
-	t_measure = 1e4 #1ms (unit ns)
-	cycles = 1 # just measure once.
+    #set digitzer to use software triggering and return 1 point per channel --> average the full trace.
+    t_measure = 1e3 #1us (unit ns)
+    cycles = 1 # just measure once.
+    digitizer.set_digitizer_software(t_measure, cycles, data_mode = DATA_MODE.AVERAGE_TIME_AND_CYCLES, 
+                                  channels = [1,2,3,4], fourchannel = True)
 
-	station.dig.set_digitizer_software(t_measure, cycles, data_mode=DATA_MODE.AVERAGE_TIME_AND_CYCLES, channels = [1,2], fourchannel=True )
+    digitizer.daq_flush(1)
+    digitizer.daq_flush(2)
+    digitizer.daq_flush(3)
+    digitizer.daq_flush(4)
 
-	station.dig.daq_flush(1)
-	station.dig.daq_flush(2)
-	station.dig.daq_flush(3)
-	station.dig.daq_flush(4)
-	
-	print("testing digitzer :: ")
-	print(station.dig.measure())
\ No newline at end of file
+    print("testing digitizer:",digitizer.measure())
\ No newline at end of file
-- 
GitLab