From 1bfe920d57b75277801017ba523781a93f55c784 Mon Sep 17 00:00:00 2001 From: RibhuDP Date: Tue, 21 Nov 2023 10:21:29 +0530 Subject: [PATCH 1/2] examples:ad575r: Fix typos in example script Fix typos in variable name Signed-off-by: RibhuDP --- examples/ad5754r_example.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ad5754r_example.py b/examples/ad5754r_example.py index 0cc090350..773042287 100644 --- a/examples/ad5754r_example.py +++ b/examples/ad5754r_example.py @@ -34,8 +34,8 @@ import adi # Set up AD5754R -ad578x_dev = adi.ad5754r(uri="serial:COM46,230400,8n1n") -ad578x.int_ref_powerup = "powerup" +ad5754r_dev = adi.ad5754r(uri="serial:COM46,230400,8n1n") +ad5754r_dev.int_ref_powerup = "powerup" # Configure channel 0 chn_num = 0 From dc7caa77c5ed1a4e3d38cb89ac8246364dab3834 Mon Sep 17 00:00:00 2001 From: RibhuDP Date: Tue, 28 Nov 2023 14:50:51 +0530 Subject: [PATCH 2/2] adi: ad5754r: Update attributes and example 1. Add additional dac device and channel attributes 2. Update example script to demonstrate usage of attributes Signed-off-by: RibhuDP --- adi/ad5754r.py | 127 ++++++++++++++++++++++++++++++++++++ examples/ad5754r_example.py | 20 +++++- 2 files changed, 145 insertions(+), 2 deletions(-) diff --git a/adi/ad5754r.py b/adi/ad5754r.py index d1208c29b..91b0eabb2 100644 --- a/adi/ad5754r.py +++ b/adi/ad5754r.py @@ -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""" @@ -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) + ) diff --git a/examples/ad5754r_example.py b/examples/ad5754r_example.py index 773042287..02955883b 100644 --- a/examples/ad5754r_example.py +++ b/examples/ad5754r_example.py @@ -31,10 +31,10 @@ # 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 -ad5754r_dev = adi.ad5754r(uri="serial:COM46,230400,8n1n") +ad5754r_dev = ad5754r(uri="serial:COM4,230400,8n1n") ad5754r_dev.int_ref_powerup = "powerup" # Configure channel 0 @@ -42,6 +42,22 @@ 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)