Autogainer update

master
XGudron 2021-05-07 18:03:56 +03:00
rodzic 70db7c1f20
commit 22ccf59662
2 zmienionych plików z 37 dodań i 125 usunięć

Wyświetl plik

@ -21,8 +21,8 @@
#define TX_AGC_MAXGAIN 5.0f // Maximum microphone gain during compression
#define TX_AGC_NOISEGATE 0.00001f // Minimum signal level for amplification (below - noise, cut off)
#define AUTOGAIN_TARGET_AMPLITUDE 20000.0f // maximum amplitude, upon reaching which the autocorrector of the input circuits terminates, and in case of overflow it reduces the gain
#define AUTOGAIN_MAX_AMPLITUDE 30000.0f // maximum amplitude, upon reaching which the autocorrector of the input circuits terminates, and in case of overflow it reduces the gain
#define AUTOGAIN_CORRECTOR_WAITSTEP 5 // waiting for the averaging of the results when the auto-corrector of the input circuits is running
#define AUTOGAIN_MAX_AMPLITUDE 30000.0f // maximum amplitude, upon reaching which the autocorrector of the input circuits terminates, and in case of overflow it reduces the gain
#define AUTOGAIN_CORRECTOR_WAITSTEP 5 // waiting for the averaging of the results when the auto-corrector of the input circuits is running
#define KEY_HOLD_TIME 500 // time of long pressing of the keyboard button for triggering, ms
#define MAX_RF_POWER 7.0f // Maximum power (for meter scale)
#define SHOW_LOGO true // Show logo on boot (from images.h)
@ -46,6 +46,7 @@
#define SPI_EEPROM_PRESCALER SPI_BAUDRATEPRESCALER_8
#define CODEC_BITS_FULL_SCALE 65536 // maximum signal amplitude in the bus // powf (2, FPGA_BUS_BITS)
#define ADC_FULL_SCALE 4095
#define FLOAT_FULL_SCALE_POW 4
#define USB_DEBUG_ENABLED true // allow using USB as a console
#define SWD_DEBUG_ENABLED false // enable SWD as a console
@ -53,6 +54,8 @@
#define ADC_INPUT_IMPEDANCE 200.0f //50ohm -> 1:4 trans
#define ADC_RANGE 1.0f
#define ADC_DRIVER_GAIN_DB 20.0f //on 14mhz
#define AUTOGAINER_TAGET (ADC_FULL_SCALE / 3)
#define AUTOGAINER_HYSTERESIS (ADC_FULL_SCALE / 10)
#define MAX_CALLSIGN_LENGTH 16

Wyświetl plik

@ -281,138 +281,47 @@ void TRX_setMode(uint_fast8_t _mode, VFO *vfo)
void TRX_DoAutoGain(void)
{
#define SKIP_CYCLES_DOWNSTAGE 10 //skip cycles on stage downgrade
static uint8_t skip_cycles = 0;
uint8_t skip_cycles = 0;
if (skip_cycles > 0)
{
skip_cycles--;
return;
}
//Process AutoGain feature
if (TRX.AutoGain && !TRX_on_TX())
{
int32_t max_amplitude = abs(TRX_ADC_MAXAMPLITUDE);
if(abs(TRX_ADC_MINAMPLITUDE) > max_amplitude)
max_amplitude = abs(TRX_ADC_MINAMPLITUDE);
switch (TRX_AutoGain_Stage)
if (!TRX.ATT)
{
case 0: // stage 1 - ATT
TRX.ADC_Driver = false;
TRX.ATT = true;
FPGA_NeedSendParams = true;
LCD_UpdateQuery.TopButtons = true;
autogain_wait_reaction = 0;
if(skip_cycles == 0)
{
sendToDebug_strln("AUTOGAIN BPF + ATT");
TRX_AutoGain_Stage++;
}
else
skip_cycles--;
break;
case 1: // changed the state, process the results
if ((max_amplitude * db2rateV(TRX.ATT_DB)) <= AUTOGAIN_TARGET_AMPLITUDE) // if we can turn off ATT - go to the next stage (+ 12dB)
autogain_wait_reaction++;
else
autogain_wait_reaction = 0;
if (autogain_wait_reaction >= AUTOGAIN_CORRECTOR_WAITSTEP)
{
TRX_AutoGain_Stage++;
autogain_wait_reaction = 0;
}
break;
case 2: // stage 2 - NONE
TRX.ATT = false;
TRX.ADC_Driver = false;
FPGA_NeedSendParams = true;
LCD_UpdateQuery.TopButtons = true;
autogain_wait_reaction = 0;
if(skip_cycles == 0)
{
sendToDebug_strln("AUTOGAIN BPF");
TRX_AutoGain_Stage++;
}
else
skip_cycles--;
break;
case 3: // changed the state, process the results
if (max_amplitude > AUTOGAIN_MAX_AMPLITUDE || TRX_ADC_OTR)
{
TRX_AutoGain_Stage -= 3; // too much gain, go back one step
skip_cycles = SKIP_CYCLES_DOWNSTAGE;
}
if ((max_amplitude * db2rateV(ADC_DRIVER_GAIN_DB) * db2rateV(-TRX.ATT_DB)) <= AUTOGAIN_TARGET_AMPLITUDE) // if we can turn off ATT - go to the next stage (+ 12dB)
autogain_wait_reaction++;
else
{
autogain_wait_reaction = 0;
}
if (autogain_wait_reaction >= AUTOGAIN_CORRECTOR_WAITSTEP)
{
TRX_AutoGain_Stage++;
autogain_wait_reaction = 0;
}
break;
case 5: // stage 4 - BPF + DRIVER + ATT
TRX.ATT = false;
TRX.ADC_Driver = true;
FPGA_NeedSendParams = true;
LCD_UpdateQuery.TopButtons = true;
autogain_wait_reaction = 0;
if(skip_cycles == 0)
{
sendToDebug_strln("AUTOGAIN BPF + DRIVER + ATT");
TRX_AutoGain_Stage++;
}
else
skip_cycles--;
break;
case 6: // changed the state, process the results
if (max_amplitude > AUTOGAIN_MAX_AMPLITUDE || TRX_ADC_OTR)
{
TRX_AutoGain_Stage -= 3; // too much gain, go back one step
skip_cycles = SKIP_CYCLES_DOWNSTAGE;
}
if ((max_amplitude * db2rateV(TRX.ATT_DB)) <= AUTOGAIN_TARGET_AMPLITUDE) // if we can turn off ATT - go to the next stage (+ 12dB)
autogain_wait_reaction++;
else
autogain_wait_reaction = 0;
if (autogain_wait_reaction >= AUTOGAIN_CORRECTOR_WAITSTEP)
{
TRX_AutoGain_Stage++;
autogain_wait_reaction = 0;
}
break;
case 7: // stage 5 - BPF + DRIVER
TRX.ATT = false;
TRX.ADC_Driver = true;
FPGA_NeedSendParams = true;
LCD_UpdateQuery.TopButtons = true;
autogain_wait_reaction = 0;
if(skip_cycles == 0)
{
sendToDebug_strln("AUTOGAIN BPF + DRIVER");
TRX_AutoGain_Stage++;
}
else
skip_cycles--;
break;
case 9: // changed the state, process the results
if (max_amplitude > AUTOGAIN_MAX_AMPLITUDE || TRX_ADC_OTR)
{
TRX_AutoGain_Stage -= 3; // too much gain, go back one step
skip_cycles = SKIP_CYCLES_DOWNSTAGE;
}
break;
default:
TRX_AutoGain_Stage = 0;
break;
}
int8_t band = getBandFromFreq(CurrentVFO()->Freq, true);
if (band > 0)
int32_t max_amplitude = abs(TRX_ADC_MAXAMPLITUDE);
if (abs(TRX_ADC_MINAMPLITUDE) > max_amplitude)
max_amplitude = abs(TRX_ADC_MINAMPLITUDE);
//sendToDebug_int32(max_amplitude,false);
float32_t new_att_val = TRX.ATT_DB;
if (max_amplitude > (AUTOGAINER_TAGET + AUTOGAINER_HYSTERESIS) && new_att_val < 31.5f)
new_att_val += 0.5f;
else if (max_amplitude < (AUTOGAINER_TAGET - AUTOGAINER_HYSTERESIS) && new_att_val > 1.0f)
new_att_val -= 0.5f;
if (new_att_val == 0.0f && max_amplitude < (AUTOGAINER_TAGET - AUTOGAINER_HYSTERESIS) && !TRX.ADC_Driver)
{
TRX.BANDS_SAVED_SETTINGS[band].ATT = TRX.ATT;
TRX.ADC_Driver = true;
LCD_UpdateQuery.TopButtons = true;
skip_cycles = 5;
}
if (new_att_val != TRX.ATT_DB)
{
TRX.ATT_DB = new_att_val;
LCD_UpdateQuery.TopButtons = true;
//save settings
int8_t band = getBandFromFreq(CurrentVFO()->Freq, true);
TRX.BANDS_SAVED_SETTINGS[band].ATT_DB = TRX.ATT_DB;
TRX.BANDS_SAVED_SETTINGS[band].ADC_Driver = TRX.ADC_Driver;
TRX.BANDS_SAVED_SETTINGS[band].AutoGain_Stage = TRX_AutoGain_Stage;
}
}
}