Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scope] Configure WaveRunner from config file #342

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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: 3 additions & 0 deletions capture/capture_aes.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def setup(cfg: dict, project: Path):
sparsing = cfg[scope_type].get("sparsing"),
scope_gain = cfg[scope_type].get("scope_gain"),
pll_frequency = cfg["target"]["pll_frequency"],
channel_configs = cfg[scope_type].get("channel_configs"),
trigger_config = cfg[scope_type].get("trigger_config"),
timebase_config = cfg[scope_type].get("timebase_config")
)
scope = Scope(scope_cfg)

Expand Down
3 changes: 3 additions & 0 deletions capture/capture_kmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def setup(cfg: dict, project: Path):
sparsing = cfg[scope_type].get("sparsing"),
scope_gain = cfg[scope_type].get("scope_gain"),
pll_frequency = cfg["target"]["pll_frequency"],
channel_configs = cfg[scope_type].get("channel_configs"),
trigger_config = cfg[scope_type].get("trigger_config"),
timebase_config = cfg[scope_type].get("timebase_config")
)
scope = Scope(scope_cfg)

Expand Down
23 changes: 13 additions & 10 deletions capture/capture_otbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,21 @@ def setup(cfg: dict, project: Path):

# Create scope config & setup scope.
scope_cfg = ScopeConfig(
scope_type=scope_type,
scope_type = scope_type,
batch_mode = batch,
bit = cfg[scope_type].get("bit"),
acqu_channel=cfg[scope_type].get("channel"),
ip=cfg[scope_type].get("waverunner_ip"),
num_samples=cfg[scope_type]["num_samples"],
offset_samples=cfg[scope_type]["offset_samples"],
sampling_rate=cfg[scope_type].get("sampling_rate"),
num_segments=cfg[scope_type]["num_segments"],
sparsing=cfg[scope_type].get("sparsing"),
scope_gain=cfg[scope_type].get("scope_gain"),
pll_frequency=cfg["target"]["pll_frequency"],
acqu_channel = cfg[scope_type].get("channel"),
ip = cfg[scope_type].get("waverunner_ip"),
num_samples = cfg[scope_type]["num_samples"],
offset_samples = cfg[scope_type]["offset_samples"],
sampling_rate = cfg[scope_type].get("sampling_rate"),
num_segments = cfg[scope_type].get("num_segments"),
sparsing = cfg[scope_type].get("sparsing"),
scope_gain = cfg[scope_type].get("scope_gain"),
pll_frequency = cfg["target"]["pll_frequency"],
channel_configs = cfg[scope_type].get("channel_configs"),
trigger_config = cfg[scope_type].get("trigger_config"),
timebase_config = cfg[scope_type].get("timebase_config")
)
scope = Scope(scope_cfg)

Expand Down
3 changes: 3 additions & 0 deletions capture/capture_sha3.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def setup(cfg: dict, project: Path):
sparsing = cfg[scope_type].get("sparsing"),
scope_gain = cfg[scope_type].get("scope_gain"),
pll_frequency = cfg["target"]["pll_frequency"],
channel_configs = cfg[scope_type].get("channel_configs"),
trigger_config = cfg[scope_type].get("trigger_config"),
timebase_config = cfg[scope_type].get("timebase_config")
)
scope = Scope(scope_cfg)

Expand Down
24 changes: 23 additions & 1 deletion capture/scopes/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Optional

from scopes.chipwhisperer.husky import Husky
from scopes.waverunner.waverunner import WaveRunner
from scopes.waverunner.waverunner import Channel, Timebase, Trigger, WaveRunner


@dataclass
Expand All @@ -28,6 +28,9 @@ class ScopeConfig:
scope_gain: Optional[float] = 1
pll_frequency: Optional[int] = 1
sampling_rate: Optional[int] = 0
channel_configs: Optional[list] = None
trigger_config: Optional[str] = None
timebase_config: Optional[str] = None


class Scope:
Expand Down Expand Up @@ -90,6 +93,25 @@ def _init_scope(self):
first_point = self.scope_cfg.offset_samples,
acqu_channel = self.scope_cfg.acqu_channel
)
# If a user defined config is provided, configure the channel,
# timebase, and the trigger.
if self.scope_cfg.channel_configs is not None:
for channel_config in self.scope_cfg.channel_configs:
scope.configure_channel(
Channel(name = channel_config["name"],
trace_enable = channel_config["trace_enable"],
vdiv = channel_config["vdiv"],
offset = channel_config["offset"]))
if self.scope_cfg.timebase_config is not None:
scope.configure_timebase(
Timebase(tdiv = self.scope_cfg.timebase_config["tdiv"],
delay = self.scope_cfg.timebase_config["delay"]))
if self.scope_cfg.trigger_config is not None:
scope.configure_trigger(
Trigger(channel = self.scope_cfg.trigger_config["channel"],
edge = self.scope_cfg.trigger_config["edge"],
coupling = self.scope_cfg.trigger_config["coupling"],
level = self.scope_cfg.trigger_config["level"]))
return scope
else:
raise RuntimeError("Error: No WaveRunner IP provided!")
Expand Down
73 changes: 73 additions & 0 deletions capture/scopes/waverunner/waverunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,40 @@
"""Support for capturing traces using LeCroy WaveRunner 9104."""

import re
from dataclasses import dataclass

import numpy as np
import vxi11


@dataclass
class Channel:
""" Scope configuration for a channel.
"""
name: str
trace_enable: str
vdiv: str
offset: str


@dataclass
class Timebase:
""" Timebase configuration.
"""
tdiv: str
delay: str


@dataclass
class Trigger:
""" Trigger configuration.
"""
channel: str
edge: str
coupling: str
level: str


class _Timeout:
"""Helper class for setting scoped timeout values."""

Expand Down Expand Up @@ -385,6 +414,50 @@ def _parse_waveform(self, data):
waves = waves[:, 0:self.num_samples]
return waves

def configure_channel(self, channel: Channel):
"""Configures a channel on the scope.
"""
commands = [
# Enable / disable visualization of trace. Disabling increases the
# capture rate.
f"{channel.name}:TRA {channel.trace_enable}",
# Time / division.
f"TDIV {channel.tdiv}",
# Trigger delay.
f"TRDL {channel.delay}",
# Volts / division.
f"{channel.name}:VDIV {channel.vdiv}",
# DC offset.
f"{channel.name}:OFST {channel.offset}",
]
self._write(";".join(commands))

def configure_timebase(self, timebase: Timebase):
"""Configures the timebase of the scope.
"""
commands = [
# Time / division.
f"TDIV {timebase.tdiv}",
# Trigger delay.
f"TRDL {timebase.delay}",
]
self._write(";".join(commands))

def configure_trigger(self, trigger: Trigger):
"""Configures the trigger on the scope.
"""
commands = [
# Select trigger: edge, channel 2, no hold-off.
"TRSE EDGE,SR,C2,HT,OFF",
# Rising edge.
f"{trigger.channel}:TRSL {trigger.edge}",
# DC coupling.
f"{trigger.channel}:TRCP {trigger.coupling}",
# Trigger level.
f"{trigger.channel}:TRLV {trigger.level}",
]
self._write(";".join(commands))

def capture_and_transfer_waves(self):
"""Waits until the acqu is complete and transfers waveforms.

Expand Down
Loading