mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
sync with edy555
This commit is contained in:
parent
cbe4fc7265
commit
210dc2fcf2
89
main.c
89
main.c
|
|
@ -47,7 +47,8 @@ bool sweep(bool break_on_operation);
|
||||||
static MUTEX_DECL(mutex);
|
static MUTEX_DECL(mutex);
|
||||||
|
|
||||||
#define DRIVE_STRENGTH_AUTO (-1)
|
#define DRIVE_STRENGTH_AUTO (-1)
|
||||||
#define FREQ_HARMONICS 300000000
|
#define FREQ_HARMONICS (config.harmonic_freq_threshold)
|
||||||
|
#define IS_HARMONIC_MODE(f) ((f) > FREQ_HARMONICS)
|
||||||
|
|
||||||
int32_t frequency_offset = 5000;
|
int32_t frequency_offset = 5000;
|
||||||
int32_t frequency = 10000000;
|
int32_t frequency = 10000000;
|
||||||
|
|
@ -268,36 +269,35 @@ static void cmd_reset(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int8_t gain_table[] = {
|
||||||
|
0, // 0 ~ 300MHz
|
||||||
|
40, // 300 ~ 600MHz
|
||||||
|
50, // 600 ~ 900MHz
|
||||||
|
75, // 900 ~ 1200MHz
|
||||||
|
85, // 1200 ~ 1400MHz
|
||||||
|
95 // 1400MHz ~
|
||||||
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
adjust_gain(int newfreq)
|
||||||
|
{
|
||||||
|
int delay = 0;
|
||||||
|
int new_order = newfreq / FREQ_HARMONICS;
|
||||||
|
int old_order = frequency / FREQ_HARMONICS;
|
||||||
|
if (new_order != old_order) {
|
||||||
|
tlv320aic3204_set_gain(gain_table[new_order], gain_table[new_order]);
|
||||||
|
delay += 10;
|
||||||
|
}
|
||||||
|
return delay;
|
||||||
|
}
|
||||||
|
|
||||||
int set_frequency(int freq)
|
int set_frequency(int freq)
|
||||||
{
|
{
|
||||||
int delay = 0;
|
int delay = 0;
|
||||||
if (frequency == freq)
|
if (frequency == freq)
|
||||||
return delay;
|
return delay;
|
||||||
|
|
||||||
if (freq > 1400000000 && frequency <= 1400000000) {
|
delay += adjust_gain(freq);
|
||||||
tlv320aic3204_set_gain(95, 95);
|
|
||||||
delay += 10;
|
|
||||||
} else
|
|
||||||
if (freq > 1200000000 && frequency <= 1200000000) {
|
|
||||||
tlv320aic3204_set_gain(85, 85);
|
|
||||||
delay += 10;
|
|
||||||
} else
|
|
||||||
if (freq > 900000000 && frequency <= 900000000) {
|
|
||||||
tlv320aic3204_set_gain(75, 75);
|
|
||||||
delay += 10;
|
|
||||||
} else
|
|
||||||
if (freq > 600000000 && frequency <= 600000000) {
|
|
||||||
tlv320aic3204_set_gain(50, 50);
|
|
||||||
delay += 10;
|
|
||||||
} else
|
|
||||||
if (freq > FREQ_HARMONICS && frequency <= FREQ_HARMONICS) {
|
|
||||||
tlv320aic3204_set_gain(40, 40);
|
|
||||||
delay += 10;
|
|
||||||
} else
|
|
||||||
if (freq <= FREQ_HARMONICS && frequency > FREQ_HARMONICS) {
|
|
||||||
tlv320aic3204_set_gain(0, 0);
|
|
||||||
delay += 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t ds = drive_strength;
|
int8_t ds = drive_strength;
|
||||||
if (ds == DRIVE_STRENGTH_AUTO) {
|
if (ds == DRIVE_STRENGTH_AUTO) {
|
||||||
|
|
@ -366,6 +366,18 @@ static void cmd_dac(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
dacPutChannelX(&DACD2, 0, value);
|
dacPutChannelX(&DACD2, 0, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cmd_threshold(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
if (argc != 1) {
|
||||||
|
chprintf(chp, "usage: threshold {frequency in harmonic mode}\r\n");
|
||||||
|
chprintf(chp, "current: %d\r\n", config.harmonic_freq_threshold);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
value = atoi(argv[0]);
|
||||||
|
config.harmonic_freq_threshold = value;
|
||||||
|
}
|
||||||
|
|
||||||
static void cmd_saveconfig(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_saveconfig(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
(void)argc;
|
(void)argc;
|
||||||
|
|
@ -607,10 +619,10 @@ config_t config = {
|
||||||
.grid_color = 0x1084,
|
.grid_color = 0x1084,
|
||||||
.menu_normal_color = 0xffff,
|
.menu_normal_color = 0xffff,
|
||||||
.menu_active_color = 0x7777,
|
.menu_active_color = 0x7777,
|
||||||
.trace_color = /*[4] */ { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) },
|
.trace_color = { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) },
|
||||||
//.touch_cal = /*[4] */ { 620, 600, 160, 190 },
|
.touch_cal = { 693, 605, 124, 171 }, //{ 620, 600, 160, 190 },
|
||||||
.touch_cal = /*[4] */ { 693, 605, 124, 171 },
|
|
||||||
.default_loadcal = 0,
|
.default_loadcal = 0,
|
||||||
|
.harmonic_freq_threshold = 300000000,
|
||||||
.checksum = 0
|
.checksum = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -820,16 +832,15 @@ freq_mode_centerspan(void)
|
||||||
#define STOP_MAX 1500000000
|
#define STOP_MAX 1500000000
|
||||||
|
|
||||||
void
|
void
|
||||||
set_sweep_frequency(int type, float frequency)
|
set_sweep_frequency(int type, uint32_t freq)
|
||||||
{
|
{
|
||||||
int32_t freq = frequency;
|
|
||||||
int cal_applied = cal_status & CALSTAT_APPLY;
|
int cal_applied = cal_status & CALSTAT_APPLY;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ST_START:
|
case ST_START:
|
||||||
freq_mode_startstop();
|
freq_mode_startstop();
|
||||||
if (frequency < START_MIN)
|
if (freq < START_MIN)
|
||||||
freq = START_MIN;
|
freq = START_MIN;
|
||||||
if (frequency > STOP_MAX)
|
if (freq > STOP_MAX)
|
||||||
freq = STOP_MAX;
|
freq = STOP_MAX;
|
||||||
if (frequency0 != freq) {
|
if (frequency0 != freq) {
|
||||||
ensure_edit_config();
|
ensure_edit_config();
|
||||||
|
|
@ -842,9 +853,9 @@ set_sweep_frequency(int type, float frequency)
|
||||||
break;
|
break;
|
||||||
case ST_STOP:
|
case ST_STOP:
|
||||||
freq_mode_startstop();
|
freq_mode_startstop();
|
||||||
if (frequency > STOP_MAX)
|
if (freq > STOP_MAX)
|
||||||
freq = STOP_MAX;
|
freq = STOP_MAX;
|
||||||
if (frequency < START_MIN)
|
if (freq < START_MIN)
|
||||||
freq = START_MIN;
|
freq = START_MIN;
|
||||||
if (frequency1 != freq) {
|
if (frequency1 != freq) {
|
||||||
ensure_edit_config();
|
ensure_edit_config();
|
||||||
|
|
@ -896,7 +907,7 @@ set_sweep_frequency(int type, float frequency)
|
||||||
freq_mode_centerspan();
|
freq_mode_centerspan();
|
||||||
if (frequency0 != freq || frequency1 != 0) {
|
if (frequency0 != freq || frequency1 != 0) {
|
||||||
ensure_edit_config();
|
ensure_edit_config();
|
||||||
frequency0 = frequency;
|
frequency0 = freq;
|
||||||
frequency1 = 0;
|
frequency1 = 0;
|
||||||
update_frequencies();
|
update_frequencies();
|
||||||
}
|
}
|
||||||
|
|
@ -1285,6 +1296,13 @@ cal_interpolate(int s)
|
||||||
// found f between freqs at j and j+1
|
// found f between freqs at j and j+1
|
||||||
float k1 = (float)(f - src->_frequencies[j])
|
float k1 = (float)(f - src->_frequencies[j])
|
||||||
/ (src->_frequencies[j+1] - src->_frequencies[j]);
|
/ (src->_frequencies[j+1] - src->_frequencies[j]);
|
||||||
|
|
||||||
|
// avoid glitch between freqs in different harmonics mode
|
||||||
|
if (IS_HARMONIC_MODE(src->_frequencies[j]) != IS_HARMONIC_MODE(src->_frequencies[j+1])) {
|
||||||
|
// assume f[j] < f[j+1]
|
||||||
|
k1 = IS_HARMONIC_MODE(f) ? 1.0 : 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
float k0 = 1.0 - k1;
|
float k0 = 1.0 - k1;
|
||||||
for (eterm = 0; eterm < 5; eterm++) {
|
for (eterm = 0; eterm < 5; eterm++) {
|
||||||
cal_data[eterm][i][0] = src->_cal_data[eterm][j][0] * k0 + src->_cal_data[eterm][j+1][0] * k1;
|
cal_data[eterm][i][0] = src->_cal_data[eterm][j][0] * k0 + src->_cal_data[eterm][j+1][0] * k1;
|
||||||
|
|
@ -1987,6 +2005,7 @@ static const ShellCommand commands[] =
|
||||||
{ "capture", cmd_capture },
|
{ "capture", cmd_capture },
|
||||||
{ "vbat", cmd_vbat },
|
{ "vbat", cmd_vbat },
|
||||||
{ "transform", cmd_transform },
|
{ "transform", cmd_transform },
|
||||||
|
{ "threshold", cmd_threshold },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ enum {
|
||||||
ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW
|
ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_sweep_frequency(int type, float frequency);
|
void set_sweep_frequency(int type, uint32_t frequency);
|
||||||
uint32_t get_sweep_frequency(int type);
|
uint32_t get_sweep_frequency(int type);
|
||||||
|
|
||||||
float my_atof(const char *p);
|
float my_atof(const char *p);
|
||||||
|
|
@ -195,6 +195,7 @@ typedef struct {
|
||||||
uint16_t trace_color[TRACES_MAX];
|
uint16_t trace_color[TRACES_MAX];
|
||||||
int16_t touch_cal[4];
|
int16_t touch_cal[4];
|
||||||
int8_t default_loadcal;
|
int8_t default_loadcal;
|
||||||
|
int32_t harmonic_freq_threshold;
|
||||||
int32_t checksum;
|
int32_t checksum;
|
||||||
} config_t;
|
} config_t;
|
||||||
|
|
||||||
|
|
|
||||||
5
si5351.c
5
si5351.c
|
|
@ -18,6 +18,7 @@
|
||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
|
#include "nanovna.h"
|
||||||
#include "si5351.h"
|
#include "si5351.h"
|
||||||
|
|
||||||
#define SI5351_I2C_ADDR (0x60<<1)
|
#define SI5351_I2C_ADDR (0x60<<1)
|
||||||
|
|
@ -335,10 +336,10 @@ int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strengt
|
||||||
int delay = 3;
|
int delay = 3;
|
||||||
uint32_t ofreq = freq + offset;
|
uint32_t ofreq = freq + offset;
|
||||||
uint32_t rdiv = SI5351_R_DIV_1;
|
uint32_t rdiv = SI5351_R_DIV_1;
|
||||||
if (freq > 900000000) {
|
if (freq >= config.harmonic_freq_threshold * 3) {
|
||||||
freq /= 5;
|
freq /= 5;
|
||||||
ofreq /= 7;
|
ofreq /= 7;
|
||||||
} else if (freq > 300000000) {
|
} else if (freq >= config.harmonic_freq_threshold) {
|
||||||
freq /= 3;
|
freq /= 3;
|
||||||
ofreq /= 5;
|
ofreq /= 5;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue