Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ build*/*
.vscode
.DS_Store
cmake-*
pico_sdk_import.cmake
pico_sdk_import.cmake
*.pyc
18 changes: 10 additions & 8 deletions prawn_do/prawn_do.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
#include "fast_serial.h"

#define LED_PIN 25
// output pins to use, much match pio
// output pins to use, must match pio
#define OUTPUT_PIN_BASE 0
#define OUTPUT_WIDTH 16
// mask which bits we are using
uint32_t output_mask = ((1 << OUTPUT_WIDTH) - 1) << OUTPUT_PIN_BASE;
// command type enum
enum COMMAND {
BUFFERED_HWSTART = 3 << OUTPUT_WIDTH,
BUFFERED = 1 << OUTPUT_WIDTH,
HWSTART = 2 << OUTPUT_WIDTH,
BUFFERED_HWSTART = BUFFERED | HWSTART,
MANUAL = 0
};

Expand Down Expand Up @@ -54,7 +55,7 @@ int status;
#define EXTERNAL 1
int clk_status = INTERNAL;
unsigned short debug = 0;
const char ver[6] = "1.3.0";
const char ver[6] = "1.3.1";

// Mutex for status
static mutex_t status_mutex;
Expand Down Expand Up @@ -200,7 +201,7 @@ void core1_entry() {

if(command & BUFFERED){
// buffered execution
uint32_t hwstart = (command & BUFFERED_HWSTART);
uint32_t hwstart = !!(command & HWSTART);

set_status(TRANSITION_TO_RUNNING);
if(debug){
Expand Down Expand Up @@ -253,10 +254,7 @@ void core1_entry() {
else{
// manual update
uint32_t manual_state = command;
// put new state into the TX FIFO
pio_sm_put_blocking(pio, sm, manual_state);
// pull FIFO into scratch register and update pins
pio_sm_exec_wait_blocking(pio, sm, pio_encode_out(pio_pins, 32));
pio_sm_set_pins_with_mask(pio, sm, manual_state, output_mask);
if(debug){
fast_serial_printf("Output commanded: %x\r\n", manual_state);
}
Expand Down Expand Up @@ -419,6 +417,10 @@ int main(){
// reset if we just set a stop command (two reps=0 commands in a row)
do_cmd_count = do_cmd_addr + 2;
}
if (debug){
fast_serial_printf("NumNZ: %x, Arr Idx: %x, Output: %x, Reps: %x\r\n",
do_cmd_count, do_cmd_addr, output, reps);
}
fast_serial_printf("ok\r\n");
}
}
Expand Down
75 changes: 75 additions & 0 deletions testing/KeysightScope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import pyvisa

class KeysightScope:
"""
Helper class using pyvisa for a USB connected Keysight Oscilloscope
"""
def __init__(self,
addr='USB?*::INSTR',
timeout=1,
termination='\n'
):
rm = pyvisa.ResourceManager()
devs = rm.list_resources(addr)
assert len(devs), "pyvisa didn't find any connected devices matching " + addr
self.dev = rm.open_resource(devs[0])
self.dev.timeout = 15_000 * timeout
self.dev.read_termination = termination
self.idn = self.dev.query('*IDN?')
self.read = self.dev.read
self.write = self.dev.write
self.query = self.dev.query

def _get_screenshot(self, verbose=False):
if verbose == True:
print('Acquiring screen image...')
return(self.dev.query_binary_values(':DISPlay:DATA? PNG, COLor', datatype='s'))

def get_screenshot(self):

result = self._get_screenshot()

return bytes(result)

def save_screenshot(self, filepath: str, verbose=False, inksaver=False):
if verbose == True:
print('Saving screen image...')
result = self._get_screenshot()

# Keysight scope defaults to inksaving for image save
if inksaver == True:
self.dev.write(':HARDcopy:INKSaver 1')
else:
self.dev.write(':HARDcopy:INKSaver OFF')

with open(f'{filepath}', 'wb+') as ofile:
ofile.write(bytes(result))

def set_time_delay(self, time: float):

self.write(f':TIMebase:DELay {time}')

def set_time_scale(self, time: float):
self.write(f':TIMebase:SCALe {time}')

def annotate_screen(self, message: str):
self.write(f':DISPlay:ANNotation:TEXT "{message}"')

def set_math_scale(self, scale: float):
self.write(f'FUNCtion:SCALe {scale}')

def set_math_offset(self, offset: float):
self.write(f'FUNCtion:OFFSet {offset}')

def channel_state(self, channel: int, state: int):
"""
Turn on or off a channel
state: int (ON: 1 or OFF: 0)
"""
self.write(f':CHANnel{channel}:DISPlay {state}')

def set_channel_offset(self, channel: int, y_offset: float):
self.write(f':CHANnel{channel}:OFFSet {y_offset}')

def set_channel_scale(self, channel: int, y_scale: float):
self.write(f':CHANnel{channel}:SCALe {y_scale}')
554 changes: 554 additions & 0 deletions testing/basic_tests.ipynb

Large diffs are not rendered by default.