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

Discussions related to embedded firmware, driver, and user mode application software development
Post Reply
SDRUSERJAPAN
Posts: 2
Joined: Sat Dec 02, 2023 7:32 am

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

Post 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!
vesqueeze
Posts: 1
Joined: Wed Dec 20, 2023 7:37 pm

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

Post by vesqueeze »

It appears that the issue you're facing might be related to the way the BladeRF is configured and the data handling in your code. The fact that you observe correct behavior at 8 MS/s but not at 16 MS/s suggests a potential timing or synchronization issue.
Here is my suggestion to investigate and potentially resolve the issue:
Buffer Alignment: Ensure that your buffer is aligned correctly according to the BladeRF's requirements. Improper alignment could lead to unexpected behavior, especially at higher sampling rates.
Post Reply