2018-11-06 02:45:24 +08:00
|
|
|
from artiq.language.core import kernel, delay, portable, at_mu, now_mu
|
2018-01-04 03:22:36 +08:00
|
|
|
from artiq.language.units import us, ms
|
2018-01-02 21:52:13 +08:00
|
|
|
|
2018-11-25 23:56:45 +08:00
|
|
|
from numpy import int32, int64
|
2018-01-02 21:52:13 +08:00
|
|
|
|
2018-02-21 23:00:28 +08:00
|
|
|
from artiq.coredevice import spi2 as spi
|
2018-01-02 21:52:13 +08:00
|
|
|
|
|
|
|
|
2018-02-21 23:00:28 +08:00
|
|
|
SPI_CONFIG = (0*spi.SPI_OFFLINE | 0*spi.SPI_END |
|
2018-10-08 17:06:51 +08:00
|
|
|
0*spi.SPI_INPUT | 1*spi.SPI_CS_POLARITY |
|
|
|
|
0*spi.SPI_CLK_POLARITY | 0*spi.SPI_CLK_PHASE |
|
|
|
|
0*spi.SPI_LSB_FIRST | 0*spi.SPI_HALF_DUPLEX)
|
2018-01-02 21:52:13 +08:00
|
|
|
|
|
|
|
# SPI clock write and read dividers
|
2018-02-21 23:00:28 +08:00
|
|
|
SPIT_CFG_WR = 2
|
|
|
|
SPIT_CFG_RD = 16
|
2018-11-09 20:21:18 +08:00
|
|
|
# 30 MHz fmax, 20 ns setup, 40 ns shift to latch (limiting)
|
|
|
|
SPIT_ATT_WR = 6
|
2018-02-21 23:00:28 +08:00
|
|
|
SPIT_ATT_RD = 16
|
|
|
|
SPIT_DDS_WR = 2
|
|
|
|
SPIT_DDS_RD = 16
|
2018-01-02 21:52:13 +08:00
|
|
|
|
|
|
|
# CFG configuration register bit offsets
|
|
|
|
CFG_RF_SW = 0
|
|
|
|
CFG_LED = 4
|
|
|
|
CFG_PROFILE = 8
|
|
|
|
CFG_IO_UPDATE = 12
|
2018-03-21 00:10:11 +08:00
|
|
|
CFG_MASK_NU = 13
|
2018-10-10 05:16:26 +08:00
|
|
|
CFG_CLK_SEL0 = 17
|
|
|
|
CFG_CLK_SEL1 = 21
|
2018-01-02 21:52:13 +08:00
|
|
|
CFG_SYNC_SEL = 18
|
|
|
|
CFG_RST = 19
|
|
|
|
CFG_IO_RST = 20
|
2019-01-18 18:02:18 +08:00
|
|
|
CFG_CLK_DIV = 22
|
2018-01-02 21:52:13 +08:00
|
|
|
|
|
|
|
# STA status register bit offsets
|
|
|
|
STA_RF_SW = 0
|
|
|
|
STA_SMP_ERR = 4
|
|
|
|
STA_PLL_LOCK = 8
|
|
|
|
STA_IFC_MODE = 12
|
|
|
|
STA_PROTO_REV = 16
|
|
|
|
|
2018-02-21 23:00:28 +08:00
|
|
|
# supported hardware and CPLD code version
|
|
|
|
STA_PROTO_REV_MATCH = 0x08
|
|
|
|
|
|
|
|
# chip select (decoded)
|
|
|
|
CS_CFG = 1
|
|
|
|
CS_ATT = 2
|
|
|
|
CS_DDS_MULTI = 3
|
|
|
|
CS_DDS_CH0 = 4
|
|
|
|
CS_DDS_CH1 = 5
|
|
|
|
CS_DDS_CH2 = 6
|
|
|
|
CS_DDS_CH3 = 7
|
|
|
|
|
|
|
|
|
|
|
|
@portable
|
|
|
|
def urukul_cfg(rf_sw, led, profile, io_update, mask_nu,
|
2019-01-18 18:02:18 +08:00
|
|
|
clk_sel, sync_sel, rst, io_rst, clk_div):
|
2018-02-21 23:00:28 +08:00
|
|
|
"""Build Urukul CPLD configuration register"""
|
|
|
|
return ((rf_sw << CFG_RF_SW) |
|
|
|
|
(led << CFG_LED) |
|
|
|
|
(profile << CFG_PROFILE) |
|
|
|
|
(io_update << CFG_IO_UPDATE) |
|
|
|
|
(mask_nu << CFG_MASK_NU) |
|
2018-10-10 05:16:26 +08:00
|
|
|
((clk_sel & 0x01) << CFG_CLK_SEL0) |
|
2018-11-05 20:19:35 +08:00
|
|
|
((clk_sel & 0x02) << (CFG_CLK_SEL1 - 1)) |
|
2018-02-21 23:00:28 +08:00
|
|
|
(sync_sel << CFG_SYNC_SEL) |
|
|
|
|
(rst << CFG_RST) |
|
2019-01-18 18:02:18 +08:00
|
|
|
(io_rst << CFG_IO_RST) |
|
|
|
|
(clk_div << CFG_CLK_DIV))
|
2018-02-21 23:00:28 +08:00
|
|
|
|
2018-01-02 21:52:13 +08:00
|
|
|
|
2018-02-21 23:00:28 +08:00
|
|
|
@portable
|
2018-01-02 21:52:13 +08:00
|
|
|
def urukul_sta_rf_sw(sta):
|
2018-02-21 23:00:28 +08:00
|
|
|
"""Return the RF switch status from Urukul status register value."""
|
2018-01-02 21:52:13 +08:00
|
|
|
return (sta >> STA_RF_SW) & 0xf
|
|
|
|
|
|
|
|
|
2018-02-21 23:00:28 +08:00
|
|
|
@portable
|
2018-01-02 21:52:13 +08:00
|
|
|
def urukul_sta_smp_err(sta):
|
2018-02-21 23:00:28 +08:00
|
|
|
"""Return the SMP_ERR status from Urukul status register value."""
|
2018-01-02 21:52:13 +08:00
|
|
|
return (sta >> STA_SMP_ERR) & 0xf
|
|
|
|
|
|
|
|
|
2018-02-21 23:00:28 +08:00
|
|
|
@portable
|
2018-01-02 21:52:13 +08:00
|
|
|
def urukul_sta_pll_lock(sta):
|
2018-02-21 23:00:28 +08:00
|
|
|
"""Return the PLL_LOCK status from Urukul status register value."""
|
2018-01-02 21:52:13 +08:00
|
|
|
return (sta >> STA_PLL_LOCK) & 0xf
|
|
|
|
|
|
|
|
|
2018-02-21 23:00:28 +08:00
|
|
|
@portable
|
2018-01-02 21:52:13 +08:00
|
|
|
def urukul_sta_ifc_mode(sta):
|
2018-02-21 23:00:28 +08:00
|
|
|
"""Return the IFC_MODE status from Urukul status register value."""
|
2018-01-02 21:52:13 +08:00
|
|
|
return (sta >> STA_IFC_MODE) & 0xf
|
|
|
|
|
|
|
|
|
2018-02-21 23:00:28 +08:00
|
|
|
@portable
|
2018-01-02 21:52:13 +08:00
|
|
|
def urukul_sta_proto_rev(sta):
|
2018-02-21 23:00:28 +08:00
|
|
|
"""Return the PROTO_REV value from Urukul status register value."""
|
2018-02-13 01:40:33 +08:00
|
|
|
return (sta >> STA_PROTO_REV) & 0x7f
|
2018-01-02 21:52:13 +08:00
|
|
|
|
|
|
|
|
2018-04-26 15:59:08 +08:00
|
|
|
class _RegIOUpdate:
|
|
|
|
def __init__(self, cpld):
|
|
|
|
self.cpld = cpld
|
|
|
|
|
2018-04-28 00:42:09 +08:00
|
|
|
@kernel
|
2018-04-26 15:59:08 +08:00
|
|
|
def pulse(self, t):
|
|
|
|
cfg = self.cpld.cfg_reg
|
|
|
|
self.cpld.cfg_write(cfg | (1 << CFG_IO_UPDATE))
|
|
|
|
delay(t)
|
|
|
|
self.cpld.cfg_write(cfg)
|
|
|
|
|
|
|
|
|
2018-10-31 22:47:00 +08:00
|
|
|
class _DummySync:
|
|
|
|
def __init__(self, cpld):
|
|
|
|
self.cpld = cpld
|
|
|
|
|
|
|
|
@kernel
|
|
|
|
def set_mu(self, ftw):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2018-01-02 21:52:13 +08:00
|
|
|
class CPLD:
|
2018-02-14 16:45:17 +08:00
|
|
|
"""Urukul CPLD SPI router and configuration interface.
|
|
|
|
|
|
|
|
:param spi_device: SPI bus device name
|
|
|
|
:param io_update_device: IO update RTIO TTLOut channel name
|
|
|
|
:param dds_reset_device: DDS reset RTIO TTLOut channel name
|
2018-10-25 17:51:21 +08:00
|
|
|
:param sync_device: AD9910 SYNC_IN RTIO TTLClockGen channel name
|
2018-02-14 16:45:17 +08:00
|
|
|
:param refclk: Reference clock (SMA, MMCX or on-board 100 MHz oscillator)
|
|
|
|
frequency in Hz
|
2018-10-10 05:16:26 +08:00
|
|
|
:param clk_sel: Reference clock selection. For hardware revision >= 1.3
|
|
|
|
valid options are: 0 - internal 100MHz XO; 1 - front-panel SMA; 2
|
|
|
|
internal MMCX. For hardware revision <= v1.2 valid options are: 0 -
|
|
|
|
either XO or MMCX dependent on component population; 1 SMA. Unsupported
|
|
|
|
clocking options are silently ignored.
|
2019-01-18 18:02:18 +08:00
|
|
|
:param clk_div: Reference clock divider. Valid options are 0: variant
|
|
|
|
dependent default (divide-by-4 for AD9910 and divide-by-1 for AD9912);
|
|
|
|
1: divide-by-1; 2: divide-by-2; 3: divide-by-4.
|
|
|
|
On Urukul boards with CPLD gateware before v1.3.1 only the default
|
|
|
|
(0, i.e. variant dependent divider) is valid.
|
2019-01-08 10:37:58 +08:00
|
|
|
:param sync_sel: SYNC (multi-chip synchronisation) signal source selection.
|
|
|
|
0 corresponds to SYNC_IN being supplied by the FPGA via the EEM
|
|
|
|
connector. 1 corresponds to SYNC_OUT from DDS0 being distributed to the
|
|
|
|
other chips.
|
2018-05-22 00:28:19 +08:00
|
|
|
:param rf_sw: Initial CPLD RF switch register setting (default: 0x0).
|
|
|
|
Knowledge of this state is not transferred between experiments.
|
|
|
|
:param att: Initial attenuator setting shift register (default:
|
2018-12-04 23:36:24 +08:00
|
|
|
0x00000000). See also :meth:`get_att_mu` which retrieves the hardware
|
|
|
|
state without side effects. Knowledge of this state is not transferred
|
|
|
|
between experiments.
|
2018-10-31 22:47:00 +08:00
|
|
|
:param sync_div: SYNC_IN generator divider. The ratio between the coarse
|
|
|
|
RTIO frequency and the SYNC_IN generator frequency (default: 2 if
|
2018-10-31 23:04:12 +08:00
|
|
|
`sync_device` was specified).
|
2018-02-14 16:45:17 +08:00
|
|
|
:param core_device: Core device name
|
2019-06-11 11:12:12 +08:00
|
|
|
|
|
|
|
If the clocking is incorrect (for example, setting ``clk_sel`` to the
|
|
|
|
front panel SMA with no clock connected), then the ``init()`` method of
|
|
|
|
the DDS channels can fail with the error message ``PLL lock timeout``.
|
2018-02-14 16:45:17 +08:00
|
|
|
"""
|
2019-01-18 18:02:18 +08:00
|
|
|
kernel_invariants = {"refclk", "bus", "core", "io_update", "clk_div"}
|
2018-02-21 23:00:28 +08:00
|
|
|
|
2018-04-26 01:32:36 +08:00
|
|
|
def __init__(self, dmgr, spi_device, io_update_device=None,
|
2018-10-25 17:51:21 +08:00
|
|
|
dds_reset_device=None, sync_device=None,
|
2019-01-18 18:02:18 +08:00
|
|
|
sync_sel=0, clk_sel=0, clk_div=0, rf_sw=0,
|
2018-10-31 22:47:00 +08:00
|
|
|
refclk=125e6, att=0x00000000, sync_div=None,
|
|
|
|
core_device="core"):
|
2018-01-02 21:52:13 +08:00
|
|
|
|
2018-10-08 17:06:51 +08:00
|
|
|
self.core = dmgr.get(core_device)
|
2018-01-02 21:52:13 +08:00
|
|
|
self.refclk = refclk
|
2019-01-18 18:02:18 +08:00
|
|
|
assert 0 <= clk_div <= 3
|
|
|
|
self.clk_div = clk_div
|
2018-01-02 21:52:13 +08:00
|
|
|
|
|
|
|
self.bus = dmgr.get(spi_device)
|
2018-04-26 01:32:36 +08:00
|
|
|
if io_update_device is not None:
|
|
|
|
self.io_update = dmgr.get(io_update_device)
|
2018-04-26 15:59:08 +08:00
|
|
|
else:
|
|
|
|
self.io_update = _RegIOUpdate(self)
|
2018-01-02 21:52:13 +08:00
|
|
|
if dds_reset_device is not None:
|
|
|
|
self.dds_reset = dmgr.get(dds_reset_device)
|
2018-10-25 17:51:21 +08:00
|
|
|
if sync_device is not None:
|
|
|
|
self.sync = dmgr.get(sync_device)
|
2018-10-31 22:47:00 +08:00
|
|
|
if sync_div is None:
|
|
|
|
sync_div = 2
|
|
|
|
else:
|
|
|
|
self.sync = _DummySync(self)
|
|
|
|
assert sync_div is None
|
|
|
|
sync_div = 0
|
2018-01-02 21:52:13 +08:00
|
|
|
|
2018-05-22 00:28:19 +08:00
|
|
|
self.cfg_reg = urukul_cfg(rf_sw=rf_sw, led=0, profile=0,
|
2018-10-08 17:06:51 +08:00
|
|
|
io_update=0, mask_nu=0, clk_sel=clk_sel,
|
2019-01-18 18:02:18 +08:00
|
|
|
sync_sel=sync_sel,
|
|
|
|
rst=0, io_rst=0, clk_div=clk_div)
|
2018-11-25 23:56:45 +08:00
|
|
|
self.att_reg = int32(int64(att))
|
2018-10-31 22:47:00 +08:00
|
|
|
self.sync_div = sync_div
|
2018-01-02 21:52:13 +08:00
|
|
|
|
|
|
|
@kernel
|
2018-02-21 23:00:28 +08:00
|
|
|
def cfg_write(self, cfg):
|
2018-02-14 16:45:17 +08:00
|
|
|
"""Write to the configuration register.
|
|
|
|
|
2018-02-21 23:00:28 +08:00
|
|
|
See :func:`urukul_cfg` for possible flags.
|
|
|
|
|
2018-02-14 16:45:17 +08:00
|
|
|
:param data: 24 bit data to be written. Will be stored at
|
|
|
|
:attr:`cfg_reg`.
|
|
|
|
"""
|
2018-02-21 23:00:28 +08:00
|
|
|
self.bus.set_config_mu(SPI_CONFIG | spi.SPI_END, 24,
|
2018-10-08 17:06:51 +08:00
|
|
|
SPIT_CFG_WR, CS_CFG)
|
2018-02-21 23:00:28 +08:00
|
|
|
self.bus.write(cfg << 8)
|
|
|
|
self.cfg_reg = cfg
|
2018-01-02 21:52:13 +08:00
|
|
|
|
|
|
|
@kernel
|
|
|
|
def sta_read(self):
|
2018-02-21 23:00:28 +08:00
|
|
|
"""Read the status register.
|
|
|
|
|
|
|
|
Use any of the following functions to extract values:
|
|
|
|
|
|
|
|
* :func:`urukul_sta_rf_sw`
|
|
|
|
* :func:`urukul_sta_smp_err`
|
|
|
|
* :func:`urukul_sta_pll_lock`
|
|
|
|
* :func:`urukul_sta_ifc_mode`
|
|
|
|
* :func:`urukul_sta_proto_rev`
|
|
|
|
|
|
|
|
:return: The status register value.
|
|
|
|
"""
|
|
|
|
self.bus.set_config_mu(SPI_CONFIG | spi.SPI_END | spi.SPI_INPUT, 24,
|
2018-10-08 17:06:51 +08:00
|
|
|
SPIT_CFG_RD, CS_CFG)
|
2018-01-02 21:52:13 +08:00
|
|
|
self.bus.write(self.cfg_reg << 8)
|
2018-02-21 23:00:28 +08:00
|
|
|
return self.bus.read()
|
2018-01-02 21:52:13 +08:00
|
|
|
|
|
|
|
@kernel
|
2018-04-26 15:59:08 +08:00
|
|
|
def init(self, blind=False):
|
2018-02-21 23:00:28 +08:00
|
|
|
"""Initialize and detect Urukul.
|
|
|
|
|
2018-03-21 00:40:03 +08:00
|
|
|
Resets the DDS I/O interface and verifies correct CPLD gateware
|
|
|
|
version.
|
|
|
|
Does not pulse the DDS MASTER_RESET as that confuses the AD9910.
|
2018-04-26 15:59:08 +08:00
|
|
|
|
|
|
|
:param blind: Do not attempt to verify presence and compatibility.
|
2018-02-21 23:00:28 +08:00
|
|
|
"""
|
|
|
|
cfg = self.cfg_reg
|
2018-03-21 00:40:03 +08:00
|
|
|
# Don't pulse MASTER_RESET (m-labs/artiq#940)
|
2018-03-21 00:10:26 +08:00
|
|
|
self.cfg_reg = cfg | (0 << CFG_RST) | (1 << CFG_IO_RST)
|
2018-05-17 03:12:00 +08:00
|
|
|
if blind:
|
|
|
|
self.cfg_write(self.cfg_reg)
|
|
|
|
else:
|
2018-04-26 15:59:08 +08:00
|
|
|
proto_rev = urukul_sta_proto_rev(self.sta_read())
|
|
|
|
if proto_rev != STA_PROTO_REV_MATCH:
|
|
|
|
raise ValueError("Urukul proto_rev mismatch")
|
|
|
|
delay(100*us) # reset, slack
|
2018-02-21 23:00:28 +08:00
|
|
|
self.cfg_write(cfg)
|
2018-10-31 22:47:00 +08:00
|
|
|
if self.sync_div:
|
|
|
|
at_mu(now_mu() & ~0xf) # align to RTIO/2
|
|
|
|
self.set_sync_div(self.sync_div) # 125 MHz/2 = 1 GHz/16
|
2018-02-21 23:00:28 +08:00
|
|
|
delay(1*ms) # DDS wake up
|
2018-01-02 21:52:13 +08:00
|
|
|
|
2018-01-04 02:29:39 +08:00
|
|
|
@kernel
|
|
|
|
def io_rst(self):
|
2018-02-21 23:00:28 +08:00
|
|
|
"""Pulse IO_RST"""
|
2018-01-04 02:29:39 +08:00
|
|
|
self.cfg_write(self.cfg_reg | (1 << CFG_IO_RST))
|
|
|
|
self.cfg_write(self.cfg_reg & ~(1 << CFG_IO_RST))
|
|
|
|
|
2018-01-02 21:52:13 +08:00
|
|
|
@kernel
|
2018-02-21 23:00:28 +08:00
|
|
|
def cfg_sw(self, channel, on):
|
|
|
|
"""Configure the RF switches through the configuration register.
|
|
|
|
|
|
|
|
These values are logically OR-ed with the LVDS lines on EEM1.
|
|
|
|
|
|
|
|
:param channel: Channel index (0-3)
|
|
|
|
:param on: Switch value
|
|
|
|
"""
|
2018-01-02 21:52:13 +08:00
|
|
|
c = self.cfg_reg
|
|
|
|
if on:
|
2018-02-21 23:00:28 +08:00
|
|
|
c |= 1 << channel
|
2018-01-02 21:52:13 +08:00
|
|
|
else:
|
2018-02-21 23:00:28 +08:00
|
|
|
c &= ~(1 << channel)
|
2018-01-04 02:29:39 +08:00
|
|
|
self.cfg_write(c)
|
2018-01-02 21:52:13 +08:00
|
|
|
|
2018-10-24 19:01:13 +08:00
|
|
|
@kernel
|
|
|
|
def cfg_switches(self, state):
|
|
|
|
"""Configure all four RF switches through the configuration register.
|
|
|
|
|
|
|
|
:param state: RF switch state as a 4 bit integer.
|
|
|
|
"""
|
|
|
|
self.cfg_write((self.cfg_reg & ~0xf) | state)
|
|
|
|
|
2018-01-02 21:52:13 +08:00
|
|
|
@kernel
|
2018-02-21 23:00:28 +08:00
|
|
|
def set_att_mu(self, channel, att):
|
2018-02-14 16:45:17 +08:00
|
|
|
"""Set digital step attenuator in machine units.
|
|
|
|
|
2019-11-17 23:51:26 +08:00
|
|
|
This method will also write the attenuator settings of the three other channels. Use
|
|
|
|
:meth:`get_att_mu` to retrieve the hardware state set in previous experiments.
|
2018-05-22 00:28:19 +08:00
|
|
|
|
2018-02-14 16:45:17 +08:00
|
|
|
:param channel: Attenuator channel (0-3).
|
2020-05-17 21:09:11 +08:00
|
|
|
:param att: 8-bit digital attenuation setting:
|
2018-02-14 16:45:17 +08:00
|
|
|
255 minimum attenuation, 0 maximum attenuation (31.5 dB)
|
2018-01-02 21:52:13 +08:00
|
|
|
"""
|
|
|
|
a = self.att_reg & ~(0xff << (channel * 8))
|
|
|
|
a |= att << (channel * 8)
|
2018-05-22 00:28:19 +08:00
|
|
|
self.set_all_att_mu(a)
|
|
|
|
|
|
|
|
@kernel
|
|
|
|
def set_all_att_mu(self, att_reg):
|
|
|
|
"""Set all four digital step attenuators (in machine units).
|
|
|
|
|
|
|
|
.. seealso:: :meth:`set_att_mu`
|
|
|
|
|
|
|
|
:param att_reg: Attenuator setting string (32 bit)
|
|
|
|
"""
|
2018-02-21 23:00:28 +08:00
|
|
|
self.bus.set_config_mu(SPI_CONFIG | spi.SPI_END, 32,
|
2018-10-08 17:06:51 +08:00
|
|
|
SPIT_ATT_WR, CS_ATT)
|
2018-05-22 00:28:19 +08:00
|
|
|
self.bus.write(att_reg)
|
|
|
|
self.att_reg = att_reg
|
2018-01-02 21:52:13 +08:00
|
|
|
|
|
|
|
@kernel
|
|
|
|
def set_att(self, channel, att):
|
2018-02-14 16:45:17 +08:00
|
|
|
"""Set digital step attenuator in SI units.
|
|
|
|
|
2019-11-17 23:51:26 +08:00
|
|
|
This method will write the attenuator settings of all four channels.
|
|
|
|
|
|
|
|
.. seealso:: :meth:`set_att_mu`
|
|
|
|
|
2018-02-14 16:45:17 +08:00
|
|
|
:param channel: Attenuator channel (0-3).
|
2018-02-21 23:00:28 +08:00
|
|
|
:param att: Attenuation setting in dB. Higher value is more
|
2018-11-09 20:32:05 +08:00
|
|
|
attenuation. Minimum attenuation is 0*dB, maximum attenuation is
|
|
|
|
31.5*dB.
|
2018-02-14 16:45:17 +08:00
|
|
|
"""
|
2020-05-17 21:09:11 +08:00
|
|
|
code = 255 - int32(round(att*8))
|
|
|
|
if code < 0 or code > 255:
|
|
|
|
raise ValueError("Invalid urukul.CPLD attenuation!")
|
|
|
|
self.set_att_mu(channel, code)
|
2018-02-21 23:00:28 +08:00
|
|
|
|
|
|
|
@kernel
|
|
|
|
def get_att_mu(self):
|
|
|
|
"""Return the digital step attenuator settings in machine units.
|
|
|
|
|
2019-11-17 23:51:26 +08:00
|
|
|
The result is stored and will be used in future calls of :meth:`set_att_mu`.
|
|
|
|
|
2018-02-21 23:00:28 +08:00
|
|
|
:return: 32 bit attenuator settings
|
|
|
|
"""
|
2018-11-16 22:56:26 +08:00
|
|
|
self.bus.set_config_mu(SPI_CONFIG | spi.SPI_INPUT, 32,
|
2018-10-08 17:06:51 +08:00
|
|
|
SPIT_ATT_RD, CS_ATT)
|
2018-11-16 22:56:26 +08:00
|
|
|
self.bus.write(0) # shift in zeros, shift out current value
|
|
|
|
self.bus.set_config_mu(SPI_CONFIG | spi.SPI_END, 32,
|
|
|
|
SPIT_ATT_WR, CS_ATT)
|
|
|
|
delay(10*us)
|
|
|
|
self.att_reg = self.bus.read()
|
|
|
|
self.bus.write(self.att_reg) # shift in current value again and latch
|
|
|
|
return self.att_reg
|
2018-10-25 17:51:21 +08:00
|
|
|
|
|
|
|
@kernel
|
|
|
|
def set_sync_div(self, div):
|
|
|
|
"""Set the SYNC_IN AD9910 pulse generator frequency
|
|
|
|
and align it to the current RTIO timestamp.
|
|
|
|
|
|
|
|
The SYNC_IN signal is derived from the coarse RTIO clock
|
2019-01-21 19:37:33 +08:00
|
|
|
and the divider must be a power of two.
|
2018-10-25 17:51:21 +08:00
|
|
|
Configure ``sync_sel == 0``.
|
|
|
|
|
|
|
|
:param div: SYNC_IN frequency divider. Must be a power of two.
|
|
|
|
Minimum division ratio is 2. Maximum division ratio is 16.
|
|
|
|
"""
|
|
|
|
ftw_max = 1 << 4
|
|
|
|
ftw = ftw_max//div
|
|
|
|
assert ftw*div == ftw_max
|
|
|
|
self.sync.set_mu(ftw)
|
2018-11-14 14:43:56 +08:00
|
|
|
|
|
|
|
@kernel
|
|
|
|
def set_profile(self, profile):
|
|
|
|
"""Set the PROFILE pins.
|
|
|
|
|
|
|
|
The PROFILE pins are common to all four DDS channels.
|
|
|
|
|
|
|
|
:param profile: PROFILE pins in numeric representation (0-7).
|
|
|
|
"""
|
|
|
|
cfg = self.cfg_reg & ~(7 << CFG_PROFILE)
|
|
|
|
cfg |= (profile & 7) << CFG_PROFILE
|
|
|
|
self.cfg_write(cfg)
|