From 055af67a4ef9989dfdc220276191aac061795faf Mon Sep 17 00:00:00 2001 From: Thomas Tsou Date: Mon, 23 May 2011 14:26:52 -0700 Subject: [PATCH] transceiver: rework digital gain settings The output of the modulator or resampler is scaled and converted from floating point to fixed point. The scaling factor is the leftover dB in RF attention (relative to max transmit power), which is handled prior to the integer conversion. This should work across all daughterboards and non-UHD installations. Signed-off-by: Thomas Tsou --- public-trunk/Transceiver/radioInterface.cpp | 12 ++++++++---- public-trunk/Transceiver/radioInterface.h | 2 ++ public-trunk/Transceiver52M/Transceiver.cpp | 2 +- public-trunk/Transceiver52M/radioInterface.cpp | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/public-trunk/Transceiver/radioInterface.cpp b/public-trunk/Transceiver/radioInterface.cpp index 5c6483a..327f2b7 100644 --- a/public-trunk/Transceiver/radioInterface.cpp +++ b/public-trunk/Transceiver/radioInterface.cpp @@ -58,7 +58,7 @@ RadioInterface::RadioInterface(RadioDevice *wUsrp, receiveOffset = wReceiveOffset; samplesPerSymbol = wSamplesPerSymbol; mClock.set(wStartTime); - + powerScaling = 1.0; } RadioInterface::~RadioInterface(void) { @@ -82,7 +82,12 @@ double RadioInterface::fullScaleOutputValue(void) { void RadioInterface::setPowerAttenuation(double atten) { - usrp->setTxGain(usrp->maxTxGain() - atten); + double HWatten = usrp->setTxGain(usrp->maxTxGain() - atten); + atten -= HWatten; + if (atten < 1.0) + powerScaling = 1.0; + else + powerScaling = 1.0 / sqrt(pow(10, (atten / 10.0))); } short *RadioInterface::USRPifyVector(signalVector &wVector) @@ -150,8 +155,7 @@ void RadioInterface::pushBuffer(void) { delete inputVector; // Set transmit gain and power here. - scaleVector(*resampledVector,13500.0); ///2.25); // this gets 2W out of 3318PA at 885Mhz - //scaleVector(*resampledVector,100.0); + scaleVector(*resampledVector, powerScaling * usrp->fullScaleInputValue()); short *resampledVectorShort = USRPifyVector(*resampledVector); diff --git a/public-trunk/Transceiver/radioInterface.h b/public-trunk/Transceiver/radioInterface.h index 94d0166..4d3fb21 100644 --- a/public-trunk/Transceiver/radioInterface.h +++ b/public-trunk/Transceiver/radioInterface.h @@ -142,6 +142,8 @@ private: bool mOn; ///< indicates radio is on + double powerScaling; + /** format samples to USRP */ short *USRPifyVector(signalVector &wVector); diff --git a/public-trunk/Transceiver52M/Transceiver.cpp b/public-trunk/Transceiver52M/Transceiver.cpp index 57ff81f..036a4d8 100644 --- a/public-trunk/Transceiver52M/Transceiver.cpp +++ b/public-trunk/Transceiver52M/Transceiver.cpp @@ -513,7 +513,7 @@ void Transceiver::driveControl() sprintf(response,"RSP SETPOWER 1 %d",dbPwr); else { mPower = dbPwr; - mRadioInterface->setPowerAttenuation(pow(10.0,dbPwr/10.0)); + mRadioInterface->setPowerAttenuation(dbPwr); sprintf(response,"RSP SETPOWER 0 %d",dbPwr); } } diff --git a/public-trunk/Transceiver52M/radioInterface.cpp b/public-trunk/Transceiver52M/radioInterface.cpp index c4f8d23..69f563c 100644 --- a/public-trunk/Transceiver52M/radioInterface.cpp +++ b/public-trunk/Transceiver52M/radioInterface.cpp @@ -110,11 +110,11 @@ double RadioInterface::fullScaleOutputValue(void) { void RadioInterface::setPowerAttenuation(double atten) { double HWatten = mRadio->setTxGain(mRadio->maxTxGain() - atten); - atten -= (-HWatten); + atten -= HWatten; if (atten < 1.0) powerScaling = 1.0; else - powerScaling = 1.0/sqrt(atten); + powerScaling = 1.0 / sqrt(pow(10, (atten / 10.0))); } short *RadioInterface::radioifyVector(signalVector &wVector, short *retVector, double scale, bool zeroOut)