LimeSDR LMS_SetNCOFrequency

When we are calling the LMS_SetNCOFrequency, it gives the following error: “NCO frequency is negative or outside of RF bandwidth range”. If we want to set the center frequency to be lower than 30MHz, how should we call 2 functions below?


 [DllImport("LimeSuite", CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern int LMS_SetNCOFrequency(IntPtr device, bool dir_tx, uint chan, float* freq, double pho);
 [DllImport("LimeSuite", CallingConvention = CallingConvention.Cdecl)]
        public static extern int LMS_SetNCOIndex(IntPtr device, bool dir_tx, uint chan, int index, bool downconv);

2)Setting frequency (Say I do not want to set center frefrencuy of 25M, bandwidth 2M):

UnsafeBuffer freqs = UnsafeBuffer.Create(16, sizeof(float));
float* _freqPtr = (float*)freqs;
for(int i = 0 ; i <16; i++)
_freqPtr[i] = (float)(25000000.0);
if (NativeMethods.LMS_SetNCOFrequency(this._device, false, this._channel, _freqPtr, 0.0) != 0)
throw new ApplicationException(NativeMethods.limesdr_strerror());
if (NativeMethods.LMS_SetNCOIndex(this._device, false, this._channel, 0, true) != 0) //set nco index
throw new ApplicationException(NativeMethods.limesdr_strerror());

This is C# dll import definition functions but your implementation is wrong because UnsafeBuffer is a class not float array. Take a look at:

and set frequency method public unsafe long Frequency
Algo is to fix local oscillator to 30Mhz and calculate NCO difference:
losc_freq[0] = (30.0 * 1e6) - _centerFrequency;

1 Like