0

I am having trouble getting a custom block to operate at high frequency.

The block I would like to use is going to take in data from an external radio.

I am using an Ettus USRP block to stream data in from this radio, and I can display this on the QT Scope. I can set this block's sample rate to 15 MHz, and with the scope this seems to work ok.

Problem:

I have tried making a simple block with the gnuradio gr_modtool which takes in 2 floats as input and has 0 outputs. The block has private members "timer", a time_t, and "counter", an int. In the "work" function, my code simply does this at the moment:

const float *in_i = (const float *) input_items[0];
const float *in_q = (const float *) input_items[1];

if (count == 0){
    if (*in_i > 0.5){
        timer = clock();
        count = 30000;
    }
}else{
    count --;
    if(count == 0){
        timer = clock()-timer;
        printf("Count took %d clicks, or %f seconds\n",timer,(float)timer/CLOCKS_PER_SEC);
    }
}
  // Tell runtime system how many output items we produced.
  return 0;

However, when I run this code, it takes longer than the expected time. For 30000 cycles, it takes 0.872970 to complete, instead of the desired 0.002 seconds. Since the standard gnuradio block generated with gr_modtool is a sync block, and the input stream to the block is coming from the 15 MHz USRP, I would have expected this block to run at that same frequency. This is not currently the case.

Eventually my goal is to be able to store data streaming in over a period of time, and write it to file with certain formatting(A block already exists to do this, but there is some sort of bug that is preventing that block and the USRP block from working at the same time, so I am attempting to write my own.). However, unless I can keep up with the sample rate of 15 MHz, I will lose data. Since this block is fairly simple, I would have hoped it would be able to run quickly enough to keep up. However, the input stream block is able to pull data from the radio and output at 15 MHz, so I know my computer is capable of it.

How can I make this custom block operate more quickly, and keep up with the 15 MHz frequency?(Or, how can I make this sync block operate at the input stream frequency, since it currently does not)

Zephyr
  • 337
  • 5
  • 23

1 Answers1

0

Your block is not consuming any samples. I presume you're writing a sync_block (work function, not general_work), so your number of produced items is identical to the number of consumed items. But as your source code says:

// Tell runtime system how many output items we produced.
return 0;

In other words, your block tells GNU Radio that it didn't use any of the input GNU Radio offered, and produced no output. That means GNU Radio can't do nothing. You must return the number of items you've produced, and for sync blocks, that's the number of items you consumed – even if you're a sink, with zero output streams!

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • Well I'm actually writing a sink block, but when you use gr_modtool to make a sink, it inherits from the "sync" block. The only difference being that the io_signature for the output has 0 for the minimum and maximum number. So I am not returning any items, but I am still consuming. Since the default for the return is noutput_items, I put 0 because I am not outputting a stream. – Zephyr Dec 07 '16 at 20:53
  • As said, a sink should be a sync_blcok and it **must** return the number of items you've consumed. – Marcus Müller Dec 07 '16 at 23:19
  • To repeat that: For a sink to consume, you must "produce". – Marcus Müller Dec 08 '16 at 01:12