@@ -96,7 +96,11 @@ def __init__(self, name, parent_device, com_port, dynamic_channels,
9696 raise ValueError ('ref_clock_frequency must be less than 133 MHz when clock is provided by Pi Pico' )
9797
9898 self .dds_clock = ref_clock_frequency * pll_mult
99- self .clk_scale = 2 ** 32 / self .dds_clock
99+ # define output scale factors for dynamic channels
100+ # static channel scaling handled by firmware
101+ self .freq_scale = 2 ** 32 / self .dds_clock
102+ self .amp_scale = 1023
103+ self .phase_scale = 16384 / 360.0
100104
101105 # Store number of dynamic channels
102106 if dynamic_channels > 4 :
@@ -168,11 +172,10 @@ def quantise_freq(self, data, device):
168172 raise LabscriptError ('%s %s ' % (device .description , device .name ) +
169173 'can only have frequencies between 0.0Hz and %f MHz, ' +
170174 'the limit imposed by %s.' % (self .name , self .dds_clock / 2e6 ))
171- scale_factor = self .clk_scale # Need to multiply by clk scale factor
172175
173176 # It's faster to add 0.5 then typecast than to round to integers first:
174- data = np .array ((scale_factor * data )+ 0.5 ,dtype = '<u4' )
175- return data , scale_factor
177+ data = np .array ((self . freq_scale * data )+ 0.5 ,dtype = '<u4' )
178+ return data
176179
177180 def quantise_phase (self , data , device ):
178181 """Ensures phase is wrapped about 360 degrees and scales to instrument
@@ -182,9 +185,8 @@ def quantise_phase(self, data, device):
182185 # ensure that phase wraps around:
183186 data %= 360
184187 # It's faster to add 0.5 then typecast than to round to integers first:
185- scale_factor = 16384 / 360.0
186- data = np .array ((scale_factor * data )+ 0.5 ,dtype = '<u2' )
187- return data , scale_factor
188+ data = np .array ((self .phase_scale * data )+ 0.5 ,dtype = '<u2' )
189+ return data
188190
189191 def quantise_amp (self , data , device ):
190192 """Ensures amplitude is within bounds and scales to instrument units
@@ -197,9 +199,8 @@ def quantise_amp(self, data, device):
197199 'can only have amplitudes between 0 and 1 (Volts peak to peak approx), ' +
198200 'the limit imposed by %s.' % self .name )
199201 # It's faster to add 0.5 then typecast than to round to integers first:
200- data = np .array ((1023 * data )+ 0.5 ,dtype = '<u2' )
201- scale_factor = 1023
202- return data , scale_factor
202+ data = np .array ((self .amp_scale * data )+ 0.5 ,dtype = '<u2' )
203+ return data
203204
204205 def generate_code (self , hdf5_file ):
205206
@@ -238,9 +239,9 @@ def generate_code(self, hdf5_file):
238239
239240 for connection in dyn_DDSs :
240241 dds = dyn_DDSs [connection ]
241- dds .frequency .raw_output , dds . frequency . scale_factor = self .quantise_freq (dds .frequency .raw_output , dds )
242- dds .phase .raw_output , dds . phase . scale_factor = self .quantise_phase (dds .phase .raw_output , dds )
243- dds .amplitude .raw_output , dds . amplitude . scale_factor = self .quantise_amp (dds .amplitude .raw_output , dds )
242+ dds .frequency .raw_output = self .quantise_freq (dds .frequency .raw_output , dds )
243+ dds .phase .raw_output = self .quantise_phase (dds .phase .raw_output , dds )
244+ dds .amplitude .raw_output = self .quantise_amp (dds .amplitude .raw_output , dds )
244245
245246 dyn_dtypes = {'names' :['%s%d' % (k , i ) for i in dyn_DDSs for k in ['freq' , 'amp' , 'phase' ] ],
246247 'formats' :[f for i in dyn_DDSs for f in ('<u4' , '<u2' , '<u2' )]}
@@ -280,9 +281,6 @@ def generate_code(self, hdf5_file):
280281 if stat_DDSs :
281282 grp .create_dataset ('static_data' , compression = config .compression , data = static_table )
282283 # Store parameter scale factors
283- _ , frequency_scale_factor = self .quantise_freq ([], None )
284- _ , amplitude_scale_factor = self .quantise_amp ([], None )
285- _ , phase_scale_factor = self .quantise_phase ([], None )
286- self .set_property ('frequency_scale_factor' , frequency_scale_factor , location = 'device_properties' )
287- self .set_property ('amplitude_scale_factor' , amplitude_scale_factor , location = 'device_properties' )
288- self .set_property ('phase_scale_factor' , phase_scale_factor , location = 'device_properties' )
284+ self .set_property ('frequency_scale_factor' , self .freq_scale , location = 'device_properties' )
285+ self .set_property ('amplitude_scale_factor' , self .amp_scale , location = 'device_properties' )
286+ self .set_property ('phase_scale_factor' , self .phase_scale , location = 'device_properties' )
0 commit comments