Commit 5fbd54a2 authored by Matthieu Cattin's avatar Matthieu Cattin

test28: Fix few bugs, add comments.

parent 43f1a9c8
...@@ -110,6 +110,7 @@ def hex2signed(value): ...@@ -110,6 +110,7 @@ def hex2signed(value):
else: else:
return value return value
# Converts signed to two's complement hex # Converts signed to two's complement hex
def signed2hex(value): def signed2hex(value):
if value < 0: if value < 0:
...@@ -117,10 +118,12 @@ def signed2hex(value): ...@@ -117,10 +118,12 @@ def signed2hex(value):
else: else:
return value return value
# Converts digital value to volts # Converts digital value to volts
def digital2volt(value, full_scale, nb_bit): def digital2volt(value, full_scale, nb_bit):
return float(value) * float(full_scale)/2**nb_bit return float(value) * float(full_scale)/2**nb_bit
# Converts volts to digital value with half full range offset # Converts volts to digital value with half full range offset
def volt2digital(value, full_scale, nb_bit): def volt2digital(value, full_scale, nb_bit):
digital = (value + full_scale/2) * 2**nb_bit/full_scale digital = (value + full_scale/2) * 2**nb_bit/full_scale
...@@ -131,6 +134,7 @@ def volt2digital(value, full_scale, nb_bit): ...@@ -131,6 +134,7 @@ def volt2digital(value, full_scale, nb_bit):
#print('volt2digital: %2.9f > %2.9f')%(value,digital) #print('volt2digital: %2.9f > %2.9f')%(value,digital)
return int(digital) return int(digital)
# Converts volts to digital value # Converts volts to digital value
def volt2digital_without_offset(value, full_scale, nb_bit): def volt2digital_without_offset(value, full_scale, nb_bit):
if(value > (2**nb_bit)/2 - 1): if(value > (2**nb_bit)/2 - 1):
...@@ -141,7 +145,8 @@ def volt2digital_without_offset(value, full_scale, nb_bit): ...@@ -141,7 +145,8 @@ def volt2digital_without_offset(value, full_scale, nb_bit):
#print('volt2digital: %2.9f > %2.9f')%(value,digital) #print('volt2digital: %2.9f > %2.9f')%(value,digital)
return int(digital) return int(digital)
# Clear DDR memory (fill with zeros)
# Clears DDR memory (fill with zeros)
def clear_ddr(carrier, verbose=False): def clear_ddr(carrier, verbose=False):
if verbose: if verbose:
print("Clearing DDR memory") print("Clearing DDR memory")
...@@ -174,6 +179,7 @@ def clear_ddr(carrier, verbose=False): ...@@ -174,6 +179,7 @@ def clear_ddr(carrier, verbose=False):
carrier.set_irq_dma_done_mask(0) carrier.set_irq_dma_done_mask(0)
# Returns calibration data from fmc eeprom
def get_calibr_data(fmc, eeprom_bin_filename, calibr_bin_filename, verbose=False): def get_calibr_data(fmc, eeprom_bin_filename, calibr_bin_filename, verbose=False):
if verbose: if verbose:
print "Read calibration data from FMC EEPROM:" print "Read calibration data from FMC EEPROM:"
...@@ -232,12 +238,12 @@ def get_calibr_data(fmc, eeprom_bin_filename, calibr_bin_filename, verbose=False ...@@ -232,12 +238,12 @@ def get_calibr_data(fmc, eeprom_bin_filename, calibr_bin_filename, verbose=False
adc_corr_data[adc_range]['gain'].append(eeprom_corr_data.pop(0)) adc_corr_data[adc_range]['gain'].append(eeprom_corr_data.pop(0))
adc_corr_data[adc_range]['temp'] = eeprom_corr_data.pop(0)/100.0 adc_corr_data[adc_range]['temp'] = eeprom_corr_data.pop(0)/100.0
for IN_RANGE in RANGES: for dac_range in RANGES:
for ch in range(NB_CHANNELS): for ch in range(NB_CHANNELS):
dac_corr_data[adc_range]['offset'].append(hex2signed(eeprom_corr_data.pop(0))) dac_corr_data[dac_range]['offset'].append(hex2signed(eeprom_corr_data.pop(0)))
for ch in range(NB_CHANNELS): for ch in range(NB_CHANNELS):
dac_corr_data[adc_range]['gain'].append(eeprom_corr_data.pop(0)) dac_corr_data[dac_range]['gain'].append(eeprom_corr_data.pop(0))
dac_corr_data[adc_range]['temp'] = eeprom_corr_data.pop(0)/100.0 dac_corr_data[dac_range]['temp'] = eeprom_corr_data.pop(0)/100.0
return adc_corr_data, dac_corr_data return adc_corr_data, dac_corr_data
...@@ -258,6 +264,7 @@ def set_awg(awg, freq, ampl, offset, verbose=False): ...@@ -258,6 +264,7 @@ def set_awg(awg, freq, ampl, offset, verbose=False):
awg.sync = True awg.sync = True
time.sleep(AWG_SET_SLEEP) time.sleep(AWG_SET_SLEEP)
# Get best adc input range for a given amplitude # Get best adc input range for a given amplitude
def get_best_input_range(in_ampl, term, verbose=False): def get_best_input_range(in_ampl, term, verbose=False):
# If the 50 ohms termination is enabled, input amplitude is reduced by a factor 2 # If the 50 ohms termination is enabled, input amplitude is reduced by a factor 2
...@@ -272,6 +279,7 @@ def get_best_input_range(in_ampl, term, verbose=False): ...@@ -272,6 +279,7 @@ def get_best_input_range(in_ampl, term, verbose=False):
print("Selected input range: %s"%in_range) print("Selected input range: %s"%in_range)
return in_range return in_range
# Set acquisition params # Set acquisition params
def set_acq(fmc, nb_shots, pre_trig_samples, post_trig_samples, decim_factor, verbose=False): def set_acq(fmc, nb_shots, pre_trig_samples, post_trig_samples, decim_factor, verbose=False):
fmc.set_pre_trig_samples(pre_trig_samples) fmc.set_pre_trig_samples(pre_trig_samples)
...@@ -281,6 +289,7 @@ def set_acq(fmc, nb_shots, pre_trig_samples, post_trig_samples, decim_factor, ve ...@@ -281,6 +289,7 @@ def set_acq(fmc, nb_shots, pre_trig_samples, post_trig_samples, decim_factor, ve
if verbose: if verbose:
print("Acquisition params -> number of shots: %d, pre-trigger samples: %d, post-trigger samples: %d, decimation factor: %d"%(nb_shots, pre_trig_samples, post_trig_samples, decim_factor)) print("Acquisition params -> number of shots: %d, pre-trigger samples: %d, post-trigger samples: %d, decimation factor: %d"%(nb_shots, pre_trig_samples, post_trig_samples, decim_factor))
# Set analog input range and termination (same on all channels) # Set analog input range and termination (same on all channels)
def set_adc_input(fmc, term, in_range, verbose=False): def set_adc_input(fmc, term, in_range, verbose=False):
for channel in range(1,NB_CHANNELS+1): for channel in range(1,NB_CHANNELS+1):
...@@ -290,6 +299,7 @@ def set_adc_input(fmc, term, in_range, verbose=False): ...@@ -290,6 +299,7 @@ def set_adc_input(fmc, term, in_range, verbose=False):
if verbose: if verbose:
print("ADC input params -> Termination: %s, input range: %s"%(term, in_range)) print("ADC input params -> Termination: %s, input range: %s"%(term, in_range))
# Set channel offset with the DAC (same on all channels) # Set channel offset with the DAC (same on all channels)
def set_adc_offset(fmc, offset_volt, verbose=False): def set_adc_offset(fmc, offset_volt, verbose=False):
dac_fs = DAC_FS dac_fs = DAC_FS
...@@ -301,6 +311,7 @@ def set_adc_offset(fmc, offset_volt, verbose=False): ...@@ -301,6 +311,7 @@ def set_adc_offset(fmc, offset_volt, verbose=False):
fmc.set_dc_offset(channel,dac_d) fmc.set_dc_offset(channel,dac_d)
time.sleep(DAC_SET_SLEEP) time.sleep(DAC_SET_SLEEP)
# Set hardware trigger # Set hardware trigger
def set_adc_trig(fmc, hw_sel, hw_pol, channel, thres_volt, delay, in_range, verbose=False): def set_adc_trig(fmc, hw_sel, hw_pol, channel, thres_volt, delay, in_range, verbose=False):
fs = RANGES[in_range] fs = RANGES[in_range]
...@@ -365,6 +376,7 @@ def make_acq(carrier, fmc, verbose=False): ...@@ -365,6 +376,7 @@ def make_acq(carrier, fmc, verbose=False):
# Disables acquisition end interrupt # Disables acquisition end interrupt
carrier.set_irq_acq_end_mask(0) carrier.set_irq_acq_end_mask(0)
# Make a linked list dma # Make a linked list dma
def make_dma(carrier, start_byte_addr, length_bytes, in_range, verbose=False): def make_dma(carrier, start_byte_addr, length_bytes, in_range, verbose=False):
# Enable "DMA done" interrupt # Enable "DMA done" interrupt
...@@ -394,6 +406,7 @@ def make_dma(carrier, start_byte_addr, length_bytes, in_range, verbose=False): ...@@ -394,6 +406,7 @@ def make_dma(carrier, start_byte_addr, length_bytes, in_range, verbose=False):
#carrier.print_irq_controller_regs() #carrier.print_irq_controller_regs()
return data return data
# Get data from DDR memory # Get data from DDR memory
def get_acq_data(carrier, fmc, samples, pre_trig_samples, nb_shots, in_range, verbose=False): def get_acq_data(carrier, fmc, samples, pre_trig_samples, nb_shots, in_range, verbose=False):
...@@ -420,9 +433,9 @@ def get_acq_data(carrier, fmc, samples, pre_trig_samples, nb_shots, in_range, ve ...@@ -420,9 +433,9 @@ def get_acq_data(carrier, fmc, samples, pre_trig_samples, nb_shots, in_range, ve
start_pos = trig_pos - pre_trig_samples start_pos = trig_pos - pre_trig_samples
if verbose: if verbose:
print("Trigger position (samples) : %d" % (trig_pos)) print("Trigger position (samples) : %d" % (trig_pos))
print("Acqisition start position (samples): %d" % (start_pos)) print("Acquisition start position (samples): %d" % (start_pos))
print("Total number of samples : %d" % (samples)) print("Total number of samples : %d" % (samples))
# Check if acquisition is overlapping ddr memory # Check if acquisition is overlapping ddr memory
if start_pos + samples > MEMORY_SIZE: if start_pos + samples > MEMORY_SIZE:
...@@ -491,6 +504,8 @@ def plot_all(data, ylimit, trig_level, trig_pos): ...@@ -491,6 +504,8 @@ def plot_all(data, ylimit, trig_level, trig_pos):
return 0 return 0
def main (default_directory='.'): def main (default_directory='.'):
...@@ -525,7 +540,7 @@ def main (default_directory='.'): ...@@ -525,7 +540,7 @@ def main (default_directory='.'):
try: try:
# Others objects declaration # Calibration box and arbitrary waveform generator objects declaration
usb_tty = CttyUSB() usb_tty = CttyUSB()
awg_tty = usb_tty.find_usb_tty(AWG_USB_VENDOR_ID, AWG_USB_PRODUCT_ID) awg_tty = usb_tty.find_usb_tty(AWG_USB_VENDOR_ID, AWG_USB_PRODUCT_ID)
box_tty = usb_tty.find_usb_tty(BOX_USB_VENDOR_ID, BOX_USB_PRODUCT_ID) box_tty = usb_tty.find_usb_tty(BOX_USB_VENDOR_ID, BOX_USB_PRODUCT_ID)
...@@ -542,7 +557,7 @@ def main (default_directory='.'): ...@@ -542,7 +557,7 @@ def main (default_directory='.'):
calibr_bin_filename = os.path.join(default_directory, CALIBR_BIN_FILENAME) calibr_bin_filename = os.path.join(default_directory, CALIBR_BIN_FILENAME)
eeprom_bin_filename = os.path.join(default_directory, EEPROM_BIN_FILENAME) eeprom_bin_filename = os.path.join(default_directory, EEPROM_BIN_FILENAME)
adc_corr_data, dac_corr_data = get_calibr_data(fmc, eeprom_bin_filename, calibr_bin_filename, False) adc_corr_data, dac_corr_data = get_calibr_data(fmc, eeprom_bin_filename, calibr_bin_filename, False)
# Apply DAC correction # Apply DAC correction (correction data will be used every time a DAC is set)
fmc.set_dac_corr(dac_corr_data) fmc.set_dac_corr(dac_corr_data)
...@@ -561,15 +576,15 @@ def main (default_directory='.'): ...@@ -561,15 +576,15 @@ def main (default_directory='.'):
# Choose input termination randomly # Choose input termination randomly
########################################################## ##########################################################
#adc_term = rdm.choice(['ON', 'OFF']) adc_term = rdm.choice(['ON', 'OFF'])
adc_term = 'OFF' #adc_term = 'ON'
########################################################## ##########################################################
print("Input termination: %s"%adc_term) print("Input termination: %s"%adc_term)
# Choose input range randomly # Choose input range randomly
########################################################## ##########################################################
#adc_range = rdm.choice(['10V', '1V', '100mV']) adc_range = rdm.choice(['10V', '1V', '100mV'])
adc_range = '10V' #adc_range = '10V'
########################################################## ##########################################################
print("Input range: %s"%adc_range) print("Input range: %s"%adc_range)
...@@ -593,14 +608,19 @@ def main (default_directory='.'): ...@@ -593,14 +608,19 @@ def main (default_directory='.'):
if adc_term == 'ON': if adc_term == 'ON':
sine_min_ampl *= 2 sine_min_ampl *= 2
sine_max_ampl *= 2 sine_max_ampl *= 2
print("Input sine wave => max amplitude: %2.3fV, min amplitude: %2.3fV"%(sine_min_ampl, sine_max_ampl)) print("Input sine wave => min amplitude: %2.3fV, max amplitude: %2.3fV"%(sine_min_ampl, sine_max_ampl))
#sine_ampl = sine_min_ampl + ((sine_max_ampl-sine_min_ampl)*rdm.random()) #sine_ampl = sine_min_ampl + ((sine_max_ampl-sine_min_ampl)*rdm.random())
sine_ampl = rdm.randrange(int(sine_min_ampl*1E3), int(sine_max_ampl*1E3), 100)/1000.0 sine_ampl = rdm.randrange(int(sine_min_ampl*1E3), int(sine_max_ampl*1E3), 100)/1000.0
#sine_offset = (sine_max_ampl-sine_ampl)*rdm.random() #sine_offset = (sine_max_ampl-sine_ampl)*rdm.random()
sine_offset = 0 sine_offset = 0.0
print("Input sine wave => Frequency: %3.3fMHz, Amplitude: %2.3fVp, Offset: %2.3fV"%(sine_freq/1E6, sine_ampl, sine_offset)) print("Input sine wave => Frequency: %3.3fMHz, Amplitude: %2.3fVp, Offset: %2.3fV"%(sine_freq/1E6, sine_ampl, sine_offset))
# Configure AWG with sine wave # Configure AWG with sine wave
#######################
#sine_freq = 1E6
#sine_ampl = 2.0
#sien_offset = 0.0
#######################
set_awg(awg, sine_freq, sine_ampl, sine_offset, True) set_awg(awg, sine_freq, sine_ampl, sine_offset, True)
...@@ -621,11 +641,14 @@ def main (default_directory='.'): ...@@ -621,11 +641,14 @@ def main (default_directory='.'):
######################################################################## ########################################################################
# Configure trigger # Configure trigger
#######################
trig_hw_sel = 0 # internal trig_hw_sel = 0 # internal
#trig_hw_sel = 1 # external
trig_hw_pol = 0 # rising trig_hw_pol = 0 # rising
trig_channel = channel trig_channel = channel
trig_thres = (sine_ampl+0.05) # in Volts trig_thres = sine_offset # in Volts
trig_delay = 0 # in samples trig_delay = 0 # in samples
#######################
set_adc_trig(fmc, trig_hw_sel, trig_hw_pol, trig_channel, trig_thres, trig_delay, adc_range, True) set_adc_trig(fmc, trig_hw_sel, trig_hw_pol, trig_channel, trig_thres, trig_delay, adc_range, True)
# Find the minimum number of samples to have ACQ_MIN_PERIODS of the sine wave # Find the minimum number of samples to have ACQ_MIN_PERIODS of the sine wave
...@@ -635,13 +658,16 @@ def main (default_directory='.'): ...@@ -635,13 +658,16 @@ def main (default_directory='.'):
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Can't use all available memory on-board. # Can't use all available memory on-board.
# Bad memory management in my Python program... # Bad memory management in my Python program...
# -> Limiting the max number of samples.
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
mem_size = MEMORY_SIZE/100 mem_size = MEMORY_SIZE/100
print("Memory size in samples : %d"%mem_size) print("Memory size in samples : %d"%mem_size)
# Choose the number of shots and samples randomly # Choose the number of shots and samples randomly
#######################
#multishot = rdm.choice([False, True]) #multishot = rdm.choice([False, True])
multishot = False multishot = False
#######################
if multishot: if multishot:
acq_samples = rdm.randrange(acq_min_samples, MULTISHOT_MAX_SIZE+1) acq_samples = rdm.randrange(acq_min_samples, MULTISHOT_MAX_SIZE+1)
acq_nb_shots = rdm.randrange(1, (mem_size/acq_samples)+1) acq_nb_shots = rdm.randrange(1, (mem_size/acq_samples)+1)
...@@ -655,7 +681,13 @@ def main (default_directory='.'): ...@@ -655,7 +681,13 @@ def main (default_directory='.'):
acq_post_trig_samples = acq_samples - acq_pre_trig_samples acq_post_trig_samples = acq_samples - acq_pre_trig_samples
# Configure acquisition # Configure acquisition
####################
acq_decim_factor = 1 acq_decim_factor = 1
acq_nb_shots = 1
#acq_pre_trig_samples = 100
#acq_post_trig_samples = 1000
#acq_samples = acq_pre_trig_samples + acq_post_trig_samples
####################
set_acq(fmc, acq_nb_shots, acq_pre_trig_samples, acq_post_trig_samples, acq_decim_factor, True) set_acq(fmc, acq_nb_shots, acq_pre_trig_samples, acq_post_trig_samples, acq_decim_factor, True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment