ttl: factor out examples

Also, the ttl timestamp_mu method has a parameter.
This commit is contained in:
occheung 2022-01-20 14:51:47 +08:00
parent 611a0009af
commit 9488a03aa4
4 changed files with 111 additions and 175 deletions

View File

@ -4,8 +4,6 @@
\usepackage{minted} \usepackage{minted}
\usepackage{tcolorbox} \usepackage{tcolorbox}
\usepackage{etoolbox} \usepackage{etoolbox}
\BeforeBeginEnvironment{minted}{\begin{tcolorbox}[colback=white]}%
\AfterEndEnvironment{minted}{\end{tcolorbox}}%
\usepackage[justification=centering]{caption} \usepackage[justification=centering]{caption}
@ -68,6 +66,11 @@ The card support a minimum pulse width of 3ns.
\newcommand*{\MyLabel}[3][2cm]{\parbox{#1}{\centering #2 \\ #3}} \newcommand*{\MyLabel}[3][2cm]{\parbox{#1}{\centering #2 \\ #3}}
\newcommand*{\MymyLabel}[3][4cm]{\parbox{#1}{\centering #2 \\ #3}} \newcommand*{\MymyLabel}[3][4cm]{\parbox{#1}{\centering #2 \\ #3}}
\newcommand{\repeatfootnote}[1]{\textsuperscript{\ref{#1}}} \newcommand{\repeatfootnote}[1]{\textsuperscript{\ref{#1}}}
\newcommand{\inputcolorboxminted}[2]{%
\begin{tcolorbox}[colback=white]
\inputminted[#1, gobble=4]{python}{#2}
\end{tcolorbox}
}
\begin{figure}[h] \begin{figure}[h]
\centering \centering
@ -434,78 +437,27 @@ Timing accuracy in the examples below is well under 1 nanosecond thanks to the A
\subsection{One pulse per second} \subsection{One pulse per second}
The channel should be configured as output in both the gateware and hardware. The channel should be configured as output in both the gateware and hardware.
\inputcolorboxminted{firstline=9,lastline=15}{examples/ttl.py}
\begin{minted}{python}
@kernel
def run(self):
self.core.reset()
while True:
self.ttl0.pulse(500*ms)
delay(500*ms)
\end{minted}
\newpage \newpage
\subsection{Morse code} \subsection{Morse code}
This example demonstrates some basic algorithmic features of the ARTIQ-Python language. This example demonstrates some basic algorithmic features of the ARTIQ-Python language.
\begin{minted}{python} \inputcolorboxminted{firstline=23,lastline=40}{examples/ttl.py}
def prepare(self):
# As of ARTIQ-6, the ARTIQ compiler has limited string handling
# capabilities, so we pass a list of integers instead.
message = ".- .-. - .. --.-"
self.commands = [{".": 1, "-": 2, " ": 3}[c] for c in message]
@kernel
def run(self):
self.core.reset()
for cmd in self.commands:
if cmd == 1:
self.led.pulse(100*ms)
delay(100*ms)
if cmd == 2:
self.led.pulse(300*ms)
delay(100*ms)
if cmd == 3:
delay(700*ms)
\end{minted}
\subsection{Counting rising edges in a 1ms window} \subsection{Counting rising edges in a 1ms window}
The channel should be configured as input in both the gateware and hardware. The channel should be configured as input in both the gateware and hardware.
\inputcolorboxminted{firstline=48,lastline=53}{examples/ttl.py}
\begin{minted}{python}
@kernel
def run(self):
self.core.reset()
gate_end_mu = self.ttl0.gate_rising(1*ms)
counts = self.ttl0.count()
print(counts)
\end{minted}
This example code uses the software counter, which has a maximum count rate of approximately 1 million events per second. This example code uses the software counter, which has a maximum count rate of approximately 1 million events per second.
If the gateware counter is enabled on the TTL channel, it can typically count up to 125 million events per second: If the gateware counter is enabled on the TTL channel, it can typically count up to 125 million events per second:
\begin{minted}{python} \inputcolorboxminted{firstline=61,lastline=66}{examples/ttl.py}
@kernel
def run(self):
self.core.reset()
self.edgecounter0.gate_rising(1*ms)
counts = self.edgecounter0.fetch_count()
print(counts)
\end{minted}
\newpage \newpage
\subsection{Responding to an external trigger} \subsection{Responding to an external trigger}
One channel needs to be configured as input, and the other as output. One channel needs to be configured as input, and the other as output.
\inputcolorboxminted{firstline=75,lastline=81}{examples/ttl.py}
\begin{minted}{python}
@kernel
def run(self):
self.core.reset()
self.ttlin.gate_rising(5*ms)
timestamp_mu = self.ttlin.timestamp_mu()
at_mu(timestamp_mu + self.core.seconds_to_mu(10*ms))
self.ttlout.pulse(1*us)
\end{minted}
\section{Ordering Information} \section{Ordering Information}
To order, please visit \url{https://m-labs.hk} and select the 2118 BNC-TTL/2128 SMA-TTL in the ARTIQ Sinara crate configuration tool. The card may also be ordered separately by writing to \url{mailto:sales@m-labs.hk}. To order, please visit \url{https://m-labs.hk} and select the 2118 BNC-TTL/2128 SMA-TTL in the ARTIQ Sinara crate configuration tool. The card may also be ordered separately by writing to \url{mailto:sales@m-labs.hk}.

View File

@ -4,8 +4,6 @@
\usepackage{minted} \usepackage{minted}
\usepackage{tcolorbox} \usepackage{tcolorbox}
\usepackage{etoolbox} \usepackage{etoolbox}
\BeforeBeginEnvironment{minted}{\begin{tcolorbox}[colback=white]}%
\AfterEndEnvironment{minted}{\end{tcolorbox}}%
\usepackage[justification=centering]{caption} \usepackage[justification=centering]{caption}
@ -65,6 +63,11 @@ This card can achieve higher speed and lower jitter than the isolated 2118/2128
\newcommand*{\MyLabel}[3][2cm]{\parbox{#1}{\centering #2 \\ #3}} \newcommand*{\MyLabel}[3][2cm]{\parbox{#1}{\centering #2 \\ #3}}
\newcommand*{\MymyLabel}[3][4cm]{\parbox{#1}{\centering #2 \\ #3}} \newcommand*{\MymyLabel}[3][4cm]{\parbox{#1}{\centering #2 \\ #3}}
\newcommand{\inputcolorboxminted}[2]{%
\begin{tcolorbox}[colback=white]
\inputminted[#1, gobble=4]{python}{#2}
\end{tcolorbox}
}
\begin{figure}[h] \begin{figure}[h]
\centering \centering
@ -560,75 +563,24 @@ Timing accuracy in the examples below is well under 1 nanosecond thanks to the A
\subsection{One pulse per second} \subsection{One pulse per second}
The channel should be configured as output in both the gateware and hardware. The channel should be configured as output in both the gateware and hardware.
\inputcolorboxminted{firstline=9,lastline=15}{examples/ttl.py}
\begin{minted}{python}
@kernel
def run(self):
self.core.reset()
while True:
self.ttl0.pulse(500*ms)
delay(500*ms)
\end{minted}
\subsection{Morse code} \subsection{Morse code}
This example demonstrates some basic algorithmic features of the ARTIQ-Python language. This example demonstrates some basic algorithmic features of the ARTIQ-Python language.
\begin{minted}{python} \inputcolorboxminted{firstline=23,lastline=40}{examples/ttl.py}
def prepare(self):
# As of ARTIQ-6, the ARTIQ compiler has limited string handling
# capabilities, so we pass a list of integers instead.
message = ".- .-. - .. --.-"
self.commands = [{".": 1, "-": 2, " ": 3}[c] for c in message]
@kernel
def run(self):
self.core.reset()
for cmd in self.commands:
if cmd == 1:
self.led.pulse(100*ms)
delay(100*ms)
if cmd == 2:
self.led.pulse(300*ms)
delay(100*ms)
if cmd == 3:
delay(700*ms)
\end{minted}
\newpage \newpage
\subsection{Counting rising edges in a 1ms window} \subsection{Counting rising edges in a 1ms window}
The channel should be configured as input in both the gateware and hardware. The channel should be configured as input in both the gateware and hardware.
\inputcolorboxminted{firstline=48,lastline=53}{examples/ttl.py}
\begin{minted}{python}
@kernel
def run(self):
self.core.reset()
gate_end_mu = self.ttl0.gate_rising(1*ms)
counts = self.ttl0.count()
print(counts)
\end{minted}
This example code uses the software counter, which has a maximum count rate of approximately 1 million events per second. This example code uses the software counter, which has a maximum count rate of approximately 1 million events per second.
If the gateware counter is enabled on the TTL channel, it can typically count up to 125 million events per second: If the gateware counter is enabled on the TTL channel, it can typically count up to 125 million events per second:
\begin{minted}{python} \inputcolorboxminted{firstline=61,lastline=66}{examples/ttl.py}
@kernel
def run(self):
self.core.reset()
self.edgecounter0.gate_rising(1*ms)
counts = self.edgecounter0.fetch_count()
print(counts)
\end{minted}
\subsection{Responding to an external trigger} \subsection{Responding to an external trigger}
One channel needs to be configured as input, and the other as output. One channel needs to be configured as input, and the other as output.
\inputcolorboxminted{firstline=75,lastline=81}{examples/ttl.py}
\begin{minted}{python}
@kernel
def run(self):
self.core.reset()
self.ttlin.gate_rising(5*ms)
timestamp_mu = self.ttlin.timestamp_mu()
at_mu(timestamp_mu + self.core.seconds_to_mu(10*ms))
self.ttlout.pulse(1*us)
\end{minted}
\section{Ordering Information} \section{Ordering Information}
To order, please visit \url{https://m-labs.hk} and select the 2238 MCX-TTL in the ARTIQ Sinara crate configuration tool. The card may also be ordered separately by writing to \url{mailto:sales@m-labs.hk}. To order, please visit \url{https://m-labs.hk} and select the 2238 MCX-TTL in the ARTIQ Sinara crate configuration tool. The card may also be ordered separately by writing to \url{mailto:sales@m-labs.hk}.

View File

@ -4,8 +4,6 @@
\usepackage{minted} \usepackage{minted}
\usepackage{tcolorbox} \usepackage{tcolorbox}
\usepackage{etoolbox} \usepackage{etoolbox}
\BeforeBeginEnvironment{minted}{\begin{tcolorbox}[colback=white]}%
\AfterEndEnvironment{minted}{\end{tcolorbox}}%
\usepackage[justification=centering]{caption} \usepackage[justification=centering]{caption}
@ -69,6 +67,11 @@ Only shielded Ethernet Cat-6 cables should be connected.
\newcommand*{\MyLabel}[3][2cm]{\parbox{#1}{\centering #2 \\ #3}} \newcommand*{\MyLabel}[3][2cm]{\parbox{#1}{\centering #2 \\ #3}}
\newcommand*{\MymyLabel}[3][4cm]{\parbox{#1}{\centering #2 \\ #3}} \newcommand*{\MymyLabel}[3][4cm]{\parbox{#1}{\centering #2 \\ #3}}
\newcommand{\inputcolorboxminted}[2]{%
\begin{tcolorbox}[colback=white]
\inputminted[#1, gobble=4]{python}{#2}
\end{tcolorbox}
}
\begin{figure}[h] \begin{figure}[h]
\centering \centering
@ -466,76 +469,24 @@ Timing accuracy in the examples below is well under 1 nanosecond thanks to the A
\subsection{One pulse per second} \subsection{One pulse per second}
The channel should be configured as output in both the gateware and hardware. The channel should be configured as output in both the gateware and hardware.
\inputcolorboxminted{firstline=9,lastline=15}{examples/ttl.py}
\begin{minted}{python}
@kernel
def run(self):
self.core.reset()
while True:
self.ttl0.pulse(500*ms)
delay(500*ms)
\end{minted}
\subsection{Morse code} \subsection{Morse code}
This example demonstrates some basic algorithmic features of the ARTIQ-Python language. This example demonstrates some basic algorithmic features of the ARTIQ-Python language.
\begin{minted}{python} \inputcolorboxminted{firstline=23,lastline=40}{examples/ttl.py}
def prepare(self):
# As of ARTIQ-6, the ARTIQ compiler has limited string handling
# capabilities, so we pass a list of integers instead.
message = ".- .-. - .. --.-"
self.commands = [{".": 1, "-": 2, " ": 3}[c] for c in message]
@kernel
def run(self):
self.core.reset()
for cmd in self.commands:
if cmd == 1:
self.led.pulse(100*ms)
delay(100*ms)
if cmd == 2:
self.led.pulse(300*ms)
delay(100*ms)
if cmd == 3:
delay(700*ms)
\end{minted}
\newpage \newpage
\subsection{Counting rising edges in a 1ms window} \subsection{Counting rising edges in a 1ms window}
The channel should be configured as input in both the gateware and hardware. The channel should be configured as input in both the gateware and hardware.
\inputcolorboxminted{firstline=48,lastline=53}{examples/ttl.py}
\begin{minted}{python}
@kernel
def run(self):
self.core.reset()
gate_end_mu = self.ttl0.gate_rising(1*ms)
counts = self.ttl0.count()
print(counts)
\end{minted}
This example code uses the software counter, which has a maximum count rate of approximately 1 million events per second. This example code uses the software counter, which has a maximum count rate of approximately 1 million events per second.
If the gateware counter is enabled on the TTL channel, it can typically count up to 125 million events per second: If the gateware counter is enabled on the TTL channel, it can typically count up to 125 million events per second:
\begin{minted}{python} \inputcolorboxminted{firstline=61,lastline=66}{examples/ttl.py}
@kernel
def run(self):
self.core.reset()
self.edgecounter0.gate_rising(1*ms)
counts = self.edgecounter0.fetch_count()
print(counts)
\end{minted}
\subsection{Responding to an external trigger} \subsection{Responding to an external trigger}
One channel needs to be configured as input, and the other as output. One channel needs to be configured as input, and the other as output.
\inputcolorboxminted{firstline=75,lastline=81}{examples/ttl.py}
\begin{minted}{python}
@kernel
def run(self):
self.core.reset()
self.ttlin.gate_rising(5*ms)
timestamp_mu = self.ttlin.timestamp_mu()
at_mu(timestamp_mu + self.core.seconds_to_mu(10*ms))
self.ttlout.pulse(1*us)
\end{minted}
\section{Ordering Information} \section{Ordering Information}
To order, please visit \url{https://m-labs.hk} and select the 2245 LVDS-TTL in the ARTIQ Sinara crate configuration tool. The card may also be ordered separately by writing to \url{mailto:sales@m-labs.hk}. To order, please visit \url{https://m-labs.hk} and select the 2245 LVDS-TTL in the ARTIQ Sinara crate configuration tool. The card may also be ordered separately by writing to \url{mailto:sales@m-labs.hk}.

81
examples/ttl.py Normal file
View File

@ -0,0 +1,81 @@
from artiq.experiment import *
class OnePulsePerSecond(EnvExperiment):
def build(self):
self.setattr_device("core")
self.ttl0 = self.get_device("ttl0")
@kernel
def run(self):
self.core.reset()
self.core.break_realtime()
while True:
self.ttl0.pulse(500*ms)
delay(500*ms)
class MorseCode(EnvExperiment):
def build(self):
self.setattr_device("core")
self.led = self.get_device("led0")
def prepare(self):
# As of ARTIQ-6, the ARTIQ compiler has limited string handling
# capabilities, so we pass a list of integers instead.
message = ".- .-. - .. --.-"
self.commands = [{".": 1, "-": 2, " ": 3}[c] for c in message]
@kernel
def run(self):
self.core.reset()
for cmd in self.commands:
if cmd == 1:
self.led.pulse(100*ms)
delay(100*ms)
if cmd == 2:
self.led.pulse(300*ms)
delay(100*ms)
if cmd == 3:
delay(700*ms)
class SoftwareEdgeCount(EnvExperiment):
def build(self):
self.setattr_device("core")
self.ttl0 = self.get_device("ttl0")
@kernel
def run(self):
self.core.reset()
gate_end_mu = self.ttl0.gate_rising(1*ms)
counts = self.ttl0.count(gate_end_mu)
print(counts)
class EdgeCounter(EnvExperiment):
def build(self):
self.setattr_device("core")
self.edgecounter0 = self.get_device("ttl0_counter")
@kernel
def run(self):
self.core.reset()
self.edgecounter0.gate_rising(1*ms)
counts = self.edgecounter0.fetch_count()
print(counts)
class ExternalTrigger(EnvExperiment):
def build(self):
self.setattr_device("core")
self.ttlin = self.get_device("ttl0")
self.ttlout = self.get_device("ttl4")
@kernel
def run(self):
self.core.reset()
gate_end_mu = self.ttlin.gate_rising(5*ms)
timestamp_mu = self.ttlin.timestamp_mu(gate_end_mu)
at_mu(timestamp_mu + self.core.seconds_to_mu(10*ms))
self.ttlout.pulse(1*us)