Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tfcollins/dac auto type #498

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions adi/rx_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class tx(dds, rx_tx_common):
_txdac: iio.Device = []
_tx_channel_names: List[str] = []
_complex_data = False
_tx_data_type = np.int16
_tx_data_type = None
__txbuf = None
_output_byte_filename = "out.bin"
_push_to_file = False
Expand Down Expand Up @@ -432,6 +432,16 @@ def tx(self, data_np=None):
is enabled containing samples from a channel or set of channels.
Data must be complex when using a complex data device.
"""

if not self._tx_data_type:
# Find channel data format
chan_name = self._tx_channel_names[self.tx_enabled_channels[0]]
chan = self._txdac.find_channel(chan_name, True)
df = chan.data_format
fmt = ("i" if df.is_signed is True else "u") + str(df.length // 8)
fmt = ">" + fmt if df.is_be else fmt
self._tx_data_type = np.dtype(fmt)

if not self.__tx_enabled_channels and data_np:
raise Exception(
"When tx_enabled_channels is None or empty,"
Expand Down Expand Up @@ -464,8 +474,8 @@ def tx(self, data_np=None):
for chan in data_np:
i = np.real(chan)
q = np.imag(chan)
data[indx::stride] = i.astype(int)
data[indx + 1 :: stride] = q.astype(int)
data[indx::stride] = i.astype(self._tx_data_type)
data[indx + 1 :: stride] = q.astype(self._tx_data_type)
indx = indx + 2
else:
if self._num_tx_channels_enabled == 1:
Expand All @@ -478,7 +488,7 @@ def tx(self, data_np=None):
stride = self._num_tx_channels_enabled
data = np.empty(stride * len(data_np[0]), dtype=self._tx_data_type)
for chan in data_np:
data[indx::stride] = chan.astype(int)
data[indx::stride] = chan.astype(self._tx_data_type)
indx = indx + 1

if not self.__txbuf:
Expand Down
1 change: 1 addition & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def checkparts(c):
"ad469x",
"ad777x",
"ad578x",
"adaq42xx",
]
for c in dir(mod):
if (
Expand Down
Loading