examples: port to nac3

This commit is contained in:
2026-03-16 21:36:37 +08:00
parent 3e9505b342
commit 227110f55a
4 changed files with 43 additions and 19 deletions

View File

@@ -1,7 +1,12 @@
from artiq.experiment import *
from artiq.coredevice.core import Core
from artiq.coredevice.ttl import TTLOut
@compile
class BlinkForever(EnvExperiment):
core: KernelInvariant[Core]
led0: KernelInvariant[TTLOut]
def build(self):
self.setattr_device("core")
self.setattr_device("led0")
@@ -10,5 +15,5 @@ class BlinkForever(EnvExperiment):
def run(self):
self.core.reset()
while True:
self.led0.pulse(100*ms)
delay(100*ms)
self.led0.pulse(100.*ms)
self.core.delay(100.*ms)

View File

@@ -1,6 +1,14 @@
from artiq.experiment import *
from artiq.coredevice.core import Core
from artiq.coredevice.dma import CoreDMA
from artiq.coredevice.ttl import TTLOut
@compile
class DMAPulses(EnvExperiment):
core: KernelInvariant[Core]
core_dma: KernelInvariant[CoreDMA]
led0: KernelInvariant[TTLOut]
def build(self):
self.setattr_device("core")
self.setattr_device("core_dma")
@@ -8,11 +16,12 @@ class DMAPulses(EnvExperiment):
@kernel
def record(self):
with self.core_dma.record("pulse"):
delay(200*ms)
self.core_dma.prepare_record("pulse")
with self.core_dma.recorder:
self.core.delay(200.*ms)
# all RTIO operations now go to the "pulse"
# DMA buffer, instead of being executed immediately.
self.led0.pulse(500*ms)
self.led0.pulse(500.*ms)
@kernel

View File

@@ -1,15 +1,20 @@
from artiq.experiment import *
from artiq.language.core import TerminationRequested
from artiq.coredevice.core import Core
@compile
class ExceptionDemo(EnvExperiment):
core: KernelInvariant[Core]
def build(self):
self.setattr_device("core")
self.setattr_device("led0")
@rpc
def foo(self):
print("raise error")
raise Exception
@rpc
def termination(self):
raise TerminationRequested
@@ -24,15 +29,15 @@ class ExceptionDemo(EnvExperiment):
try:
self.foo()
except ValueError as e:
print("should not trigger this")
print_rpc("should not trigger this")
except:
print("catch all")
print_rpc("catch all")
try:
self.remote()
except:
print("Error!")
print_rpc("Error!")
print("Uncaught error at last")
print_rpc("Uncaught error at last")
self.termination()

View File

@@ -1,16 +1,21 @@
import sys
from numpy import int32
from artiq.experiment import *
from artiq.coredevice.core import Core
@compile
class Mandelbrot(EnvExperiment):
"""Mandelbrot set demo"""
core: KernelInvariant[Core]
def build(self):
self.setattr_device("core")
@rpc(flags={"async"})
def col(self, i):
def col(self, i: int32):
sys.stdout.write(" .,-:;i+hHM$*#@ "[i])
@rpc(flags={"async"})
@@ -18,7 +23,7 @@ class Mandelbrot(EnvExperiment):
print("")
@rpc(flags={"async"})
def prt(self, x):
def prt(self, x: int32):
print(x)
@@ -29,22 +34,22 @@ class Mandelbrot(EnvExperiment):
maxX = 1.0
width = 78
height = 36
aspectRatio = 2
aspectRatio = 2.
yScale = (maxX-minX)*(height/width)*aspectRatio
yScale = (maxX-minX)*(float(height)/float(width))*aspectRatio
for y in range(height):
for x in range(width):
c_r = minX+x*(maxX-minX)/width
c_i = y*yScale/height-yScale/2
c_r = minX+float(x)*(maxX-minX)/float(width)
c_i = float(y)*yScale/float(height)-yScale/2.
z_r = c_r
z_i = c_i
i = 0
for i in range(16):
if z_r*z_r + z_i*z_i > 4:
if z_r*z_r + z_i*z_i > 4.:
break
new_z_r = (z_r*z_r)-(z_i*z_i) + c_r
z_i = 2*z_r*z_i + c_i
z_i = 2.*z_r*z_i + c_i
z_r = new_z_r
self.col(i)
self.row()