AM fix modification

This commit is contained in:
Krzysiek Egzmont
2023-12-06 17:54:32 +01:00
parent e95f577074
commit c1a009cc2f
8 changed files with 66 additions and 35 deletions

View File

@@ -33,7 +33,7 @@ ENABLE_BOOT_BEEPS := 0
ENABLE_SHOW_CHARGE_LEVEL := 0 ENABLE_SHOW_CHARGE_LEVEL := 0
ENABLE_REVERSE_BAT_SYMBOL := 0 ENABLE_REVERSE_BAT_SYMBOL := 0
ENABLE_NO_CODE_SCAN_TIMEOUT := 1 ENABLE_NO_CODE_SCAN_TIMEOUT := 1
ENABLE_AM_FIX := 0 ENABLE_AM_FIX := 1
ENABLE_SQUELCH_MORE_SENSITIVE := 1 ENABLE_SQUELCH_MORE_SENSITIVE := 1
ENABLE_FASTER_CHANNEL_SCAN := 1 ENABLE_FASTER_CHANNEL_SCAN := 1
ENABLE_RSSI_BAR := 1 ENABLE_RSSI_BAR := 1

View File

@@ -29,6 +29,7 @@
#include "frequencies.h" #include "frequencies.h"
#include "functions.h" #include "functions.h"
#include "misc.h" #include "misc.h"
#include "settings.h"
#ifdef ENABLE_AM_FIX #ifdef ENABLE_AM_FIX
@@ -186,7 +187,7 @@ static const t_gain_table gain_table[] =
{0x03FF, 0}, // 91 .. 3 7 3 7 .. 0dB 0dB 0dB 0dB .. 0dB {0x03FF, 0}, // 91 .. 3 7 3 7 .. 0dB 0dB 0dB 0dB .. 0dB
}; };
static const unsigned int original_index = 85; static const unsigned int original_index = ARRAY_SIZE(gain_table) - 7;
#ifdef ENABLE_AM_FIX_SHOW_DATA #ifdef ENABLE_AM_FIX_SHOW_DATA
// display update rate // display update rate
@@ -212,6 +213,9 @@ const unsigned max_index = ARRAY_SIZE(gain_table) - 1;
// -89dBm, any higher and the AM demodulator starts to saturate/clip/distort // -89dBm, any higher and the AM demodulator starts to saturate/clip/distort
const int16_t desired_rssi = (-89 + 160) * 2; const int16_t desired_rssi = (-89 + 160) * 2;
int8_t currentGainDiff;
bool enabled = true;
void AM_fix_init(void) void AM_fix_init(void)
{ // called at boot-up { // called at boot-up
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
@@ -242,7 +246,7 @@ void AM_fix_reset(const unsigned vfo)
// //
void AM_fix_10ms(const unsigned vfo, bool force) void AM_fix_10ms(const unsigned vfo, bool force)
{ {
if(vfo > 1) if(!gSetting_AM_fix || !enabled || vfo > 1 )
return; return;
if(!force) switch (gCurrentFunction) if(!force) switch (gCurrentFunction)
@@ -254,7 +258,6 @@ void AM_fix_10ms(const unsigned vfo, bool force)
#ifdef ENABLE_AM_FIX_SHOW_DATA #ifdef ENABLE_AM_FIX_SHOW_DATA
counter = display_update_rate; // queue up a display update as soon as we switch to RX mode counter = display_update_rate; // queue up a display update as soon as we switch to RX mode
#endif #endif
AM_fix_reset(vfo);
return; return;
// only adjust stuff if we're in one of these modes // only adjust stuff if we're in one of these modes
@@ -273,6 +276,12 @@ void AM_fix_10ms(const unsigned vfo, bool force)
} }
#endif #endif
static uint32_t lastFreq[2];
if(gEeprom.VfoInfo[vfo].pRX->Frequency != lastFreq[vfo]) {
lastFreq[vfo] = gEeprom.VfoInfo[vfo].pRX->Frequency;
AM_fix_reset(vfo);
}
int16_t rssi; int16_t rssi;
{ // sample the current RSSI level { // sample the current RSSI level
// average it with the previous rssi (a bit of noise/spike immunity) // average it with the previous rssi (a bit of noise/spike immunity)
@@ -348,7 +357,7 @@ void AM_fix_10ms(const unsigned vfo, bool force)
// remember the new table index // remember the new table index
gain_table_index_prev[vfo] = index; gain_table_index_prev[vfo] = index;
currentGainDiff = gain_table[original_index].gain_dB - gain_table[index].gain_dB;
BK4819_WriteRegister(BK4819_REG_13, gain_table[index].reg_val); BK4819_WriteRegister(BK4819_REG_13, gain_table[index].reg_val);
} }
@@ -370,5 +379,13 @@ void AM_fix_print_data(const unsigned vfo, char *s) {
} }
#endif #endif
int8_t AM_fix_get_gain_diff()
{
return currentGainDiff;
}
void AM_fix_enable(bool on)
{
enabled = on;
}
#endif #endif

View File

@@ -22,11 +22,14 @@
#ifdef ENABLE_AM_FIX #ifdef ENABLE_AM_FIX
void AM_fix_init(void); void AM_fix_init(void);
void AM_fix_reset(const unsigned vfo);
void AM_fix_10ms(const unsigned vfo, bool force); void AM_fix_10ms(const unsigned vfo, bool force);
#ifdef ENABLE_AM_FIX_SHOW_DATA #ifdef ENABLE_AM_FIX_SHOW_DATA
void AM_fix_print_data(const unsigned vfo, char *s); void AM_fix_print_data(const unsigned vfo, char *s);
#endif #endif
int8_t AM_fix_get_gain_diff();
void AM_fix_enable(bool on);
#endif #endif
#endif #endif

View File

@@ -1121,7 +1121,7 @@ void APP_TimeSlice10ms(void)
#endif #endif
#ifdef ENABLE_AM_FIX #ifdef ENABLE_AM_FIX
if (gRxVfo->Modulation == MODULATION_AM && gSetting_AM_fix) if (gRxVfo->Modulation == MODULATION_AM)
AM_fix_10ms(gEeprom.RX_VFO, false); AM_fix_10ms(gEeprom.RX_VFO, false);
#endif #endif

View File

@@ -113,8 +113,7 @@ static uint16_t GetRegMenuValue(uint8_t st) {
void LockAGC() void LockAGC()
{ {
if(!lockAGC) RADIO_SetupAGC(true, lockAGC);
BK4819_SetAGC(0);
lockAGC = true; lockAGC = true;
} }
@@ -492,13 +491,6 @@ static void ToggleModulation() {
} }
RADIO_SetModulation(settings.modulationType); RADIO_SetModulation(settings.modulationType);
#ifdef ENABLE_AM_FIX
if(gSetting_AM_fix && settings.modulationType != MODULATION_AM) {
BK4819_InitAGC(false);
BK4819_SetAGC(1);
}
#endif
RelaunchScan(); RelaunchScan();
redrawScreen = true; redrawScreen = true;
} }
@@ -1178,13 +1170,6 @@ void APP_RunSpectrum() {
ToggleRX(true), ToggleRX(false); // hack to prevent noise when squelch off ToggleRX(true), ToggleRX(false); // hack to prevent noise when squelch off
RADIO_SetModulation(settings.modulationType = gRxVfo->Modulation); RADIO_SetModulation(settings.modulationType = gRxVfo->Modulation);
#ifdef ENABLE_AM_FIX
if(settings.modulationType != MODULATION_AM) {
BK4819_InitAGC(false);
BK4819_SetAGC(true);
}
#endif
BK4819_SetFilterBandwidth(settings.listenBw = BK4819_FILTER_BW_WIDE, false); BK4819_SetFilterBandwidth(settings.listenBw = BK4819_FILTER_BW_WIDE, false);
RelaunchScan(); RelaunchScan();

41
radio.c
View File

@@ -772,12 +772,7 @@ void RADIO_SetupRegisters(bool switchToForeground)
} }
#endif #endif
#ifdef ENABLE_AM_FIX RADIO_SetupAGC(false, false);
if(gSetting_AM_fix) {
BK4819_SetAGC(true);
BK4819_InitAGC(false);
}
#endif
// enable/disable BK4819 selected interrupts // enable/disable BK4819 selected interrupts
BK4819_WriteRegister(BK4819_REG_3F, InterruptMask); BK4819_WriteRegister(BK4819_REG_3F, InterruptMask);
@@ -926,12 +921,36 @@ void RADIO_SetModulation(ModulationMode_t modulation)
BK4819_SetRegValue(afDacGainRegSpec, 0xF); BK4819_SetRegValue(afDacGainRegSpec, 0xF);
BK4819_WriteRegister(BK4819_REG_3D, modulation == MODULATION_USB ? 0 : 0x2AAB); BK4819_WriteRegister(BK4819_REG_3D, modulation == MODULATION_USB ? 0 : 0x2AAB);
BK4819_SetRegValue(afcDisableRegSpec, modulation != MODULATION_FM); BK4819_SetRegValue(afcDisableRegSpec, modulation != MODULATION_FM);
#ifdef ENABLE_AM_FIX
if(modulation == MODULATION_AM && gSetting_AM_fix) { RADIO_SetupAGC(modulation == MODULATION_AM, false);
BK4819_SetAGC(0); }
void RADIO_SetupAGC(bool listeningAM, bool disable)
{
static uint8_t lastSettings;
uint8_t newSettings = (listeningAM << 1) | (disable << 1);
if(lastSettings == newSettings)
return;
lastSettings = newSettings;
if(!listeningAM) { // if not actively listening AM we don't need any AM specific regulation
BK4819_SetAGC(1);
BK4819_InitAGC(false);
} }
else {
#ifdef ENABLE_AM_FIX
if(gSetting_AM_fix) { // if AM fix active lock AGC so AM-fix can do it's job
BK4819_SetAGC(0);
AM_fix_enable(!disable);
}
else
#endif #endif
BK4819_InitAGC(modulation == MODULATION_AM); {
BK4819_SetAGC(!disable);
BK4819_InitAGC(true);
}
}
} }
void RADIO_SetVfoState(VfoState_t State) void RADIO_SetVfoState(VfoState_t State)
@@ -1149,4 +1168,4 @@ void RADIO_SendEndOfTransmission(void)
} }
BK4819_ExitDTMF_TX(true); BK4819_ExitDTMF_TX(true);
} }

View File

@@ -159,6 +159,7 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0);
void RADIO_ConfigureNOAA(void); void RADIO_ConfigureNOAA(void);
#endif #endif
void RADIO_SetTxParameters(void); void RADIO_SetTxParameters(void);
void RADIO_SetupAGC(bool listeningAM, bool disable);
void RADIO_SetModulation(ModulationMode_t modulation); void RADIO_SetModulation(ModulationMode_t modulation);
void RADIO_SetVfoState(VfoState_t State); void RADIO_SetVfoState(VfoState_t State);
void RADIO_PrepareTX(void); void RADIO_PrepareTX(void);

View File

@@ -189,7 +189,13 @@ void DisplayRSSIBar(const bool now)
const int16_t s0_dBm = -130; // S0 .. base level const int16_t s0_dBm = -130; // S0 .. base level
const int16_t rssi_dBm = BK4819_GetRSSI_dBm() + dBmCorrTable[gRxVfo->Band]; const int16_t rssi_dBm =
BK4819_GetRSSI_dBm()
#ifdef ENABLE_AM_FIX
+ (gSetting_AM_fix ? AM_fix_get_gain_diff() : 0)
#endif
+ dBmCorrTable[gRxVfo->Band];
const uint8_t s_level = MIN(MAX((rssi_dBm - s0_dBm) / 6, 0), 9); // S0 - S9 const uint8_t s_level = MIN(MAX((rssi_dBm - s0_dBm) / 6, 0), 9); // S0 - S9
uint8_t overS9dBm = MIN(MAX(rssi_dBm - (s0_dBm + 9*6), 0), 99); uint8_t overS9dBm = MIN(MAX(rssi_dBm - (s0_dBm + 9*6), 0), 99);