forked from M-Labs/artiq
1
0
Fork 0

coredevice/suservo: Add separate methods for setting only the IIR offset

This commit is contained in:
David Nadlinger 2019-12-30 20:02:22 +00:00
parent a666766f38
commit 1e864b7e2d
1 changed files with 38 additions and 6 deletions

View File

@ -294,7 +294,7 @@ class Channel:
base = (self.servo_channel << 8) | (profile << 3) base = (self.servo_channel << 8) | (profile << 3)
self.servo.write(base + 0, ftw >> 16) self.servo.write(base + 0, ftw >> 16)
self.servo.write(base + 6, (ftw & 0xffff)) self.servo.write(base + 6, (ftw & 0xffff))
self.servo.write(base + 4, offs) self.set_dds_offset_mu(profile, offs)
self.servo.write(base + 2, pow_) self.servo.write(base + 2, pow_)
@kernel @kernel
@ -307,10 +307,8 @@ class Channel:
:param profile: Profile number (0-31) :param profile: Profile number (0-31)
:param frequency: DDS frequency in Hz :param frequency: DDS frequency in Hz
:param offset: IIR offset (negative setpoint) in units of full scale. :param offset: IIR offset (negative setpoint) in units of full scale,
For positive ADC voltages as setpoints, this should be negative. see :meth:`dds_offset_to_mu`
Due to rounding and representation as two's complement,
``offset=1`` can not be represented while ``offset=-1`` can.
:param phase: DDS phase in turns :param phase: DDS phase in turns
""" """
if self.servo_channel < 4: if self.servo_channel < 4:
@ -319,9 +317,43 @@ class Channel:
dds = self.servo.dds1 dds = self.servo.dds1
ftw = dds.frequency_to_ftw(frequency) ftw = dds.frequency_to_ftw(frequency)
pow_ = dds.turns_to_pow(phase) pow_ = dds.turns_to_pow(phase)
offs = int(round(offset*(1 << COEFF_WIDTH - 1))) offs = self.dds_offset_to_mu(offset)
self.set_dds_mu(profile, ftw, offs, pow_) self.set_dds_mu(profile, ftw, offs, pow_)
@kernel
def set_dds_offset_mu(self, profile, offs):
"""Set only IIR offset in DDS coefficient profile.
See :meth:`set_dds_mu` for setting the complete DDS profile.
:param profile: Profile number (0-31)
:param offs: IIR offset (17 bit signed)
"""
base = (self.servo_channel << 8) | (profile << 3)
self.servo.write(base + 4, offs)
@kernel
def set_dds_offset(self, profile, offset):
"""Set only IIR offset in DDS coefficient profile.
See :meth:`set_dds` for setting the complete DDS profile.
:param profile: Profile number (0-31)
:param offset: IIR offset (negative setpoint) in units of full scale
"""
self.set_dds_offset_mu(profile, self.dds_offset_to_mu(offset))
@portable
def dds_offset_to_mu(self, offset):
"""Convert IIR offset (negative setpoint) from units of full scale to
machine units (see :meth:`set_dds_mu`, :meth:`set_dds_offset_mu`).
For positive ADC voltages as setpoints, this should be negative. Due to
rounding and representation as two's complement, ``offset=1`` can not
be represented while ``offset=-1`` can.
"""
return int(round(offset * (1 << COEFF_WIDTH - 1)))
@kernel @kernel
def set_iir_mu(self, profile, adc, a1, b0, b1, dly=0): def set_iir_mu(self, profile, adc, a1, b0, b1, dly=0):
"""Set profile IIR coefficients in machine units. """Set profile IIR coefficients in machine units.