Skip to content

Commit

Permalink
Move SET_FREQ for both NCOs at start
Browse files Browse the repository at this point in the history
--DR
  • Loading branch information
CoherenceController committed Sep 7, 2016
1 parent b64fb99 commit a5b8c16
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions QGL/drivers/APS2Pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,15 @@ def to_instruction(self, write_flag=True, label=None):
def inject_modulation_cmds(seqs):
"""
Inject modulation commands from phase, frequency and frameChange of waveforms
in an IQ waveform sequence. Assume single NCO for now.
in an IQ waveform sequence. Assume up to 2 NCOs for now.
"""
cur_freq = 0
cur_phase = 0
for ct,seq in enumerate(seqs):
#check whether we have modulation commands
freqs = np.unique([entry.frequency for entry in filter(lambda s: isinstance(s,Compiler.Waveform), seq)])
if len(freqs) > 2:
raise Exception("Max 2 frequencies on the same channel allowed.")
no_freq_cmds = np.allclose(freqs, 0)
phases = [entry.phase for entry in filter(lambda s: isinstance(s,Compiler.Waveform), seq)]
no_phase_cmds = np.allclose(phases, 0)
Expand All @@ -506,7 +508,6 @@ def inject_modulation_cmds(seqs):

mod_seq = []
pending_frame_update = False
nco_select = 0x1

for entry in seq:

Expand All @@ -520,34 +521,28 @@ def inject_modulation_cmds(seqs):
if isinstance(entry, ControlFlow.Wait):
if not ( no_modulation_cmds and (cur_freq == 0) and (cur_phase == 0)):
mod_seq.append(ModulationCommand("RESET_PHASE", 0x3))
for nco_ind, freq in enumerate(freqs):
mod_seq.append( ModulationCommand("SET_FREQ", nco_ind + 1, frequency = -freq) )
elif isinstance(entry, ControlFlow.Return):
cur_freq = 0 #makes sure that the frequency is set in the first sequence after the definition of subroutines
mod_seq.append(copy(entry))
elif isinstance(entry, Compiler.Waveform):
if not no_modulation_cmds:
#insert phase and frequency commands before modulation command so they have the same start time
phase_freq_cmds = []
if cur_freq != entry.frequency and (not entry.isTimeAmp or cur_freq==0):
if nco_select == 0x1 and cur_freq!=0:
nco_select = 0x2
else:
nco_select = 0x1
phase_freq_cmds.append( ModulationCommand("SET_FREQ", nco_select, frequency=-entry.frequency) )
cur_freq = entry.frequency
#select nco
nco_select = (list(freqs)).index(entry.frequency) + 1
cur_freq = entry.frequency
if USE_PHASE_OFFSET_INSTRUCTION and (entry.length > 0) and (cur_phase != entry.phase):
phase_freq_cmds.append( ModulationCommand("SET_PHASE", nco_select, phase=entry.phase) )
mod_seq.append( ModulationCommand("SET_PHASE", nco_select, phase=entry.phase) )
cur_phase = entry.phase
for cmd in phase_freq_cmds:
mod_seq.append(cmd)
#now apply modulation for count command and waveform command, if non-zero length
if entry.length > 0:
mod_seq.append(entry)
# if we have a modulate waveform modulate pattern and there is no pending frame update we can append length to previous modulation command
if (len(mod_seq) > 1) and (isinstance(mod_seq[-1], Compiler.Waveform)) and (isinstance(mod_seq[-2], ModulationCommand)) and (mod_seq[-2].instruction == "MODULATE") \
and mod_seq[-1].frequency == cur_freq and not pending_frame_update:
and mod_seq[-1].frequency == freqs[mod_seq[-2].nco_select - 1] and not pending_frame_update:
mod_seq[-2].length += entry.length
else:
mod_seq.append( ModulationCommand("MODULATE", nco_select, length=entry.length))
mod_seq.append( ModulationCommand("MODULATE", nco_select, length = entry.length))
pending_frame_update = False
#now apply non-zero frame changes after so it is applied at end
if entry.frameChange != 0:
Expand Down

0 comments on commit a5b8c16

Please sign in to comment.