enhancement: adjust delay

This commit is contained in:
TT 2019-09-07 13:13:25 +09:00
parent b7fb2c390b
commit 58bf0fb151
2 changed files with 26 additions and 12 deletions

28
main.c
View file

@ -258,42 +258,48 @@ static void cmd_reset(BaseSequentialStream *chp, int argc, char *argv[])
;
}
#define DELAY_ON_GAIN_CHANGE 3
int set_frequency(int freq)
{
int delay = 0;
bool gain_changed = false;
if (frequency == freq)
return delay;
return 0;
if (freq > 1400000000 && frequency <= 1400000000) {
tlv320aic3204_set_gain(95, 95);
delay += 10;
gain_changed = true;
} else
if (freq > 1200000000 && frequency <= 1200000000) {
tlv320aic3204_set_gain(85, 85);
delay += 10;
gain_changed = true;
} else
if (freq > 900000000 && frequency <= 900000000) {
tlv320aic3204_set_gain(75, 75);
delay += 10;
gain_changed = true;
} else
if (freq > 600000000 && frequency <= 600000000) {
tlv320aic3204_set_gain(50, 50);
delay += 10;
gain_changed = true;
} else
if (freq > FREQ_HARMONICS && frequency <= FREQ_HARMONICS) {
tlv320aic3204_set_gain(40, 40);
delay += 10;
gain_changed = true;
} else
if (freq <= FREQ_HARMONICS && frequency > FREQ_HARMONICS) {
tlv320aic3204_set_gain(0, 0);
delay += 10;
gain_changed = true;
}
int8_t ds = drive_strength;
if (ds == DRIVE_STRENGTH_AUTO) {
ds = freq > FREQ_HARMONICS ? SI5351_CLK_DRIVE_STRENGTH_8MA : SI5351_CLK_DRIVE_STRENGTH_2MA;
}
delay += si5351_set_frequency_with_offset(freq, frequency_offset, ds);
int delay = si5351_set_frequency_with_offset(freq, frequency_offset, ds);
if (gain_changed && delay < DELAY_ON_GAIN_CHANGE) {
delay = DELAY_ON_GAIN_CHANGE;
}
frequency = freq;
return delay;
@ -642,6 +648,8 @@ ensure_edit_config(void)
cal_status = 0;
}
#define DELAY_CHANNEL_CHANGE 1
// main loop for measurement
bool sweep(bool break_on_operation)
{
@ -659,7 +667,7 @@ bool sweep(bool break_on_operation)
(*sample_func)(measured[0][i]);
tlv320aic3204_select_in1(); // CH1:TRANSMISSION
wait_dsp(delay);
wait_dsp(delay + DELAY_CHANNEL_CHANGE);
/* calculate transmission coeficient */
(*sample_func)(measured[1][i]);

View file

@ -295,6 +295,10 @@ si5351_set_frequency(int channel, int freq, uint8_t drive_strength)
int current_band = -1;
#define DELAY_NORMAL 1
#define DELAY_BANDCHANGE 1
#define DELAY_LOWBAND 1
/*
* configure output as follows:
* CLK0: frequency + offset
@ -306,7 +310,7 @@ int
si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength)
{
int band;
int delay = 3;
int delay = DELAY_NORMAL;
uint32_t ofreq = freq + offset;
uint32_t rdiv = SI5351_R_DIV_1;
if (freq > 900000000) {
@ -388,8 +392,10 @@ si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength)
#if 1
si5351_enable_output();
#endif
delay += 10;
delay += DELAY_BANDCHANGE;
}
if (band == 0)
delay += DELAY_LOWBAND;
current_band = band;
return delay;