AnsweredAssumed Answered

Ad7266 - Fetching samples takes too long

Question asked by eddi on Sep 7, 2016
Latest reply on Sep 23, 2016 by eddi

Hallo,

 

I want to fetch 2048 samples in 20 ms from the ad7266. But it takes about 1000ms. 

I tried to set the timeout in iio_context_set_timeout() but every value greater than 0 gives an -110 error (Timeout error).

As trigger I use the hrtimer from kernel 4.7.

 

Maybe the device is not able to fetch this samples in this time cause of the warning "WARNING: High-speed mode not enabled" but the datasheet http://www.analog.com/media/en/technical-documentation/data-sheets/AD7266.pdf  says this is a 2 MSPS device. Or I am wrong?

 

Further information to my device is in this forum thread: Ad7266 - How to use the buffer and trigger with libiio? 

 

Questions:

1. Is it even possible to fetch 2048 samples in 20 ms with that device? Look at "High-speed mode not enabled"-warning

2. Why I cannot set a timeout?

 

Thanks.

 

Source code:

#include <stdio.h>
#include <iio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include "log.h"

 

#define SAMPLES 2048

 

struct iio_context *context = NULL;
struct iio_device *device = NULL;
struct iio_device *trigger = NULL;
struct iio_channel *channel = NULL;
struct iio_buffer *buffer = NULL;

 

static void init_buffer()
{
    int ret;

 

    context = iio_create_local_context();
    LOG_Notice(__FILE__, __FUNCTION__, __LINE__, "IIO_BUF", "Context: %p", context);

 

    ret = iio_context_set_timeout(context, 0);
    LOG_Notice(__FILE__, __FUNCTION__, __LINE__, "IIO_BUF", "Cxt_Timeout: %d", ret);

 

    device =  iio_context_get_device(context, 4);
    LOG_Notice(__FILE__, __FUNCTION__, __LINE__, "IIO_BUF", "Device: %p", device);

 

    channel =  iio_device_get_channel(device, 0);
    LOG_Notice(__FILE__, __FUNCTION__, __LINE__, "IIO_BUF", "Channel: %p", channel);

 

    trigger =  iio_context_get_device(context, 1);
    LOG_Notice(__FILE__, __FUNCTION__, __LINE__, "IIO_BUF", "Trigger: %p", trigger);

 

    ret = iio_device_attr_write_longlong(trigger, "sampling_frequency", SAMPLES);
    LOG_Notice(__FILE__, __FUNCTION__, __LINE__, "IIO_BUF", "Write sampling_frequency: %d", ret);

 

    ret = iio_device_set_trigger(device, trigger);
    LOG_Notice(__FILE__, __FUNCTION__, __LINE__, "IIO_BUF", "Set trigger: %d", ret);

 

    iio_channel_enable(channel);
    buffer =  iio_device_create_buffer(device, SAMPLES, 0);
    LOG_Notice(__FILE__, __FUNCTION__, __LINE__, "IIO_BUF", "Buffer: %p\n", buffer);
}

 

static void read_buffer()
{
    int ret;

 

    LOG_Notice(__FILE__, __FUNCTION__, __LINE__, "IIO_BUF", "Start reading buffer");
    ret = iio_buffer_refill(buffer);
    LOG_Notice(__FILE__, __FUNCTION__, __LINE__, "IIO_BUF", "End reading buffer: Ret: %d\n", ret);
}

 


int main()
{    
    LOG_Init();

 

    init_buffer();    

 

    read_buffer();
    read_buffer();
    read_buffer();
    read_buffer();
    read_buffer();

 

    return 0;
}

 

Output:

1970.01.01-01:05:26.920 - [NOTICE] IIO_BUF: init_buffer() => Context: 0xa09008
1970.01.01-01:05:26.980 - [NOTICE] IIO_BUF: init_buffer() => Cxt_Timeout: 0
1970.01.01-01:05:26.35 - [NOTICE] IIO_BUF: init_buffer() => Device: 0xa0bb10
1970.01.01-01:05:26.87 - [NOTICE] IIO_BUF: init_buffer() => Channel: 0xa0bce0
1970.01.01-01:05:26.125 - [NOTICE] IIO_BUF: init_buffer() => Trigger: 0xa0a240
1970.01.01-01:05:26.199 - [NOTICE] IIO_BUF: init_buffer() => Write sampling_frequency: 0
1970.01.01-01:05:26.290 - [NOTICE] IIO_BUF: init_buffer() => Set trigger: 0
WARNING: High-speed mode not enabled
1970.01.01-01:05:26.399 - [NOTICE] IIO_BUF: init_buffer() => Buffer: 0xa0fab8

 

1970.01.01-01:05:26.456 - [NOTICE] IIO_BUF: read_buffer() => Start reading buffer
1970.01.01-01:05:27.440 - [NOTICE] IIO_BUF: read_buffer() => End reading buffer: Ret: 4096

 

1970.01.01-01:05:27.510 - [NOTICE] IIO_BUF: read_buffer() => Start reading buffer
1970.01.01-01:05:28.470 - [NOTICE] IIO_BUF: read_buffer() => End reading buffer: Ret: 4096

 

1970.01.01-01:05:28.541 - [NOTICE] IIO_BUF: read_buffer() => Start reading buffer
1970.01.01-01:05:29.507 - [NOTICE] IIO_BUF: read_buffer() => End reading buffer: Ret: 4096

 

1970.01.01-01:05:29.564 - [NOTICE] IIO_BUF: read_buffer() => Start reading buffer
1970.01.01-01:05:30.537 - [NOTICE] IIO_BUF: read_buffer() => End reading buffer: Ret: 4096

 

1970.01.01-01:05:30.616 - [NOTICE] IIO_BUF: read_buffer() => Start reading buffer
1970.01.01-01:05:31.574 - [NOTICE] IIO_BUF: read_buffer() => End reading buffer: Ret: 4096

Outcomes