Skip to content

Commit

Permalink
Merge pull request #183 from BBN-Q/feature/4-ncos
Browse files Browse the repository at this point in the history
Support for 4 NCOs on APS2
  • Loading branch information
Diego Ristè committed Feb 25, 2019
2 parents 6f62640 + ae4796a commit 53e5f16
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions QGL/drivers/APS2Pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
MAX_NUM_INSTRUCTIONS = 2**26
MAX_REPEAT_COUNT = 2**16 - 1
MAX_TRIGGER_COUNT = 2**32 - 1
NUM_NCO = 4

# instruction encodings
WFM = 0x0
Expand Down Expand Up @@ -583,13 +584,19 @@ def to_instruction(self, write_flag=True, label=None):
NCO_SELECT_OP_OFFSET = 40
MODULATION_CLOCK = 300e6

nco_select_bits = {1 : 0b0001,
2 : 0b0010,
3 : 0b0100,
4 : 0b1000,
15: 0b1111}[self.nco_select]

op_code_map = {"MODULATE": 0x0,
"RESET_PHASE": 0x2,
"SET_FREQ": 0x6,
"SET_PHASE": 0xa,
"UPDATE_FRAME": 0xe}
payload = (op_code_map[self.instruction] << MODULATOR_OP_OFFSET) | (
self.nco_select << NCO_SELECT_OP_OFFSET)
(nco_select_bits) << NCO_SELECT_OP_OFFSET)
if self.instruction == "MODULATE":
#zero-indexed quad count
payload |= np.uint32(self.length / ADDRESS_UNIT - 1)
Expand Down Expand Up @@ -617,8 +624,8 @@ def inject_modulation_cmds(seqs):
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.")
if len(freqs) > NUM_NCO:
raise Exception("Max {} frequencies on the same channel allowed.".format(NUM_NCO))
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 @@ -643,7 +650,7 @@ def inject_modulation_cmds(seqs):
#heuristic to insert phase reset before trigger if we have modulation commands
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))
mod_seq.append(ModulationCommand("RESET_PHASE", 0xF))
for nco_ind, freq in enumerate(freqs):
mod_seq.append( ModulationCommand("SET_FREQ", nco_ind + 1, frequency = -freq) )
elif isinstance(entry, ControlFlow.Return):
Expand Down Expand Up @@ -1140,7 +1147,6 @@ def start_new_seq():
1.0 /
MAX_WAVEFORM_VALUE) * FID['/chan_2/waveforms'].value.flatten()
instructions = FID['/chan_1/instructions'].value.flatten()
NUM_NCO = 2
freq = np.zeros(NUM_NCO) #radians per timestep
phase = np.zeros(NUM_NCO)
frame = np.zeros(NUM_NCO)
Expand Down Expand Up @@ -1267,7 +1273,6 @@ def start_new_seq():
seqs['ch2'][ct] = mod_ch2

del seqs['mod_phase']

return seqs


Expand Down

0 comments on commit 53e5f16

Please sign in to comment.