From a1e1f2b387ebd1a1c02d94233eee3e0f5f5226a9 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 1 Mar 2016 00:28:40 +0800 Subject: [PATCH] doc: insist that output() must be called on TTLInOut. Closes #297 --- artiq/coredevice/ttl.py | 15 +++++++++++++-- doc/manual/getting_started_core.rst | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/artiq/coredevice/ttl.py b/artiq/coredevice/ttl.py index be410d919..91c8c5531 100644 --- a/artiq/coredevice/ttl.py +++ b/artiq/coredevice/ttl.py @@ -91,6 +91,11 @@ class TTLInOut: This should be used with bidirectional channels. + Note that the channel is in input mode by default. If you need to drive a + signal, you must call ``output``. If the channel is in output mode most of + the time in your setup, it is a good idea to call ``output`` in the + startup kernel. + :param channel: channel number """ def __init__(self, dmgr, channel): @@ -107,12 +112,18 @@ class TTLInOut: @kernel def output(self): - """Set the direction to output.""" + """Set the direction to output. + + There must be a delay of at least one RTIO clock cycle before any + other command can be issued.""" self.set_oe(True) @kernel def input(self): - """Set the direction to input.""" + """Set the direction to input. + + There must be a delay of at least one RTIO clock cycle before any + other command can be issued.""" self.set_oe(False) @kernel diff --git a/doc/manual/getting_started_core.rst b/doc/manual/getting_started_core.rst index 2189e65bd..4dde970cc 100644 --- a/doc/manual/getting_started_core.rst +++ b/doc/manual/getting_started_core.rst @@ -108,6 +108,10 @@ Create a new file ``rtio.py`` containing the following: :: delay(2*us) +.. note:: + If ``ttl0`` is a bidirectional channel (``TTLInOut``), it is in input (non-driving) mode by default. You need to call ``self.ttl0.output()`` as explained above for the LED. + + Connect an oscilloscope or logic analyzer to TTL0 and run ``artiq_run.py led.py``. Notice that the generated signal's period is precisely 4 microseconds, and that it has a duty cycle of precisely 50%. This is not what you would expect if the delay and the pulse were implemented with CPU-controlled GPIO: overhead from the loop management, function calls, etc. would increase the signal's period, and asymmetry in the overhead would cause duty cycle distortion. Instead, inside the core device, output timing is generated by the gateware and the CPU only programs switching commands with certain timestamps that the CPU computes. This guarantees precise timing as long as the CPU can keep generating timestamps that are increasing fast enough. In case it fails to do that (and attempts to program an event with a timestamp in the past), the :class:`artiq.coredevice.exceptions.RTIOUnderflow` exception is raised. The kernel causing it may catch it (using a regular ``try... except...`` construct), or it will be propagated to the host.