Added harmonic mixer

tinySA
erikkaashoek 6 years ago
parent 2d430a4f58
commit 8bffd8ba36

@ -37,10 +37,10 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
extern uint32_t minFreq; extern float minFreq;
extern uint32_t maxFreq; extern float maxFreq;
uint32_t frequencyStart; float frequencyStart;
uint32_t frequencyStop; float frequencyStop;
int32_t frequencyExtra; int32_t frequencyExtra;
#define START_MIN minFreq #define START_MIN minFreq
#define STOP_MAX maxFreq #define STOP_MAX maxFreq

@ -30,6 +30,7 @@
#define __MEASURE__ #define __MEASURE__
#define __SELFTEST__ #define __SELFTEST__
#define __CALIBRATE__ #define __CALIBRATE__
#define __ULTRA__
/* /*
* main.c * main.c
@ -124,12 +125,12 @@ int shell_printf(const char *fmt, ...);
void toggle_sweep(void); void toggle_sweep(void);
void load_default_properties(void); void load_default_properties(void);
extern float perform(bool b, int i, int32_t f, int e); extern float perform(bool b, int i, uint32_t f, int e);
enum { enum {
AV_OFF, AV_MIN, AV_MAX_HOLD, AV_MAX_DECAY, AV_4, AV_16 AV_OFF, AV_MIN, AV_MAX_HOLD, AV_MAX_DECAY, AV_4, AV_16
}; };
enum { enum {
M_LOW, M_HIGH, M_GENLOW, M_GENHIGH, M_LOW, M_HIGH, M_GENLOW, M_GENHIGH, M_ULTRA
}; };
enum { enum {
@ -137,7 +138,11 @@ enum {
}; };
#define MODE_OUTPUT(x) ((x) == M_GENLOW || (x) == M_GENHIGH ) #define MODE_OUTPUT(x) ((x) == M_GENLOW || (x) == M_GENHIGH )
#ifdef __ULTRA__
#define MODE_INPUT(x) ((x) == M_LOW || (x) == M_HIGH || (x) == M_ULTRA )
#else
#define MODE_INPUT(x) ((x) == M_LOW || (x) == M_HIGH ) #define MODE_INPUT(x) ((x) == M_LOW || (x) == M_HIGH )
#endif
#define MODE_HIGH(x) ((x) == M_HIGH || (x) == M_GENHIGH ) #define MODE_HIGH(x) ((x) == M_HIGH || (x) == M_GENHIGH )
#define MODE_LOW(x) ((x) == M_LOW || (x) == M_GENLOW ) #define MODE_LOW(x) ((x) == M_LOW || (x) == M_GENLOW )
#define MODE_SELECT(x) (MODE_HIGH(x) ? 1 : 0) #define MODE_SELECT(x) (MODE_HIGH(x) ? 1 : 0)
@ -575,7 +580,7 @@ typedef struct uistat {
int8_t digit; /* 0~5 */ int8_t digit; /* 0~5 */
int8_t digit_mode; int8_t digit_mode;
int8_t current_trace; /* 0..3 */ int8_t current_trace; /* 0..3 */
int32_t value; // for editing at numeric input area float value; // for editing at numeric input area
// uint32_t previous_value; // uint32_t previous_value;
uint8_t lever_mode; uint8_t lever_mode;
uint8_t marker_delta; uint8_t marker_delta;

@ -33,9 +33,9 @@ int setting_measurement;
int vbwSteps = 1; int vbwSteps = 1;
//int setting_spur = 0; int setting_spur = 0;
uint32_t minFreq = 0; float minFreq = 0;
uint32_t maxFreq = 520000000; float maxFreq = 520000000;
int setting_refer = -1; // Off by default int setting_refer = -1; // Off by default
const int reffer_freq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000}; const int reffer_freq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000};
@ -69,15 +69,24 @@ void reset_settings(int m)
trace[TRACE_TEMP].enabled = false; trace[TRACE_TEMP].enabled = false;
setting_measurement = M_OFF; setting_measurement = M_OFF;
// setting_spur = 0; setting_spur = 0;
switch(m) { switch(m) {
case M_LOW: case M_LOW:
minFreq = 0; minFreq = 0;
maxFreq = 520000000; maxFreq = 520000000;
set_sweep_frequency(ST_START, (int32_t) 0); set_sweep_frequency(ST_START, (uint32_t) 0);
set_sweep_frequency(ST_STOP, (int32_t) 350000000); set_sweep_frequency(ST_STOP, (uint32_t) 350000000);
setting_attenuate = 30; setting_attenuate = 30;
break; break;
#ifdef __ULTRA__
case M_ULTRA:
minFreq = 770000000;
maxFreq = 4360000000;
set_sweep_frequency(ST_START, (uint32_t) 960000000);
set_sweep_frequency(ST_STOP, (uint32_t) 2100000000);
setting_attenuate = 30;
break;
#endif
case M_GENLOW: case M_GENLOW:
setting_drive=8; setting_drive=8;
minFreq = 0; minFreq = 0;
@ -290,6 +299,10 @@ void SetPowerLevel(int o)
config.high_level_offset = new_offset; config.high_level_offset = new_offset;
else if (setting_mode == M_LOW) else if (setting_mode == M_LOW)
config.low_level_offset = new_offset; config.low_level_offset = new_offset;
#ifdef __ULTRA__
else if (setting_mode == M_ULTRA)
config.low_level_offset = new_offset;
#endif
} }
else { else {
config.low_level_offset = 100; config.low_level_offset = 100;
@ -338,13 +351,13 @@ int GetActualRBW(void)
{ {
return((int) actual_rbw); return((int) actual_rbw);
} }
#if 0
void SetSpur(int v) void SetSpur(int v)
{ {
// setting_spur = v; setting_spur = v;
dirty = true; dirty = true;
} }
#endif
void SetStepDelay(int d) void SetStepDelay(int d)
{ {
@ -422,6 +435,10 @@ void SetScale(int s) {
//} //}
void SetMode(int m) void SetMode(int m)
{ {
#ifdef __ULTRA__
if (m == 6)
m = M_ULTRA;
#endif
if (setting_mode == m) if (setting_mode == m)
return; return;
reset_settings(m); reset_settings(m);
@ -511,6 +528,9 @@ void SetRX(int m)
{ {
switch(m) { switch(m) {
case M_LOW: // Mixed into 0 case M_LOW: // Mixed into 0
#ifdef __ULTRA__
case M_ULTRA:
#endif
SI4432_Sel = 0; SI4432_Sel = 0;
SI4432_Receive(); SI4432_Receive();
if (setting_step_atten) { if (setting_step_atten) {
@ -821,14 +841,14 @@ static int modulation_counter = 0;
char age[POINTS_COUNT]; char age[POINTS_COUNT];
float perform(bool break_on_operation, int i, int32_t f, int tracking) float perform(bool break_on_operation, int i, uint32_t f, int tracking)
{ {
// long local_IF = (MODE_LOW(setting_mode)?frequency_IF + (int)(actual_rbw < 300.0?setting_spur * 1000 * actual_rbw :0):0);
long local_IF; long local_IF;
if (MODE_HIGH(setting_mode)) if (MODE_HIGH(setting_mode))
local_IF = 0; local_IF = 0;
else else
local_IF = frequency_IF; local_IF = frequency_IF + (int)(actual_rbw < 300.0?setting_spur * 1000 * actual_rbw:0);
// local_IF = frequency_IF;
if (i == 0 && dirty) { if (i == 0 && dirty) {
apply_settings(); apply_settings();
@ -865,7 +885,7 @@ float perform(bool break_on_operation, int i, int32_t f, int tracking)
float RSSI = -150.0; float RSSI = -150.0;
int t = 0; int t = 0;
do { do {
int lf = (uint32_t)(f + (int)((t * 500 - vbwSteps * 250) * actual_rbw)); uint32_t lf = (uint32_t)(f + (int)((t * 500 - vbwSteps * 250) * actual_rbw));
if (lf < 0) lf = 0; if (lf < 0) lf = 0;
if (setting_mode == M_LOW && tracking) { if (setting_mode == M_LOW && tracking) {
setFreq (0, frequency_IF + lf - reffer_freq[setting_refer]); // Offset so fundamental of reffer is visible setFreq (0, frequency_IF + lf - reffer_freq[setting_refer]); // Offset so fundamental of reffer is visible
@ -874,11 +894,15 @@ float perform(bool break_on_operation, int i, int32_t f, int tracking)
if (setting_mode == M_LOW && !in_selftest && avoid_spur(f)) { if (setting_mode == M_LOW && !in_selftest && avoid_spur(f)) {
local_IF = spur_alternate_IF; local_IF = spur_alternate_IF;
} else { } else {
local_IF = frequency_IF ; // local_IF = frequency_IF ;
} }
if (setting_mode == M_GENLOW && setting_modulation == MO_EXTERNAL) if (setting_mode == M_GENLOW && setting_modulation == MO_EXTERNAL)
local_IF += lf; local_IF += lf;
setFreq (0, local_IF); setFreq (0, local_IF);
#ifdef __ULTRA__
} else if (setting_mode == M_ULTRA) {
// local_IF = frequency_IF;
#endif
} else } else
local_IF= 0; local_IF= 0;
#if 0 #if 0
@ -887,13 +911,32 @@ float perform(bool break_on_operation, int i, int32_t f, int tracking)
break; break;
} }
#endif #endif
setFreq (1, local_IF + lf); #ifdef __ULTRA__
if (setting_mode == M_ULTRA) {
// if (lf > 3406000000 )
// setFreq (1, local_IF/5 + lf/5);
// else
if (lf > 2446000000 )
setFreq (1, local_IF/5 + lf/5);
else
// if (lf > 1486000000)
setFreq (1, local_IF/3 + lf/3);
// else
// setFreq (1, local_IF/2 + lf/2);
} else
#endif
setFreq (1, local_IF + lf);
if (MODE_OUTPUT(setting_mode)) // No substepping in output mode if (MODE_OUTPUT(setting_mode)) // No substepping in output mode
return(0); return(0);
float signal_path_loss; float signal_path_loss;
if (setting_mode == M_LOW) #ifdef __ULTRA__
signal_path_loss = -9.5; // Loss in dB, -9.5 for v0.1, -12.5 for v0.2 if (setting_mode == M_ULTRA)
signal_path_loss = -15; // Loss in dB, -9.5 for v0.1, -12.5 for v0.2
else else
#endif
if (setting_mode == M_LOW)
signal_path_loss = -9.5; // Loss in dB, -9.5 for v0.1, -12.5 for v0.2
else
signal_path_loss = 7; // Loss in dB (+ is gain) signal_path_loss = 7; // Loss in dB (+ is gain)
float subRSSI = SI4432_RSSI(lf, MODE_SELECT(setting_mode))+settingLevelOffset()+ setting_attenuate - signal_path_loss; float subRSSI = SI4432_RSSI(lf, MODE_SELECT(setting_mode))+settingLevelOffset()+ setting_attenuate - signal_path_loss;
if (RSSI < subRSSI) if (RSSI < subRSSI)
@ -918,7 +961,7 @@ static bool sweep(bool break_on_operation)
temppeakLevel = -150; temppeakLevel = -150;
float temp_min_level = 100; float temp_min_level = 100;
// spur_old_stepdelay = 0; // spur_old_stepdelay = 0;
//again: again:
for (int i = 0; i < sweep_points; i++) { for (int i = 0; i < sweep_points; i++) {
RSSI = perform(break_on_operation, i, frequencies[i], setting_tracking); RSSI = perform(break_on_operation, i, frequencies[i], setting_tracking);
@ -930,12 +973,12 @@ static bool sweep(bool break_on_operation)
} }
if (MODE_INPUT(setting_mode)) { if (MODE_INPUT(setting_mode)) {
// if (setting_spur == 1) { // First pass if (setting_spur == 1) { // First pass
// temp_t[i] = RSSI; temp_t[i] = RSSI;
// continue; // Skip all other processing continue; // Skip all other processing
// } }
// if (setting_spur == -1) // Second pass if (setting_spur == -1) // Second pass
// RSSI = ( RSSI < temp_t[i] ? RSSI : temp_t[i]); // Minimum of two passes RSSI = ( RSSI < temp_t[i] ? RSSI : temp_t[i]); // Minimum of two passes
temp_t[i] = RSSI; temp_t[i] = RSSI;
if (setting_subtract_stored) { if (setting_subtract_stored) {
RSSI = RSSI - stored_t[i] ; RSSI = RSSI - stored_t[i] ;
@ -1023,11 +1066,11 @@ static bool sweep(bool break_on_operation)
temp_min_level = actual_t[i]; temp_min_level = actual_t[i];
} }
// if (setting_spur == 1) { if (setting_spur == 1) {
// setting_spur = -1; setting_spur = -1;
// goto again; goto again;
// } else if (setting_spur == -1) } else if (setting_spur == -1)
// setting_spur = 1; setting_spur = 1;
if (scandirty) { if (scandirty) {
scandirty = false; scandirty = false;
@ -1335,7 +1378,7 @@ void draw_cal_status(void)
buf[5]=0; buf[5]=0;
ili9341_drawstring(buf, x, y); ili9341_drawstring(buf, x, y);
} }
#if 0 #if 1
if (setting_spur) { if (setting_spur) {
ili9341_set_foreground(BRIGHT_COLOR_BLUE); ili9341_set_foreground(BRIGHT_COLOR_BLUE);
y += YSTEP*2; y += YSTEP*2;
@ -1383,7 +1426,7 @@ void draw_cal_status(void)
ili9341_drawstring("Scan:", x, y); ili9341_drawstring("Scan:", x, y);
y += YSTEP; y += YSTEP;
int32_t t = (int)((2* vbwSteps * sweep_points * ( actualStepDelay / 100) )) /10 /* * (setting_spur ? 2 : 1) */; // in mS int32_t t = (int)((2* vbwSteps * sweep_points * ( actualStepDelay / 100) )) /10 * (setting_spur ? 2 : 1); // in mS
if (t>1000) if (t>1000)
plot_printf(buf, BLEN, "%dS",(t+500)/1000); plot_printf(buf, BLEN, "%dS",(t+500)/1000);
else else

@ -2051,7 +2051,7 @@ keypad_click(int key)
/* numeric input done */ /* numeric input done */
double value = my_atof(kp_buf) * scale; double value = my_atof(kp_buf) * scale;
#if 1 #if 1
uistat.value = (int)value; uistat.value = value;
set_numeric_value(); set_numeric_value();
#else #else
switch (keypad_mode) { switch (keypad_mode) {

@ -23,7 +23,7 @@ void SetDrive(int d);
void SetIF(int f); void SetIF(int f);
void SetStepDelay(int t); void SetStepDelay(int t);
extern int setting_rbw; extern int setting_rbw;
void SetSpur(int); extern int setting_spur;
int GetSpur(void); int GetSpur(void);
void SetAverage(int); void SetAverage(int);
int GetAverage(void); int GetAverage(void);
@ -473,6 +473,7 @@ extern const menuitem_t menu_highoutputmode[];
extern const menuitem_t menu_modulation[]; extern const menuitem_t menu_modulation[];
extern const menuitem_t menu_top[]; extern const menuitem_t menu_top[];
extern const menuitem_t menu_tophigh[]; extern const menuitem_t menu_tophigh[];
extern const menuitem_t menu_topultra[];
static void menu_mode_cb(int item, uint8_t data) static void menu_mode_cb(int item, uint8_t data)
{ {
@ -492,6 +493,9 @@ static void menu_mode_cb(int item, uint8_t data)
case 4: case 4:
menu_push_submenu(menu_highoutputmode); menu_push_submenu(menu_highoutputmode);
break; break;
case 7:
menu_push_submenu(menu_topultra);
break;
} }
// draw_cal_status(); // draw_cal_status();
} }
@ -614,13 +618,13 @@ static void menu_drive_cb(int item, uint8_t data)
#if 0 #if 1
static void menu_spur_cb(int item, uint8_t data) static void menu_spur_cb(int item, uint8_t data)
{ {
(void)data; (void)data;
(void)item; (void)item;
if (GetSpur()) if (setting_spur)
SetSpur(0); SetSpur(0);
else else
SetSpur(1); // must be 0 or 1 !!!! SetSpur(1); // must be 0 or 1 !!!!
@ -1250,6 +1254,7 @@ static const menuitem_t menu_stimulus[] = {
{ MT_KEYPAD, KM_SPAN, "SPAN", NULL}, { MT_KEYPAD, KM_SPAN, "SPAN", NULL},
{ MT_KEYPAD, KM_CW, "\2ZERO\0SPAN", NULL}, { MT_KEYPAD, KM_CW, "\2ZERO\0SPAN", NULL},
{ MT_SUBMENU,0, "RBW", menu_rbw}, { MT_SUBMENU,0, "RBW", menu_rbw},
{ MT_CALLBACK,0, "\2SPUR\0REMOVAL", menu_spur_cb},
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
}; };
@ -1264,10 +1269,29 @@ static const menuitem_t menu_mode[] = {
{ MT_FORM | MT_CALLBACK | MT_ICON, I_HIGH_OUTPUT+I_GEN, "HIGH OUTPUT", menu_mode_cb}, { MT_FORM | MT_CALLBACK | MT_ICON, I_HIGH_OUTPUT+I_GEN, "HIGH OUTPUT", menu_mode_cb},
{ MT_FORM | MT_SUBMENU | MT_ICON, I_CONNECT+I_GEN, "CAL OUTPUT: %s", menu_reffer}, { MT_FORM | MT_SUBMENU | MT_ICON, I_CONNECT+I_GEN, "CAL OUTPUT: %s", menu_reffer},
{ MT_FORM | MT_SUBMENU | MT_ICON, I_EMPTY+I_CONFIG, "CONFIG", menu_config}, { MT_FORM | MT_SUBMENU | MT_ICON, I_EMPTY+I_CONFIG, "CONFIG", menu_config},
// { MT_CANCEL, 0, S_LARROW" BACK", NULL }, #ifdef __ULTRA__
{ MT_FORM | MT_CALLBACK | MT_ICON, I_LOW_INPUT+I_SA, "ULTRA HIGH INPUT",menu_mode_cb},
#endif
// { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel
}; };
#if 1 #if 1
#ifdef __ULTRA__
const menuitem_t menu_topultra[] = {
{ MT_CALLBACK, 0, "RESET", menu_autosettings_cb},
{ MT_SUBMENU, 0, "FREQ", menu_stimulus},
{ MT_SUBMENU, 0, "LEVEL", menu_level},
{ MT_SUBMENU, 0, "DISPLAY", menu_display},
{ MT_SUBMENU, 0, "MARKER", menu_marker},
{ MT_SUBMENU, 0, "MEASURE", menu_measure},
{ MT_SUBMENU, 0, "SETTINGS", menu_settings},
{ MT_CANCEL, 0, S_LARROW" MODE",NULL},
{ MT_NONE, 0, NULL, NULL } // sentinel,
// MENUITEM_CLOSE,
};
#endif
const menuitem_t menu_top[] = { const menuitem_t menu_top[] = {
{ MT_CALLBACK, 0, "RESET", menu_autosettings_cb}, { MT_CALLBACK, 0, "RESET", menu_autosettings_cb},
{ MT_SUBMENU, 0, "FREQ", menu_stimulus}, { MT_SUBMENU, 0, "FREQ", menu_stimulus},
@ -1367,6 +1391,9 @@ static void menu_item_modify_attribute(
if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_ENABLE)) { if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_ENABLE)) {
mark = true; mark = true;
} }
if (item == 6 && setting_spur) {
mark = true;
}
} else if (menu == menu_average) { } else if (menu == menu_average) {
if (item == GetAverage()){ if (item == GetAverage()){
mark = true; mark = true;

Loading…
Cancel
Save

Powered by TurnKey Linux.