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: 423ca03f3b7e
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: 669fbaa4f12a
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Mar 3, 2016

  1. Verified

    This commit was signed with the committer’s verified signature.
    issyl0 Issy Long
    Copy the full SHA
    dc6d116 View commit details
  2. ad53xx->ad5360 and refactor

    jordens committed Mar 3, 2016
    Copy the full SHA
    669fbaa View commit details
Showing with 103 additions and 74 deletions.
  1. +95 −0 artiq/coredevice/ad5360.py
  2. +0 −71 artiq/coredevice/ad53xx.py
  3. +3 −3 artiq/coredevice/spi.py
  4. +5 −0 doc/manual/core_drivers_reference.rst
95 changes: 95 additions & 0 deletions artiq/coredevice/ad5360.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from artiq.language.core import kernel, portable, delay
from artiq.language.units import ns
from artiq.coredevice import spi


_AD5360_SPI_CONFIG = (0*spi.SPI_OFFLINE | 0*spi.SPI_CS_POLARITY |
0*spi.SPI_CLK_POLARITY | 1*spi.SPI_CLK_PHASE |
0*spi.SPI_LSB_FIRST | 0*spi.SPI_HALF_DUPLEX)

_AD5360_CMD_DATA = 3 << 22
_AD5360_CMD_OFFSET = 2 << 22
_AD5360_CMD_GAIN = 1 << 22
_AD5360_CMD_SPECIAL = 0 << 22


@portable
def _AD5360_WRITE_CHANNEL(c):
return (c + 8) << 16

_AD5360_SPECIAL_NOP = 0 << 16
_AD5360_SPECIAL_CONTROL = 1 << 16
_AD5360_SPECIAL_OFS0 = 2 << 16
_AD5360_SPECIAL_OFS1 = 3 << 16
_AD5360_SPECIAL_READ = 3 << 16


@portable
def _AD5360_READ_CHANNEL(ch):
return (ch + 8) << 7

_AD5360_READ_X1A = 0x000 << 7
_AD5360_READ_X1B = 0x040 << 7
_AD5360_READ_OFFSET = 0x080 << 7
_AD5360_READ_GAIN = 0x0c0 << 7
_AD5360_READ_CONTROL = 0x101 << 7
_AD5360_READ_OFS0 = 0x102 << 7
_AD5360_READ_OFS1 = 0x103 << 7


class AD5360:
"""
Support for the Analog devices AD53[67][0123]
multi-channel Digital to Analog Converters
"""

def __init__(self, dmgr, spi_bus, ldac=None, chip_select=0):
self.core = dmgr.get("core")
self.bus = dmgr.get(spi_bus)
if ldac is not None:
ldac = dmgr.get(ldac)
self.ldac = ldac
self.chip_select = chip_select

@kernel
def setup_bus(self, write_div=4, read_div=7):
# write: 2*8ns >= 10ns = t_6 (clk falling to cs_n rising)
# read: 4*8*ns >= 25ns = t_22 (clk falling to miso valid)
self.bus.set_config_mu(_AD5360_SPI_CONFIG, write_div, read_div)
self.bus.set_xfer(self.chip_select, 24, 0)

@kernel
def write_offsets(self, value=0x1fff):
value &= 0x3fff
self.bus.write((_AD5360_CMD_SPECIAL | _AD5360_SPECIAL_OFS0 | value
) << 8)
self.bus.write((_AD5360_CMD_SPECIAL | _AD5360_SPECIAL_OFS1 | value
) << 8)

@kernel
def write_channel(self, channel=0, value=0, op=_AD5360_CMD_DATA):
channel &= 0x3f
value &= 0xffff
self.bus.write((op | _AD5360_WRITE_CHANNEL(channel) | value) << 8)

@kernel
def write_channels(self, values, first=0, op=_AD5360_CMD_DATA):
for i in range(len(values)):
self.write_channel(i + first, values[i], op)

@kernel
def read_channel_sync(self, channel=0, op=_AD5360_READ_X1A):
channel &= 0x3f
self.bus.write((_AD5360_CMD_SPECIAL | _AD5360_SPECIAL_READ | op |
_AD5360_READ_CHANNEL(channel)) << 8)
self.bus.set_xfer(self.chip_select, 0, 24)
self.bus.write((_AD5360_CMD_SPECIAL | _AD5360_SPECIAL_NOP) << 8)
self.bus.read_async()
self.bus.set_xfer(self.chip_select, 24, 0)
return self.bus.input_async() & 0xffff

@kernel
def load(self):
self.ldac.off()
delay(24*ns)
self.ldac.on()
71 changes: 0 additions & 71 deletions artiq/coredevice/ad53xx.py

This file was deleted.

6 changes: 3 additions & 3 deletions artiq/coredevice/spi.py
Original file line number Diff line number Diff line change
@@ -198,11 +198,11 @@ def write(self, data=0):
the previous transfer's read data is available in the
``data`` register.
This method advances the timeline by the duration of the
RTIO-to-Wishbone bus transaction (three RTIO clock cycles).
This method advances the timeline by the duration of the SPI transfer.
If a transfer is to be chained, the timeline needs to be rewound.
"""
rtio_output(now_mu(), self.channel, SPI_DATA_ADDR, data)
delay_mu(3*self.ref_period_mu)
delay_mu(self.xfer_period_mu + self.write_period_mu)

@kernel
def read_async(self):
5 changes: 5 additions & 0 deletions doc/manual/core_drivers_reference.rst
Original file line number Diff line number Diff line change
@@ -30,6 +30,11 @@ These drivers are for the core device and the peripherals closely integrated int
.. automodule:: artiq.coredevice.spi
:members:

:mod:`artiq.coredevice.ad5360` module
-------------------------------------

.. automodule:: artiq.coredevice.ad5360
:members:

:mod:`artiq.coredevice.exceptions` module
-----------------------------------------