Post Go back to editing

ad9361 ad9363

Category: Software
Product Number: ad9361 sweep and get rssi on linux platform, ad9361 , ad9361 , ad9361 , ad9361 , ad9361
Software Version: iio

hello.

I want to build a spectrum analyser with ad9361+zynq .

I have three question:

1. I can't change the adc freq blow 3M with iio interface .

my code is as below 

```


void start_capture(){
if(!rx_thread.joinable()){
rx_thread = std::thread([&cap_i,&cap_q]()
{
struct iio_device *tx;
struct iio_device *rx;
/* scratch mem for strings */
char tmpstr[64];

/* IIO structs required for streaming */

// RX and TX sample counters
size_t nrx = 0;
size_t ntx = 0;

// Stream configurations
struct stream_cfg rxcfg;
struct stream_cfg txcfg;

// Listen to ctrl+c and IIO_ENSURE
signal(SIGINT, handle_sig);

// RX stream config
rxcfg.bw_hz = MHZ(20); // 2 MHz rf bandwidth
rxcfg.fs_hz = MHZ(g_capture_speed); // 2.5 MS/s rx sample rate
rxcfg.lo_hz = GHZ(0.5); // 2.5 GHz rf frequency
rxcfg.rfport = "A_BALANCED"; // port A (select for rf freq.)

// TX stream config
txcfg.bw_hz = MHZ(1.5); // 1.5 MHz rf bandwidth
txcfg.fs_hz = MHZ(2.5); // 2.5 MS/s tx sample rate
txcfg.lo_hz = GHZ(0.5); // 2.5 GHz rf frequency
txcfg.rfport = "A"; // port A (select for rf freq.)

printf("* Acquiring IIO context\n");

IIO_ENSURE((ctx = iio_create_default_context()) && "No context");


IIO_ENSURE(iio_context_get_devices_count(ctx) > 0 && "No devices");

printf("* Acquiring AD9361 streaming devices\n");
IIO_ENSURE(get_ad9361_stream_dev(TX, &tx) && "No tx dev found");
IIO_ENSURE(get_ad9361_stream_dev(RX, &rx) && "No rx dev found");

printf("* Configuring AD9361 for streaming\n");
IIO_ENSURE(cfg_ad9361_streaming_ch(&rxcfg, RX, 0) && "RX port 0 not found");
IIO_ENSURE(cfg_ad9361_streaming_ch(&txcfg, TX, 0) && "TX port 0 not found");

printf("* Initializing AD9361 IIO streaming channels\n");
IIO_ENSURE(get_ad9361_stream_ch(RX, rx, 0, &rx0_i) && "RX chan i not found");
IIO_ENSURE(get_ad9361_stream_ch(RX, rx, 1, &rx0_q) && "RX chan q not found");

printf("* Enabling IIO streaming channels\n");
iio_channel_enable(rx0_i);
iio_channel_enable(rx0_q);

printf("* Creating non-cyclic IIO buffers with 1 MiS\n");
rxbuf = iio_device_create_buffer(rx, 2048, false);

VectorXd in(2048);
VectorXcd fft(2048);
VectorXcd fft_f(2048);

while(!g_capture_status){

ssize_t nbytes_rx, nbytes_tx;
char *p_dat, *p_end;
ptrdiff_t p_inc;


nbytes_rx = iio_buffer_refill(rxbuf);
if (nbytes_rx < 0) {
printf("Error refilling buf %d\n",(int) nbytes_rx); shutdown();
}

// READ: Get pointers to RX buf and read IQ from RX buf port 0
p_inc = iio_buffer_step(rxbuf);
p_end = (char*)iio_buffer_end(rxbuf);
int z = 0;
static int count = 0;
for (p_dat = (char *)iio_buffer_first(rxbuf, rx0_i); p_dat < p_end; p_dat += p_inc) {
// Example: swap I and Q
const int16_t i = ((int16_t*)p_dat)[0]; // Real (I)
const int16_t q = ((int16_t*)p_dat)[1]; // Imag (Q)
((int16_t*)p_dat)[0] = q;
((int16_t*)p_dat)[1] = i;

if(z < 2048){
cap_i[z] = lv_coord_t(i);
z++;
}

}

count ++ ;
if(count %10 == 0){
fft_f = fft/2048;
for(int z = 0;z < 2048;z++){
in[z] = cap_i[z];
}
fft = FFT(in);

Eigen::VectorXd mag = fft_f.unaryExpr([](std::complex<double> c){return std::abs(c);}); // magnitude only.
std::vector<double> fft_f_std(mag.data(), mag.data()+mag.size()); // convert Eigen vector to std vector
z = 0;
for(int z = 0;z < 2048;z++){
cap_q[z] = int(fft_f_std[z])* 30;
z++;
}
rxcfg.lo_hz = GHZ(0.5) + MHZ(0.1); // 2.5 GHz rf frequency
cfg_ad9361_streaming_ch(&rxcfg, RX, 0);
}
gCaptureMux.lock();
lv_chart_refresh(ui_Chart2);
gCaptureMux.unlock();
}
}
);
}
}

```

2. i the rssi can detect frequency range changable? for example,I set the adc sample freq 50K for if ,the rssi read out means the singal from this 50K bandwith. It is call RBW from the concept of spectrum analyser.

3. How can I gert rssi register from iio interface?

Thread Notes