How to set number of buffers in iio.py

Hi,

I'm trying to configure the number of buffers on Pluto.  I want to be able to change a parameter, measure data, change it again, etc.  So I don't want the buffers filled up with data that is for the wrong configuration.  A wise man told me I need to modify "set_kernel_buffers_count".  The default is 4, and I want to change that to 1.  So I added that and then plotted data where I set the DDS scale, grab some data, change the scale etc.  But it seems to still act like it has 4 buffers.  And nothing I do can make it more or less.  Here's the modifications I made to a Travis Collins Pluto example script:

#!/usr/bin/env python
#
# Copyright (C) 2018 Analog Devices, Inc.
# Author: Travis Collins <travis.collins@analog.com>
#
# Licensed under the GPL-2.

import sys
import iio
import numpy as np
import matplotlib.pyplot as plt
do_plots = True

# User configurable
TXLO = 1000000000
TXBW = 5000000
TXFS = 3000000
RXLO = TXLO
RXBW = TXBW
RXFS = TXFS

# Setup contexts
ctx = iio.Context('ip:192.168.2.1')
ctrl = ctx.find_device("ad9361-phy")
txdac = ctx.find_device("cf-ad9361-dds-core-lpc")
rxadc = ctx.find_device("cf-ad9361-lpc")

rxadc.set_kernel_buffers_count=1
txdac.set_kernel_buffers_count=1

# Configure transceiver settings
rxLO = ctrl.find_channel("altvoltage0", True)
rxLO.attrs["frequency"].value = str(int(RXLO))
txLO = ctrl.find_channel("altvoltage1", True)
txLO.attrs["frequency"].value = str(int(TXLO))

tx = ctrl.find_channel("voltage0",True)
tx.attrs["rf_bandwidth"].value = str(int(RXBW))
tx.attrs["sampling_frequency"].value = str(int(RXFS))
tx.attrs['hardwaregain'].value = '-40'

rx = ctrl.find_channel("voltage0")
rx.attrs["rf_bandwidth"].value = str(int(TXBW))
rx.attrs["sampling_frequency"].value = str(int(TXFS))
rx.attrs['gain_control_mode'].value = 'manual'
rx.attrs['hardwaregain'].value = '10'

# Enable all IQ channels
v0 = rxadc.find_channel("voltage0")
v1 = rxadc.find_channel("voltage1")
v0.enabled = True
v1.enabled = True

# Create buffer for RX data
rxbuf = iio.Buffer(rxadc, 2**8, False)

# Enable single tone DDS
dds0 = txdac.find_channel('altvoltage0',True)
dds2 = txdac.find_channel('altvoltage2',True)
dds0.attrs['raw'].value = str(1)
dds0.attrs['frequency'].value = str(100000)
dds0.attrs['scale'].value = str(0.9)
dds0.attrs['phase'].value = str(90000)
dds2.attrs['raw'].value = str(1)
dds2.attrs['frequency'].value = str(100000)
dds2.attrs['scale'].value = str(0.9)
dds2.attrs['phase'].value = str(0)

# Collect data
reals = np.array([])
imags = np.array([])
rxbuf.refill()
rxbuf.read()
rxbuf.refill()
rxbuf.read()
rxbuf.refill()
rxbuf.read()


for i in range(10):
  dds0.attrs['scale'].value = str(i*0.1)
  dds2.attrs['scale'].value = str(i*0.1)
  rxbuf.refill()
  data = rxbuf.read()
  x = np.frombuffer(data,dtype=np.int16)
  reals = np.append(reals,x[::2])
  imags = np.append(imags,x[1::2])


# Plot
if do_plots:
    plt.plot(reals)
    plt.plot(imags)
    plt.xlabel("Samples")
    plt.ylabel("Amplitude [dbFS]")
    plt.show()

When I run it, it seems that there are buffers which still retain the "old" settings, before loading refreshing with my new settings.  You can see that the first 3 grabs of 256 data points are old (0.9 DDS scale) data:



tagged
[edited by: JValeriani at 2:18 PM (GMT 0) on 14 Oct 2019]
Parents Reply Children