0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-29 14:51:26 +03:00
This commit is contained in:
OneOfEleven 2023-09-22 05:00:03 +01:00
parent 0cc5abfecc
commit 4dade7fbb9
5 changed files with 72 additions and 42 deletions

View File

@ -30,6 +30,7 @@ ENABLE_BOOT_BEEPS := 0 give user audio feedback on volume knob
ENABLE_COMPANDER := 1 compander option (per channel) ENABLE_COMPANDER := 1 compander option (per channel)
ENABLE_SHOW_CHARGE_LEVEL := 1 show the charge level when the radio is on charge ENABLE_SHOW_CHARGE_LEVEL := 1 show the charge level when the radio is on charge
ENABLE_REVERSE_BAT_SYMBOL := 1 mirror the battery symbol on the status bar (+ pole on the right) ENABLE_REVERSE_BAT_SYMBOL := 1 mirror the battery symbol on the status bar (+ pole on the right)
ENABLE_AM_FIX := 1 dynamically adjust the front end gains when in AM mode to helo prevent AM demodulator saturation - ignore the on-screen RSSI (for now)
ENABLE_AUDIO_BAR := 0 experimental, display an audo bar level when TX'ing ENABLE_AUDIO_BAR := 0 experimental, display an audo bar level when TX'ing
#ENABLE_SINGLE_VFO_CHAN := 1 not yet implemented - single VFO on display when possible #ENABLE_SINGLE_VFO_CHAN := 1 not yet implemented - single VFO on display when possible
#ENABLE_BAND_SCOPE := 1 not yet implemented - spectrum/pan-adapter #ENABLE_BAND_SCOPE := 1 not yet implemented - spectrum/pan-adapter

View File

@ -69,9 +69,15 @@ static uint16_t mixer = 3; // 0dB
static uint16_t pga = 6; // -3dB static uint16_t pga = 6; // -3dB
#ifdef ENABLE_AM_FIX #ifdef ENABLE_AM_FIX
// computes the average RSSI level over several samples // moving average RSSI buffer
static unsigned int avg_rssi_counter = 0; struct {
static uint16_t avg_rssi = 0; unsigned int index;
uint16_t samples[10]; // 100ms long buffer (10ms RSSI sample rate)
uint16_t sum; // sum of all samples in the buffer
} moving_avg_rssi;
unsigned int rssi_peak_hold_val = 0;
unsigned int rssi_peak_hold_count = 0;
#endif #endif
static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld); static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
@ -426,8 +432,10 @@ void APP_StartListening(FUNCTION_Type_t Function)
#endif #endif
#ifdef ENABLE_AM_FIX #ifdef ENABLE_AM_FIX
avg_rssi_counter = 0; // reset the moving average filter
avg_rssi = 0; memset(&moving_avg_rssi, 0, sizeof(moving_avg_rssi));
rssi_peak_hold_val = 0;
rssi_peak_hold_count = 0;
#endif #endif
gVFO_RSSI_Level[gEeprom.RX_CHANNEL == 0] = 0; gVFO_RSSI_Level[gEeprom.RX_CHANNEL == 0] = 0;
@ -1359,7 +1367,7 @@ void APP_CheckKeys(void)
// REG_10 <15:0> 0x0038 Rx AGC Gain Table[0]. (Index Max->Min is 3,2,1,0,-1) // REG_10 <15:0> 0x0038 Rx AGC Gain Table[0]. (Index Max->Min is 3,2,1,0,-1)
// //
// <9:8> = LNA Gain Short // <9:8> = LNA Gain Short
// 3 = 0dB // 3 = 0dB < original value
// 2 = -11dB // 2 = -11dB
// 1 = -16dB // 1 = -16dB
// 0 = -19dB // 0 = -19dB
@ -1370,19 +1378,19 @@ void APP_CheckKeys(void)
// 5 = -4dB // 5 = -4dB
// 4 = -6dB // 4 = -6dB
// 3 = -9dB // 3 = -9dB
// 2 = -14dB // 2 = -14dB < original value
// 1 = -19dB // 1 = -19dB
// 0 = -24dB // 0 = -24dB
// //
// <4:3> = MIXER Gain // <4:3> = MIXER Gain
// 3 = 0dB // 3 = 0dB < original value
// 2 = -3dB // 2 = -3dB
// 1 = -6dB // 1 = -6dB
// 0 = -8dB // 0 = -8dB
// //
// <2:0> = PGA Gain // <2:0> = PGA Gain
// 7 = 0dB // 7 = 0dB
// 6 = -3dB // 6 = -3dB < original value
// 5 = -6dB // 5 = -6dB
// 4 = -9dB // 4 = -9dB
// 3 = -15dB // 3 = -15dB
@ -1397,34 +1405,36 @@ void APP_CheckKeys(void)
register uint16_t new_pga = pga; register uint16_t new_pga = pga;
// -86dBm, any higher and the AM demodulator starts to saturate // -86dBm, any higher and the AM demodulator starts to saturate
const uint16_t desired_rssi = (-86 + 160) * 2; const uint16_t desired_rssi = (-86 + 160) * 2; // dBm to ADC sample
// sample the current RSSI level // sample the current RSSI level
gCurrentRSSI = BK4819_GetRSSI(); uint16_t rssi = BK4819_GetRSSI(); // 9-bit value
//gCurrentRSSI = rssi;
// compute the moving average RSSI
moving_avg_rssi.sum -= moving_avg_rssi.samples[moving_avg_rssi.index]; // remove the oldest sample
moving_avg_rssi.sum += rssi; // add the newest sample
moving_avg_rssi.samples[moving_avg_rssi.index] = rssi; // save the newest sample
if (++moving_avg_rssi.index >= ARRAY_SIZE(moving_avg_rssi.samples)) //
moving_avg_rssi.index = 0; // wrap-a-round
// compute the average // compute the average
avg_rssi += gCurrentRSSI; rssi = moving_avg_rssi.sum / ARRAY_SIZE(moving_avg_rssi.samples);
if (++avg_rssi_counter < 16) // 160ms - rate at which we adjust the front end gains
return;
avg_rssi /= avg_rssi_counter;
if (avg_rssi < (desired_rssi - 4)) if (rssi >= rssi_peak_hold_val)
{ // increase gain { // enter hold mode (pause any gain increases)
if (new_pga < 7) rssi_peak_hold_val = rssi;
new_pga++; rssi_peak_hold_count = 50; // 500ms
else
if (new_mixer < 3)
new_mixer++;
else
if (new_lna < 7)
new_lna++;
else
if (new_lna_short < 3)
new_lna_short++;
} }
else else
if (avg_rssi > (desired_rssi + 4)) if (rssi_peak_hold_count > 0)
rssi_peak_hold_count--;
else
rssi_peak_hold_val = rssi;
if (rssi > (desired_rssi + 4))
{ // decrease gain { // decrease gain
if (new_pga > 6) if (new_pga > 6)
new_pga--; new_pga--;
else else
@ -1447,13 +1457,32 @@ void APP_CheckKeys(void)
new_mixer--; new_mixer--;
} }
avg_rssi_counter = 0; if (moving_avg_rssi.index > 0)
avg_rssi = 0; { // increase gain once every 100ms
if (rssi_peak_hold_count == 0)
{
if (rssi < (desired_rssi - 4))
{ // increase gain
if (new_pga < 7)
new_pga++;
else
if (new_mixer < 3)
new_mixer++;
else
if (new_lna < 7)
new_lna++;
else
if (new_lna_short < 3)
new_lna_short++;
}
}
}
if (lna_short == new_lna_short && lna == new_lna && mixer == new_mixer && pga == new_pga) if (lna_short == new_lna_short && lna == new_lna && mixer == new_mixer && pga == new_pga)
return; // no change return; // no change
// apply the adjusted gain settings // apply the new gain settings to the front end
lna_short = new_lna_short; lna_short = new_lna_short;
lna = new_lna; lna = new_lna;

BIN
firmware

Binary file not shown.

Binary file not shown.

Binary file not shown.