Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ E. Huegler, J. C. Hill, and D. H. Meyer, An agile radio-frequency source using i
| Single Stepping | 4 $\mu s$ | 6 $\mu s$ | 8 $\mu s$ | 10 $\mu s$ |
| Sweep Mode | 8 $\mu s$ | 12 $\mu s$ | 16 $\mu s$ | 20 $\mu s$ |

- The number of instructions you can store in the table depends no the type of sweep being performed and the number of channels being used.
- The number of instructions you can store in the table depends on the type of sweep being performed and the number of channels being used. The table below was obtained with a total allocated RAM of 243 KB:

| Table Mode | 1 Channel | 2 Channel | 3 Channel | 4 Channel |
|-----------------------------|-----------|-----------|-----------|-----------|
| Single Stepping (Ext Timer) | 16656 | 8615 | 5810 | 4383 |
| Sweep Mode (Ext Timer) | 8327 | 4234 | 2838 | 2135 |
| Single Stepping (Int Timer) | 5000 | 5000 | 5000 | 4032 |
| Sweep Mode (Int Timer) | 5000 | 3895 | 2611 | 1964 |
| Single Stepping (Ext Timer) | 16587 | 8579 | 5786 | 4365 |
| Sweep Mode (Ext Timer) | 8579 | 4364 | 2927 | 2201 |
| Single Stepping (Int Timer) | 5000 | 5000 | 5000 | 4014 |
| Sweep Mode (Int Timer) | 5000 | 4014 | 2691 | 2024 |

## How to flash the firmware

Expand Down
13 changes: 8 additions & 5 deletions dds-sweeper/dds-sweeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int clk_mode = INTERNAL;
// PIO VALUES IT IS LOOKING FOR
#define UPDATE 0

#define MAX_SIZE 245760
#define MAX_SIZE 248832 // 243 * 1024
#define TIMERS 5000
#define TIMING_OFFSET (MAX_SIZE - TIMERS * 4)

Expand Down Expand Up @@ -104,6 +104,10 @@ uint stop_ins = 0; // stop/repeat being unset denoted by 0
// order is single step, amp, freq, phase, amp2, freq2, phase2
uint BYTES_PER_INS[] = {8, 7, 13, 7, 13, 17, 13};

// instruction sizes after backend processing
// order is single step, amp, freq, phase, amp2, freq2, phase2
uint SIZE_EACH_INS[] = {14, 28, 29, 27, 36, 36, 36};

// =============================================================================
// Utility Functions
// =============================================================================
Expand Down Expand Up @@ -800,7 +804,7 @@ void get_instructions(void) {
return;
}

// Loop through each instruction line to get raw bytes
// Loop through each instruction line to get raw bytes
for (uint i = 0; i < num_ins; i++) {
uint offset = i * step;
fast_serial_printf("Offset: %u | ", offset);
Expand Down Expand Up @@ -1117,8 +1121,7 @@ void loop() {
} else if (type > PHASE2_MODE) {
fast_serial_printf("Invalid Type - table type must be in range 0-6\n");
} else {
uint8_t sizes[] = {14, 28, 29, 27, 36, 36, 36};
INS_SIZE = sizes[type];
INS_SIZE = SIZE_EACH_INS[type];
ad9959.sweep_type = type;
timing = _timing;

Expand Down Expand Up @@ -1475,7 +1478,7 @@ void loop() {
if(ins_count > 0){
fast_serial_read(readstring, ins_count*bytes_per_ins*ad9959.channels);

for (int i = 0; i < ins_per_buffer; i++) {
for (int i = 0; i < ins_count; i++) {
for(int j = 0; j < ad9959.channels; j++) {
uint byte_offset = bytes_per_ins*(i*ad9959.channels + j);
if (ad9959.sweep_type == SS_MODE) {
Expand Down
102 changes: 102 additions & 0 deletions testing/BinaryRoutines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import numpy as np

class BinaryRoutines():
"""
Class handler for `setb` command to send binary tables to the dds-sweeper
"""

def __init__(self, conn):
self.conn = conn
self.mirror_channels = False
self.debug_run = True
self.MAX_SIZE = 256
self.instructions = None
self.timing_mode = None

def send(self, command: str, echo = True):
if command[-1] != '\n':
command += '\n'

self.conn.write(command.encode())
if echo:
print(self.catch_response())

def catch_response(self):
resp = self.conn.readline().decode().strip()
return resp

def assert_OK(self):
resp = self.conn.readline().decode().strip()
assert resp == 'ok', 'Expected "ok", received "%s"' % resp

def debug_on(self):
self.conn.write(b'debug on\n')
self.assert_OK()

def debug_off(self):
self.conn.write(b'debug off\n')
self.assert_OK()

def set_mode(self, sweep_mode: int, timing_mode: int, num_channels: int):
self.conn.write(b'reset\n')
self.assert_OK()

self.timing_mode = timing_mode
self.conn.write(b'mode %d %d \n' % (sweep_mode, timing_mode))
self.assert_OK()
self.conn.write(b'setchannels %d\n' % num_channels)
self.assert_OK()
if self.debug_run == True:
print('sending commands to %d channels' % num_channels)

def allocate(self, start_address: int, instructions: np.ndarray):
self.conn.write(b'setb %d %d\n' % (start_address, len(instructions)))
response = self.conn.readline().decode()
if not response.startswith('ready'):
response += ''.join([r.decode() for r in self.conn.readlines()])
raise Exception(f'setb command failed, response: {repr(response)}')
if self.debug_run == True:
print(f'Got response: {response}')

def table_to_memory(self, instructions: np.ndarray):
self.conn.write(instructions.tobytes())
self.assert_OK(), 'table not written correctly'
if self.debug_run == True:
print('table written to memory')

def end_table(self, instructions: np.ndarray):
self.conn.write(b'set 4 %d\n' % len(instructions))
self.assert_OK(), 'table not stopped correctly'
self.instructions = instructions
if self.debug_run == True:
print('table end command sent')

def start_routine(self, hwstart = False):
if hwstart:
self.conn.write(b'hwstart\n')
else:
self.conn.write(b'start\n')
self.assert_OK(), 'table did not start'
if self.debug_run == True:
print('table executed')

def read_table(self, indices = None):
self.conn.write(b'readtable\n')
for i in range(self.instructions.size + 2): # plus two to catch header and footer
resp = self.catch_response()
print(resp)
if "End of" in resp:
break
elif "Cannot" in resp:
break
elif len(resp) == 0:
break

def get_memory_layout(self):
self.conn.write(b'getmode\n')
mode = self.catch_response()
channels = self.catch_response()
memory_layout = self.catch_response()
print(f"mode {mode}")
print(channels)
print(memory_layout)
Loading