Page 1 of 1

Issue with BladeRF Sync Interface Transmitting Half Data at 16 MS/s

Posted: Sat Dec 02, 2023 8:10 am
by SDRUSERJAPAN
Hello,

I am experiencing an issue with the BladeRF's synchronous transmission interface. I'm using a simple setup to transmit a signal from a circular buffer. When I set the sampling rate to 16 MS/s, it seems that only half of the generated data in the buffer is being transmitted. The spectrum of the transmitted signal appears correct, and modulation is applied as expected.

Interestingly, if I reduce the sampling rate to 8 MS/s, the entire content of the buffer is transmitted correctly, and the interface seems to take the correct amount of data.

Below is the code I am using:

Code: Select all

#include <libbladeRF.h>

#define TX_FREQUENCY	1000000000
#define TX_SAMPLERATE	16368000.
#define TX_BANDWIDTH	8000000.
#define TX_GAIN	40 

#define NUM_BUFFERS			32//16//
#define SAMPLES_PER_BUFFER	(32 * 1024)//(16*1024) //
#define NUM_TRANSFERS		16//8 //
#define TIMEOUT_MS			3000

int StartRtThread_USB4(void *fdata)
{
	// bladeRF_sync(void)
	struct bladerf *dev = nullptr;
	int status;

	// Open the first available device
	status = bladerf_open(&dev, nullptr);
	if (status != 0) {
		//std::cerr << "Failed to open bladeRF device: " << bladerf_strerror(status) << std::endl;
		return status;
	}

	bladerf_channel tx_channel = BLADERF_CHANNEL_TX(0);

	// Set frequency, sample rate, bandwidth, and gain
	status = bladerf_set_frequency(dev, tx_channel, TX_FREQUENCY);
	status |= bladerf_set_sample_rate(dev, tx_channel, TX_SAMPLERATE, NULL);
	//status |= bladerf_set_bandwidth(dev, tx_channel, TX_BANDWIDTH, NULL);
	status |= bladerf_set_gain(dev, tx_channel, TX_GAIN);
	if (status != 0) {
		//std::cerr << "Failed to configure device: " << bladerf_strerror(status) << std::endl;
		bladerf_close(dev);
		return status;
	}

	// Configure the synchronous interface for transmission
	status = bladerf_sync_config(dev,
		BLADERF_TX_X1,
		BLADERF_FORMAT_SC16_Q11,
		NUM_BUFFERS,
		SAMPLES_PER_BUFFER,
		NUM_TRANSFERS,
		TIMEOUT_MS);

	if (status != 0)
	{
		//std::cerr << "Failed to configure synchronous interface: " << bladerf_strerror(status) << std::endl;
		bladerf_close(dev);
		return status;
	}

	// Enable the TX module
	status = bladerf_enable_module(dev, tx_channel, true);
	if (status != 0)
	{
		//std::cerr << "Failed to enable TX module: " << bladerf_strerror(status) << std::endl;
		bladerf_close(dev);
		return status;
	}


	static __int64 tlen2 = 0;

	short *buffer;
	buffer = new short[SAMPLES_PER_BUFFER * 4];

	while (*lRUN)
	{	

		tlen2 = tlen2 + SAMPLES_PER_BUFFER * 2;

		static unsigned int iTem = (tlen2) % (XIFBUF_SIZE8);

		memcpy(buffer, &XIC8[iTem], SAMPLES_PER_BUFFER * 4); // XIC8 is circular buffer

		//buffer = &XIC8[iTem]; //alternative 

 // safe pointer for signal generator thread
			__int64 *pRead = GetPointerTo_pRead();
			*pRead = tlen2;
			ReleasePointerTo_pRead();
	

		status = bladerf_sync_tx(dev, buffer, SAMPLES_PER_BUFFER, NULL, TIMEOUT_MS);
		if (status != 0) {
			//std::cerr << "Failed to transmit: " << bladerf_strerror(status) << std::endl;
			break;
		}
	}

	// Disable the TX module and close the device
	bladerf_enable_module(dev, tx_channel, false);
	bladerf_close(dev);

	return 0;
}
The behavior at 16 MS/s is puzzling because it seems to transmit data at half the set rate, effectively behaving like it's set to 8 MS/s. I've checked and rechecked my buffer management and data generation code, and everything appears to be in order.

Has anyone encountered a similar issue or can offer insights into what might be causing this behavior? Any suggestions on how to ensure full data transmission at 16 MS/s would be greatly appreciated.

Thank you in advance for your help!