Skip to content

Commit

Permalink
Merge pull request #501 from ribdp/ad5754r-update-driver-and-examples
Browse files Browse the repository at this point in the history
Ad5754r update driver and examples
  • Loading branch information
tfcollins authored Nov 29, 2023
2 parents 5670c59 + dc7caa7 commit 0e7c0de
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 3 deletions.
127 changes: 127 additions & 0 deletions adi/ad5754r.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,121 @@ def sampling_frequency(self, value):
"""Set sampling frequency"""
self._set_iio_dev_attr_str("sampling_frequency", value)

@property
def clamp_enable(self):
"""Get clamp_en setting"""
return self._get_iio_dev_attr_str("clamp_enable")

@property
def clamp_enable_available(self):
"""Get list of all clamp_en settings"""
return self._get_iio_dev_attr_str("clamp_enable_available")

@clamp_enable.setter
def clamp_enable(self, value):
"""Set clamp_en"""
if value in self.clamp_enable_available:
self._set_iio_dev_attr_str("clamp_enable", value)
else:
raise ValueError(
"Error: clamp_en setting not supported \nUse one of: "
+ str(self.clamp_enable_available)
)

@property
def tsd_enable(self):
"""Get tsd_en setting"""
return self._get_iio_dev_attr_str("tsd_enable")

@property
def tsd_enable_available(self):
"""Get list of all tsd_en settings"""
return self._get_iio_dev_attr_str("tsd_enable_available")

@tsd_enable.setter
def tsd_enable(self, value):
"""Set tsd_en"""
if value in self.tsd_enable_available:
self._set_iio_dev_attr_str("tsd_enable", value)
else:
raise ValueError(
"Error: tsd_en setting not supported \nUse one of: "
+ str(self.tsd_enable_available)
)

@property
def oc_tsd(self):
"""Get oc_tsd status"""
return self._get_iio_dev_attr_str("oc_tsd")

@property
def oc_tsd_available(self):
"""Get list of all possible oc_tsd status"""
return self._get_iio_dev_attr_str("oc_tsd_available")

@property
def all_chns_clear(self):
"""Get current all_chns_clear setting"""
return self._get_iio_dev_attr_str("all_chns_clear")

@property
def all_chns_clear_available(self):
"""Get list of all all_chns_clear settings"""
return self._get_iio_dev_attr_str("all_chns_clear_available")

@all_chns_clear.setter
def all_chns_clear(self, value):
"""Clear all channels"""
if value in self.all_chns_clear_available:
self._set_iio_dev_attr_str("all_chns_clear", value)
else:
raise ValueError(
"Error: all_chns_clear setting not supported \nUse one of: "
+ str(self.all_chns_clear_available)
)

@property
def sw_ldac_trigger(self):
"""Get sw_ldac_trigger setting"""
return self._get_iio_dev_attr_str("all_chns_clear")

@property
def sw_ldac_trigger_available(self):
"""Get list of all sw_ldac_trigger settings"""
return self._get_iio_dev_attr_str("sw_ldac_trigger_available")

@sw_ldac_trigger.setter
def sw_ldac_trigger(self, value):
"""Trigger software LDAC"""
if value in self.sw_ldac_trigger_available:
self._set_iio_dev_attr_str("sw_ldac_trigger", value)
else:
raise ValueError(
"Error: sw_ldac_trigger setting not supported \nUse one of: "
+ str(self.sw_ldac_trigger_available)
)

@property
def hw_ldac_trigger(self):
"""Get hw_ldac_trigger setting"""
return self._get_iio_dev_attr_str("hw_ldac_trigger")

@property
def hw_ldac_trigger_available(self):
"""Get list of all hw_ldac_trigger settings"""
return self._get_iio_dev_attr_str("hw_ldac_trigger_available")

@hw_ldac_trigger.setter
def hw_ldac_trigger(self, value):
"""Trigger hardware LDAC"""
if value in self.hw_ldac_trigger_available:
self._set_iio_dev_attr_str("hw_ldac_trigger", value)
else:
raise ValueError(
"Error: hw_ldac_trigger setting not supported \nUse one of: "
+ str(self.hw_ldac_trigger_available)
)

class _channel(attribute):
"""AD5754R channel"""

Expand Down Expand Up @@ -207,3 +322,15 @@ def range(self, value):
"Error: range setting not supported \nUse one of: "
+ str(self.range_available)
)

@property
def dac_register(self):
"""Get dac_register value"""
return self._get_iio_attr_str(self.name, "dac_register", True)

@dac_register.setter
def dac_register(self, value):
"""Set dac_register value"""
self._set_iio_attr(
self.name, "dac_register", True, str(Decimal(value).real)
)
22 changes: 19 additions & 3 deletions examples/ad5754r_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,33 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import adi
from adi.ad5754r import *

# Set up AD5754R
ad578x_dev = adi.ad5754r(uri="serial:COM46,230400,8n1n")
ad578x.int_ref_powerup = "powerup"
ad5754r_dev = ad5754r(uri="serial:COM4,230400,8n1n")
ad5754r_dev.int_ref_powerup = "powerup"

# Configure channel 0
chn_num = 0
ad5754r_chan = ad5754r_dev.channel[chn_num]
ad5754r_chan.powerup = "powerup"

# Update dac output for channel 0 instantaneously using the 'raw' attribute
ad5754r_chan.raw = 1600

# Update dac output for channel 0 using software LDAC operation
ad5754r_chan.dac_register = 500
ad5754r_dev.sw_ldac_trigger = "Trigger"

# Update dac output of channel 0 using hardware LDAC operation
ad5754r_chan.dac_register = 1000
ad5754r_dev.hw_ldac_trigger = "Trigger"

# Clear all DAC outputs to the midscale code
ad5754r_dev.clear_setting = "midscale_code"
ad5754r_dev.all_chns_clear = "Clear"

# Determine output voltage using scale and offset
raw = int(ad5754r_chan.raw)
scale = float(ad5754r_chan.scale)
offset = int(ad5754r_chan.offset)
Expand Down

0 comments on commit 0e7c0de

Please sign in to comment.