sync with edy555

This commit is contained in:
qrp73 2019-10-08 04:00:41 +03:00
parent 675b5bb3bc
commit 0218234e70
5 changed files with 29 additions and 17 deletions

19
main.c
View file

@ -34,9 +34,11 @@
#define ENABLED_DUMP
static void apply_error_term(void);
static void apply_error_term_at(int i);
static void apply_edelay_at(int i);
static void cal_interpolate(int s);
void update_frequencies(void);
void set_frequencies(uint32_t start, uint32_t stop, int16_t points);
void apply_edelay_at(int i);
void set_frequencies(uint32_t start, uint32_t stop, int16_t points);
@ -51,7 +53,7 @@ static MUTEX_DECL(mutex);
#define IS_HARMONIC_MODE(f) ((f) > FREQ_HARMONICS)
int32_t frequency_offset = 5000;
int32_t frequency = 10000000;
uint32_t frequency = 10000000;
int8_t drive_strength = DRIVE_STRENGTH_AUTO;
int8_t sweep_enabled = TRUE;
int8_t sweep_once = FALSE;
@ -157,7 +159,7 @@ transform_domain(void)
// and calculate ifft for time domain
float* tmp = (float*)spi_buffer;
uint8_t window_size, offset;
uint8_t window_size = 101, offset = 0;
uint8_t is_lowpass = FALSE;
switch (domain_mode & TD_FUNC) {
case TD_FUNC_BANDPASS:
@ -291,7 +293,7 @@ static int adjust_gain(int newfreq)
return delay;
}
int set_frequency(int freq)
int set_frequency(uint32_t freq)
{
int delay = 0;
if (frequency == freq)
@ -796,6 +798,8 @@ update_frequencies(void)
}
set_frequencies(start, stop, sweep_points);
operation_requested = OP_FREQCHANGE;
update_marker_index();
// set grid layout
@ -832,7 +836,7 @@ freq_mode_centerspan(void)
#define STOP_MAX 1500000000
void
set_sweep_frequency(int type, uint32_t freq)
set_sweep_frequency(int type, int32_t freq)
{
int cal_applied = cal_status & CALSTAT_APPLY;
switch (type) {
@ -1115,6 +1119,7 @@ eterm_calc_et(void)
cal_status |= CALSTAT_ET;
}
#if 0
void apply_error_term(void)
{
int i;
@ -1146,6 +1151,7 @@ void apply_error_term(void)
measured[1][i][1] = s21ai;
}
}
#endif
void apply_error_term_at(int i)
{
@ -1176,7 +1182,7 @@ void apply_error_term_at(int i)
measured[1][i][1] = s21ai;
}
void apply_edelay_at(int i)
static void apply_edelay_at(int i)
{
float w = 2 * M_PI * electrical_delay * frequencies[i] * 1E-12;
float s = sin(w);
@ -2132,5 +2138,6 @@ void HardFault_Handler(void)
void hard_fault_handler_c(uint32_t* sp)
{
(void)sp;
while (true) {}
}

View file

@ -71,7 +71,7 @@ enum {
ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW
};
void set_sweep_frequency(int type, uint32_t frequency);
void set_sweep_frequency(int type, int32_t frequency);
uint32_t get_sweep_frequency(int type);
float my_atof(const char *p);
@ -86,6 +86,9 @@ extern int8_t sweep_enabled;
extern void ui_init(void);
extern void ui_process(void);
enum { OP_NONE = 0, OP_LEVER, OP_TOUCH, OP_FREQCHANGE };
extern uint8_t operation_requested;
/*
* dsp.c
*/
@ -106,7 +109,7 @@ void calculate_gamma(float *gamma);
void fetch_amplitude(float *gamma);
void fetch_amplitude_ref(float *gamma);
int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength);
int si5351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_strength);
/*
@ -195,7 +198,7 @@ typedef struct {
uint16_t trace_color[TRACES_MAX];
int16_t touch_cal[4];
int8_t default_loadcal;
int32_t harmonic_freq_threshold;
uint32_t harmonic_freq_threshold;
int32_t checksum;
} config_t;
@ -237,6 +240,7 @@ void redraw_marker(int marker, int update_info);
void trace_get_info(int t, char *buf, int len);
void plot_into_index(float measured[2][101][2]);
void force_set_markmap(void);
void draw_frequencies(void);
void draw_all(bool flush);
void draw_cal_status(void);
@ -361,6 +365,8 @@ void ui_hide(void);
extern uint8_t operation_requested;
void touch_start_watchdog(void);
void touch_position(int *x, int *y);
void handle_touch_interrupt(void);
#define TOUCH_THRESHOLD 2000

11
plot.c
View file

@ -8,7 +8,6 @@
#define SWAP(x,y) do { int z=x; x = y; y = z; } while(0)
static void cell_draw_marker_info(int m, int n, int w, int h);
void draw_frequencies(void);
void frequency_string(char *buf, size_t len, int32_t freq);
void markmap_all_markers(void);
@ -658,7 +657,7 @@ gamma2imp(char *buf, int len, const float coeff[2], uint32_t frequency)
}
static void
gamma2resistance(char *buf, int len, const float coeff[2], uint32_t frequency)
gamma2resistance(char *buf, int len, const float coeff[2])
{
float z0 = 50;
float d = z0 / ((1-coeff[0])*(1-coeff[0])+coeff[1]*coeff[1]);
@ -667,7 +666,7 @@ gamma2resistance(char *buf, int len, const float coeff[2], uint32_t frequency)
}
static void
gamma2reactance(char *buf, int len, const float coeff[2], uint32_t frequency)
gamma2reactance(char *buf, int len, const float coeff[2])
{
float z0 = 50;
float d = z0 / ((1-coeff[0])*(1-coeff[0])+coeff[1]*coeff[1]);
@ -714,10 +713,10 @@ static void trace_get_value_string(
chsnprintf(buf, len, "%.3fj", coeff[i][1]);
break;
case TRC_R:
gamma2resistance(buf, len, coeff[i], freq[i]);
gamma2resistance(buf, len, coeff[i]);
break;
case TRC_X:
gamma2reactance(buf, len, coeff[i], freq[i]);
gamma2reactance(buf, len, coeff[i]);
break;
//case TRC_ADMIT:
case TRC_POLAR:
@ -793,7 +792,7 @@ clear_markmap(void)
memset(markmap[current_mappage], 0, sizeof markmap[current_mappage]);
}
void inline
inline void
force_set_markmap(void)
{
memset(markmap[current_mappage], 0xff, sizeof markmap[current_mappage]);

View file

@ -330,7 +330,7 @@ int current_band = -1;
* CLK2: fixed 8MHz
*/
#define CLK2_FREQUENCY 8000000L
int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength)
int si5351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_strength)
{
int band;
int delay = 3;

2
ui.c
View file

@ -20,6 +20,7 @@
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include "nanovna.h"
#include <stdlib.h>
#include <string.h>
@ -58,7 +59,6 @@ static uint32_t last_button_down_ticks;
static uint32_t last_button_repeat_ticks;
static int8_t inhibit_until_release = FALSE;
enum { OP_NONE = 0, OP_LEVER, OP_TOUCH };
uint8_t operation_requested = OP_NONE;
int8_t previous_marker = -1;