Commit 98b31dc0 authored by Matthieu Cattin's avatar Matthieu Cattin

test39: Set and test real hardware variable saturation.

parent 1a77a5f4
...@@ -145,11 +145,14 @@ def plot_channel(ncal_ch_data, cal_ch_data, scal_ch_data, ncal_ch_mean, cal_ch_m ...@@ -145,11 +145,14 @@ def plot_channel(ncal_ch_data, cal_ch_data, scal_ch_data, ncal_ch_mean, cal_ch_m
plot(sample, [scal_ch_mean]*len(sample), 'm--', label='Corrected & saturated middle') plot(sample, [scal_ch_mean]*len(sample), 'm--', label='Corrected & saturated middle')
plot(sample, [sat]*len(sample), 'm') plot(sample, [sat]*len(sample), 'm')
plot(sample, [-sat]*len(sample), 'm') plot(sample, [-sat]*len(sample), 'm')
plot(sample, [32764]*len(sample), 'r') plot(sample, [32764]*len(sample), 'g')
plot(sample, [-32765]*len(sample), 'r') plot(sample, [-32765]*len(sample), 'g')
ylim(-ylimit-(ylimit/10.0), ylimit+(ylimit/10.0)) ylim(-ylimit-(ylimit/10.0), ylimit+(ylimit/10.0))
grid(color='k', linestyle=':', linewidth=1) grid(color='k', linestyle=':', linewidth=1)
legend(loc='upper left') legend(loc='upper left')
xlabel('Samples')
ylabel('Raw ADC values (two\'s complement)')
title('Variable saturation, limit: %d'%sat)
#draw() #draw()
show() show()
return 0 return 0
...@@ -247,8 +250,8 @@ def main (default_directory='.'): ...@@ -247,8 +250,8 @@ def main (default_directory='.'):
# Set awg sine params to make adc saturate # Set awg sine params to make adc saturate
################################################## ##################################################
sine.frequency = 1E6 sine.frequency = 1E6
sine.amplitude = 1.2 * ADC_FS[IN_RANGE] sine.amplitude = 0.5 * ADC_FS[IN_RANGE]
sine.dc = 0 sine.dc = 0#ADC_FS[IN_RANGE]/4.0
print "\nSine frequency:%3.3fMHz amplitude:%2.3fVp offset:%2.3fV" % (sine.frequency/1E6, sine.amplitude, sine.dc) print "\nSine frequency:%3.3fMHz amplitude:%2.3fVp offset:%2.3fV" % (sine.frequency/1E6, sine.amplitude, sine.dc)
# Set AWG # Set AWG
...@@ -261,7 +264,7 @@ def main (default_directory='.'): ...@@ -261,7 +264,7 @@ def main (default_directory='.'):
################################################## ##################################################
# Acquire channel 1 and print # Acquire channel 1
################################################## ##################################################
print "\nAcquiring channel 1" print "\nAcquiring channel 1"
# Configure analogue input # Configure analogue input
...@@ -395,7 +398,7 @@ def main (default_directory='.'): ...@@ -395,7 +398,7 @@ def main (default_directory='.'):
get_corr_values(fmc) get_corr_values(fmc)
################################################## ##################################################
# Acquire channel 1 and print # Acquire channel 1
################################################## ##################################################
print "\nAcquiring channel 1" print "\nAcquiring channel 1"
# Perform an acquisition # Perform an acquisition
...@@ -413,6 +416,35 @@ def main (default_directory='.'): ...@@ -413,6 +416,35 @@ def main (default_directory='.'):
cal_ch_mean = ch_mid cal_ch_mean = ch_mid
cal_ch_data = channel_data cal_ch_data = channel_data
##################################################
# Set saturation
##################################################
sat_thres = 10000
fmc.fmc_adc_csr.set_field('CH1_SAT', 'VAL', sat_thres)
fmc.fmc_adc_csr.set_field('CH2_SAT', 'VAL', sat_thres)
fmc.fmc_adc_csr.set_field('CH3_SAT', 'VAL', sat_thres)
fmc.fmc_adc_csr.set_field('CH4_SAT', 'VAL', sat_thres)
##################################################
# Acquire channel 1
##################################################
print "\nAcquiring channel 1"
# Perform an acquisition
acq_data, trig_timetag = acq_channels(fmc, carrier, ADC_FS[IN_RANGE], ACQ_PAUSE)
channel_data = acq_data[0::4]
print("Number of samples: %d"%(len(channel_data)))
# Calculate middle value
ch_max = max(channel_data)
ch_min = min(channel_data)
ch_mid = (abs(ch_max) - abs(ch_min))
ch_mean = mean(channel_data)
print("Channel max=%d, min=%d, mid=%d, mean=%d"%(ch_max, ch_min, ch_mid, ch_mean))
sat_cal_ch_mean = ch_mid
sat_cal_ch_data = channel_data
"""
################################################## ##################################################
# Artificially saturate corrected data # Artificially saturate corrected data
################################################## ##################################################
...@@ -432,6 +464,7 @@ def main (default_directory='.'): ...@@ -432,6 +464,7 @@ def main (default_directory='.'):
ch_mean = mean(sat_cal_ch_data) ch_mean = mean(sat_cal_ch_data)
sat_cal_ch_mean = ch_mid sat_cal_ch_mean = ch_mid
"""
################################################## ##################################################
# Plot channel # Plot channel
......
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