AM fix modification
This commit is contained in:
2
Makefile
2
Makefile
@@ -33,7 +33,7 @@ ENABLE_BOOT_BEEPS := 0
|
||||
ENABLE_SHOW_CHARGE_LEVEL := 0
|
||||
ENABLE_REVERSE_BAT_SYMBOL := 0
|
||||
ENABLE_NO_CODE_SCAN_TIMEOUT := 1
|
||||
ENABLE_AM_FIX := 0
|
||||
ENABLE_AM_FIX := 1
|
||||
ENABLE_SQUELCH_MORE_SENSITIVE := 1
|
||||
ENABLE_FASTER_CHANNEL_SCAN := 1
|
||||
ENABLE_RSSI_BAR := 1
|
||||
|
25
am_fix.c
25
am_fix.c
@@ -29,6 +29,7 @@
|
||||
#include "frequencies.h"
|
||||
#include "functions.h"
|
||||
#include "misc.h"
|
||||
#include "settings.h"
|
||||
|
||||
#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
|
||||
};
|
||||
|
||||
static const unsigned int original_index = 85;
|
||||
static const unsigned int original_index = ARRAY_SIZE(gain_table) - 7;
|
||||
|
||||
#ifdef ENABLE_AM_FIX_SHOW_DATA
|
||||
// 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
|
||||
const int16_t desired_rssi = (-89 + 160) * 2;
|
||||
|
||||
int8_t currentGainDiff;
|
||||
bool enabled = true;
|
||||
|
||||
void AM_fix_init(void)
|
||||
{ // called at boot-up
|
||||
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)
|
||||
{
|
||||
if(vfo > 1)
|
||||
if(!gSetting_AM_fix || !enabled || vfo > 1 )
|
||||
return;
|
||||
|
||||
if(!force) switch (gCurrentFunction)
|
||||
@@ -254,7 +258,6 @@ void AM_fix_10ms(const unsigned vfo, bool force)
|
||||
#ifdef ENABLE_AM_FIX_SHOW_DATA
|
||||
counter = display_update_rate; // queue up a display update as soon as we switch to RX mode
|
||||
#endif
|
||||
AM_fix_reset(vfo);
|
||||
return;
|
||||
|
||||
// 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
|
||||
|
||||
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;
|
||||
{ // sample the current RSSI level
|
||||
// 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
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -370,5 +379,13 @@ void AM_fix_print_data(const unsigned vfo, char *s) {
|
||||
}
|
||||
#endif
|
||||
|
||||
int8_t AM_fix_get_gain_diff()
|
||||
{
|
||||
return currentGainDiff;
|
||||
}
|
||||
|
||||
void AM_fix_enable(bool on)
|
||||
{
|
||||
enabled = on;
|
||||
}
|
||||
#endif
|
||||
|
5
am_fix.h
5
am_fix.h
@@ -22,11 +22,14 @@
|
||||
|
||||
#ifdef ENABLE_AM_FIX
|
||||
void AM_fix_init(void);
|
||||
void AM_fix_reset(const unsigned vfo);
|
||||
void AM_fix_10ms(const unsigned vfo, bool force);
|
||||
#ifdef ENABLE_AM_FIX_SHOW_DATA
|
||||
void AM_fix_print_data(const unsigned vfo, char *s);
|
||||
#endif
|
||||
|
||||
int8_t AM_fix_get_gain_diff();
|
||||
void AM_fix_enable(bool on);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@@ -1121,7 +1121,7 @@ void APP_TimeSlice10ms(void)
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_AM_FIX
|
||||
if (gRxVfo->Modulation == MODULATION_AM && gSetting_AM_fix)
|
||||
if (gRxVfo->Modulation == MODULATION_AM)
|
||||
AM_fix_10ms(gEeprom.RX_VFO, false);
|
||||
#endif
|
||||
|
||||
|
@@ -113,8 +113,7 @@ static uint16_t GetRegMenuValue(uint8_t st) {
|
||||
|
||||
void LockAGC()
|
||||
{
|
||||
if(!lockAGC)
|
||||
BK4819_SetAGC(0);
|
||||
RADIO_SetupAGC(true, lockAGC);
|
||||
lockAGC = true;
|
||||
}
|
||||
|
||||
@@ -492,13 +491,6 @@ static void ToggleModulation() {
|
||||
}
|
||||
RADIO_SetModulation(settings.modulationType);
|
||||
|
||||
#ifdef ENABLE_AM_FIX
|
||||
if(gSetting_AM_fix && settings.modulationType != MODULATION_AM) {
|
||||
BK4819_InitAGC(false);
|
||||
BK4819_SetAGC(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
RelaunchScan();
|
||||
redrawScreen = true;
|
||||
}
|
||||
@@ -1178,13 +1170,6 @@ void APP_RunSpectrum() {
|
||||
ToggleRX(true), ToggleRX(false); // hack to prevent noise when squelch off
|
||||
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);
|
||||
|
||||
RelaunchScan();
|
||||
|
41
radio.c
41
radio.c
@@ -772,12 +772,7 @@ void RADIO_SetupRegisters(bool switchToForeground)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_AM_FIX
|
||||
if(gSetting_AM_fix) {
|
||||
BK4819_SetAGC(true);
|
||||
BK4819_InitAGC(false);
|
||||
}
|
||||
#endif
|
||||
RADIO_SetupAGC(false, false);
|
||||
|
||||
// enable/disable BK4819 selected interrupts
|
||||
BK4819_WriteRegister(BK4819_REG_3F, InterruptMask);
|
||||
@@ -926,12 +921,36 @@ void RADIO_SetModulation(ModulationMode_t modulation)
|
||||
BK4819_SetRegValue(afDacGainRegSpec, 0xF);
|
||||
BK4819_WriteRegister(BK4819_REG_3D, modulation == MODULATION_USB ? 0 : 0x2AAB);
|
||||
BK4819_SetRegValue(afcDisableRegSpec, modulation != MODULATION_FM);
|
||||
#ifdef ENABLE_AM_FIX
|
||||
if(modulation == MODULATION_AM && gSetting_AM_fix) {
|
||||
BK4819_SetAGC(0);
|
||||
|
||||
RADIO_SetupAGC(modulation == MODULATION_AM, false);
|
||||
}
|
||||
|
||||
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
|
||||
BK4819_InitAGC(modulation == MODULATION_AM);
|
||||
{
|
||||
BK4819_SetAGC(!disable);
|
||||
BK4819_InitAGC(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RADIO_SetVfoState(VfoState_t State)
|
||||
@@ -1149,4 +1168,4 @@ void RADIO_SendEndOfTransmission(void)
|
||||
}
|
||||
|
||||
BK4819_ExitDTMF_TX(true);
|
||||
}
|
||||
}
|
1
radio.h
1
radio.h
@@ -159,6 +159,7 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0);
|
||||
void RADIO_ConfigureNOAA(void);
|
||||
#endif
|
||||
void RADIO_SetTxParameters(void);
|
||||
void RADIO_SetupAGC(bool listeningAM, bool disable);
|
||||
void RADIO_SetModulation(ModulationMode_t modulation);
|
||||
void RADIO_SetVfoState(VfoState_t State);
|
||||
void RADIO_PrepareTX(void);
|
||||
|
@@ -189,7 +189,13 @@ void DisplayRSSIBar(const bool now)
|
||||
|
||||
|
||||
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
|
||||
uint8_t overS9dBm = MIN(MAX(rssi_dBm - (s0_dBm + 9*6), 0), 99);
|
||||
|
Reference in New Issue
Block a user