Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 021d0d312e51
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4558fb3e3381
Choose a head ref
  • 2 commits
  • 8 files changed
  • 1 contributor

Commits on Feb 16, 2015

  1. Copy the full SHA
    61dc177 View commit details
  2. Copy the full SHA
    4558fb3 View commit details
6 changes: 3 additions & 3 deletions artiq/devices/lda/driver.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ class HidError(Exception):


class Ldasim:
"""Lab Brick Digital Attenuator simulation controller.
"""Lab Brick Digital Attenuator simulation driver.
"""

def __init__(self):
@@ -56,9 +56,9 @@ def set_attenuation(self, attenuation):


class Lda:
"""Lab Brick Digital Attenuator controller.
"""Lab Brick Digital Attenuator driver.
This controller depends on the hidapi library.
This driver depends on the hidapi library.
On Linux you should install hidapi-libusb shared library in a directory
listed in your LD_LIBRARY_PATH or in the conventional places (/usr/lib,
144 changes: 1 addition & 143 deletions artiq/devices/pdq2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,143 +1 @@
from artiq.language.core import *
from artiq.language.db import *
from artiq.language.units import *
from artiq.coredevice import rtio


frame_setup = 20*ns
trigger_duration = 50*ns
frame_wait = 20*ns
sample_period = 10*us # FIXME: check this


class SegmentSequenceError(Exception):
pass


class FrameActiveError(Exception):
pass


class FrameCloseError(Exception):
pass


class _Segment:
def __init__(self, frame, sn, duration, host_data):
self.core = frame.core
self.frame = frame
self.sn = sn
self.duration = duration
self.host_data = host_data

@kernel
def advance(self):
if self.frame.pdq.current_frame != self.frame.fn:
raise FrameActiveError
if self.frame.pdq.next_sn != self.sn:
raise SegmentSequenceError
self.frame.pdq.next_sn += 1

t = time_to_cycles(now())
self.frame.pdq.trigger.on(t)
self.frame.pdq.trigger.off(t + time_to_cycles(trigger_duration))
delay(self.duration)


class _Frame:
def __init__(self, core):
self.core = core
self.segment_count = 0
self.closed = False

def append(self, t, u, trigger=False, name=None):
if self.closed:
raise FrameCloseError
sn = self.segment_count
duration = (t[-1] - t[0])*sample_period
segment = _Segment(self, sn, duration, (t, u, trigger))
if name is None:
# TODO
raise NotImplementedError("Anonymous segments are not supported yet")
else:
if hasattr(self, name):
raise NameError("Segment name already exists")
setattr(self, name, segment)
self.segment_count += 1

def close(self):
if self.closed:
raise FrameCloseError
self.closed = True

@kernel
def begin(self):
if self.pdq.current_frame >= 0:
raise FrameActiveError
self.pdq.current_frame = self.fn
self.pdq.next_sn = 0

t = (time_to_cycles(now())
- time_to_cycles(frame_setup + trigger_duration + frame_wait))
self.pdq.frame0.set_value(t, self.fn & 1)
self.pdq.frame1.set_value(t, (self.fn & 2) >> 1)
self.pdq.frame2.set_value(t, (self.fn & 4) >> 2)
t += time_to_cycles(frame_setup)
self.pdq.trigger.on(t)
self.pdq.trigger.off(t + time_to_cycles(trigger_duration))

@kernel
def advance(self):
# TODO
raise NotImplementedError

@kernel
def finish(self):
if self.pdq.current_frame != self.fn:
raise FrameActiveError
if self.pdq.next_sn != self.segment_count:
raise FrameActiveError
self.pdq.current_frame = -1
self.pdq.next_sn = -1

def _prepare(self, pdq, fn):
if not self.closed:
raise FrameCloseError
self.pdq = pdq
self.fn = fn

def _invalidate(self):
del self.pdq
del self.fn


class CompoundPDQ2(AutoDB):
class DBKeys:
ids = Argument()
rtio_trigger = Argument()
rtio_frame = Argument()

def build(self):
self.trigger = rtio.LLRTIOOut(core=self.core, channel=self.rtio_trigger)
self.frame0 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[0])
self.frame1 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[1])
self.frame2 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[2])

self.frames = []
self.current_frame = -1
self.next_sn = -1

def create_frame(self):
return _Frame(self.core)

def prepare(self, *frames):
# prevent previous frames and their segments from
# being (incorrectly) used again
for frame in self.frames:
frame._invalidate()

self.frames = list(frames)
for fn, frame in enumerate(frames):
frame._prepare(self, fn)

# TODO: upload to PDQ2 devices
from artiq.devices.pdq2.mediator import *
143 changes: 143 additions & 0 deletions artiq/devices/pdq2/mediator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
from artiq.language.core import *
from artiq.language.db import *
from artiq.language.units import *
from artiq.coredevice import rtio


frame_setup = 20*ns
trigger_duration = 50*ns
frame_wait = 20*ns
sample_period = 10*us # FIXME: check this


class SegmentSequenceError(Exception):
pass


class FrameActiveError(Exception):
pass


class FrameCloseError(Exception):
pass


class _Segment:
def __init__(self, frame, sn, duration, host_data):
self.core = frame.core
self.frame = frame
self.sn = sn
self.duration = duration
self.host_data = host_data

@kernel
def advance(self):
if self.frame.pdq.current_frame != self.frame.fn:
raise FrameActiveError
if self.frame.pdq.next_sn != self.sn:
raise SegmentSequenceError
self.frame.pdq.next_sn += 1

t = time_to_cycles(now())
self.frame.pdq.trigger.on(t)
self.frame.pdq.trigger.off(t + time_to_cycles(trigger_duration))
delay(self.duration)


class _Frame:
def __init__(self, core):
self.core = core
self.segment_count = 0
self.closed = False

def append(self, t, u, trigger=False, name=None):
if self.closed:
raise FrameCloseError
sn = self.segment_count
duration = (t[-1] - t[0])*sample_period
segment = _Segment(self, sn, duration, (t, u, trigger))
if name is None:
# TODO
raise NotImplementedError("Anonymous segments are not supported yet")
else:
if hasattr(self, name):
raise NameError("Segment name already exists")
setattr(self, name, segment)
self.segment_count += 1

def close(self):
if self.closed:
raise FrameCloseError
self.closed = True

@kernel
def begin(self):
if self.pdq.current_frame >= 0:
raise FrameActiveError
self.pdq.current_frame = self.fn
self.pdq.next_sn = 0

t = (time_to_cycles(now())
- time_to_cycles(frame_setup + trigger_duration + frame_wait))
self.pdq.frame0.set_value(t, self.fn & 1)
self.pdq.frame1.set_value(t, (self.fn & 2) >> 1)
self.pdq.frame2.set_value(t, (self.fn & 4) >> 2)
t += time_to_cycles(frame_setup)
self.pdq.trigger.on(t)
self.pdq.trigger.off(t + time_to_cycles(trigger_duration))

@kernel
def advance(self):
# TODO
raise NotImplementedError

@kernel
def finish(self):
if self.pdq.current_frame != self.fn:
raise FrameActiveError
if self.pdq.next_sn != self.segment_count:
raise FrameActiveError
self.pdq.current_frame = -1
self.pdq.next_sn = -1

def _prepare(self, pdq, fn):
if not self.closed:
raise FrameCloseError
self.pdq = pdq
self.fn = fn

def _invalidate(self):
del self.pdq
del self.fn


class CompoundPDQ2(AutoDB):
class DBKeys:
ids = Argument()
rtio_trigger = Argument()
rtio_frame = Argument()

def build(self):
self.trigger = rtio.LLRTIOOut(core=self.core, channel=self.rtio_trigger)
self.frame0 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[0])
self.frame1 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[1])
self.frame2 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[2])

self.frames = []
self.current_frame = -1
self.next_sn = -1

def create_frame(self):
return _Frame(self.core)

def prepare(self, *frames):
# prevent previous frames and their segments from
# being (incorrectly) used again
for frame in self.frames:
frame._invalidate()

self.frames = list(frames)
for fn, frame in enumerate(frames):
frame._prepare(self, fn)

# TODO: upload to PDQ2 devices
3 changes: 3 additions & 0 deletions artiq/language/units.py
Original file line number Diff line number Diff line change
@@ -117,6 +117,9 @@ def __repr__(self):
else:
return str(r_amount) + " " + self.unit

def __float__(self):
return float(self.amount)

# mul/div
def _binop(self, other, opf_name, dim_function):
opf = getattr(self.amount, opf_name)
Loading