Updated sweep time logic and corrected first sweep after update

pull/4/head
erikkaashoek 6 years ago
parent 5acc180a92
commit e680d7e8aa

@ -638,7 +638,7 @@ enum { S_OFF=0, S_ON=1, S_AUTO_OFF=2, S_AUTO_ON=3 };
enum { SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL }; enum { SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL };
#ifdef __FAST_SWEEP__ #ifdef __FAST_SWEEP__
#define MINIMUM_SWEEP_TIME 2000U // Minimum sweep time on zero span in uS #define MINIMUM_SWEEP_TIME 1800U // Minimum sweep time on zero span in uS
#else #else
#define MINIMUM_SWEEP_TIME 15000U // Minimum sweep time on zero span in uS #define MINIMUM_SWEEP_TIME 15000U // Minimum sweep time on zero span in uS
#endif #endif
@ -646,8 +646,8 @@ enum { SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL };
#define ONE_SECOND_TIME 1000000U // One second uS #define ONE_SECOND_TIME 1000000U // One second uS
#define ONE_MS_TIME 1000U // One ms uS #define ONE_MS_TIME 1000U // One ms uS
#define REPEAT_TIME 110 // Time per extra repeat in uS #define REPEAT_TIME 111 // Time per extra repeat in uS
#define MEASURE_TIME 127 // Time per vbwstep without step delay in uS #define MEASURE_TIME 127 // Time per single point measurement with vbwstep =1 without step delay in uS
extern uint32_t frequencies[POINTS_COUNT]; extern uint32_t frequencies[POINTS_COUNT];
extern const float unit_scale_value[]; extern const float unit_scale_value[];

@ -166,19 +166,20 @@ void reset_settings(int m)
//static uint32_t minimum_sweep_time = 0; //static uint32_t minimum_sweep_time = 0;
uint32_t calc_min_sweep_time_us(void) // Calculate minimum sweep time in uS needed just because of the delays for the RSSI to become stable uint32_t calc_min_sweep_time_us(void) // Estimate minimum sweep time in uS, needed to calculate the initial delays for the RSSI before first sweep
{ {
uint32_t t; uint32_t t;
if (MODE_OUTPUT(setting.mode)) if (MODE_OUTPUT(setting.mode))
t = 100; t = 100;
else { else {
uint32_t a = (SI4432_step_delay + MEASURE_TIME) * (sweep_points - 1); // Single RSSI delay and measurement time in uS while scanning uint32_t bare_sweep_time = (SI4432_step_delay + MEASURE_TIME) * (sweep_points - 1); // Single RSSI delay and measurement time in uS while scanning
if (FREQ_IS_CW()) { if (FREQ_IS_CW()) {
a = MINIMUM_SWEEP_TIME; // time per step in fast CW mode bare_sweep_time = MINIMUM_SWEEP_TIME; // minimum sweep time in fast CW mode
if (setting.repeat != 1 || setting.sweep_time_us >= ONE_SECOND_TIME || setting.spur != 0) if (setting.repeat != 1 || setting.sweep_time_us >= ONE_SECOND_TIME || setting.spur != 0) // if no fast CW sweep possible
a = 15000; // time per step in CW mode with repeat too long for fast delay bare_sweep_time = 15000; // minimum CW sweep time when not in fast CW mode
} }
t = vbwSteps * (setting.spur ? 2 : 1) * ( (a + (setting.repeat - 1)* ( REPEAT_TIME * (sweep_points - 1)))); t = vbwSteps * (setting.spur ? 2 : 1) * bare_sweep_time ; // factor in vbwSteps and spur impact
t += (setting.repeat - 1)* REPEAT_TIME * (sweep_points - 1); // Add time required for repeats
} }
return t; return t;
} }
@ -233,8 +234,8 @@ void set_level_sweep(float l)
void set_sweep_time_us(uint32_t t) // Set the sweep time as the user wants it to be. void set_sweep_time_us(uint32_t t) // Set the sweep time as the user wants it to be.
{ {
if (t < MINIMUM_SWEEP_TIME) // if (t < MINIMUM_SWEEP_TIME) // Sweep time of zero means sweep as fast as possible
t = MINIMUM_SWEEP_TIME; // t = MINIMUM_SWEEP_TIME;
if (t > MAXIMUM_SWEEP_TIME) if (t > MAXIMUM_SWEEP_TIME)
t = MAXIMUM_SWEEP_TIME; t = MAXIMUM_SWEEP_TIME;
setting.sweep_time_us = t; setting.sweep_time_us = t;
@ -1274,6 +1275,7 @@ static const int wfm_modulation[5] = { 0, 190, 118, -118, -190 }; // 5 step wi
char age[POINTS_COUNT]; char age[POINTS_COUNT];
static float old_a = -150; static float old_a = -150;
systime_t measure;
float perform(bool break_on_operation, int i, uint32_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup float perform(bool break_on_operation, int i, uint32_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup
{ {
@ -1283,6 +1285,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
dirty = false; dirty = false;
if (setting.spur) // if in spur avoidance mode if (setting.spur) // if in spur avoidance mode
setting.spur = 1; // resync spur in case of previous abort setting.spur = 1; // resync spur in case of previous abort
measure = chVTGetSystemTimeX(); // initialize again to eliminate time spend in apply_settings
} }
if (setting.mode == M_GENLOW && setting.level_sweep != 0.0) { // if in low output mode and level sweep is active if (setting.mode == M_GENLOW && setting.level_sweep != 0.0) { // if in low output mode and level sweep is active
@ -1588,7 +1591,6 @@ again: // Waiting for a trigger jumps back to here
// shell_printf("\r\n"); // shell_printf("\r\n");
modulation_counter = 0; // init modulation counter in case needed modulation_counter = 0; // init modulation counter in case needed
if (dirty) { // Calculate new scanning solution if (dirty) { // Calculate new scanning solution
update_rbw(); update_rbw();
calculate_step_delay(); calculate_step_delay();
@ -1600,11 +1602,13 @@ again: // Waiting for a trigger jumps back to here
// V // V
if (setting.sweep_time_us > setting.actual_sweep_time_us){ if (setting.sweep_time_us > setting.actual_sweep_time_us){
setting.additional_step_delay_us = (setting.sweep_time_us - setting.actual_sweep_time_us)/(sweep_points-1); setting.additional_step_delay_us = (setting.sweep_time_us - setting.actual_sweep_time_us)/(sweep_points-1);
setting.actual_sweep_time_us = setting.sweep_time_us;
} }
else{ // not add additional correction, apply recommend time else{ // not add additional correction, apply recommend time
setting.additional_step_delay_us = 0; setting.additional_step_delay_us = 0;
setting.sweep_time_us = setting.actual_sweep_time_us; // setting.sweep_time_us = setting.actual_sweep_time_us;
} }
#if 0
// manually set delay, for better sync // manually set delay, for better sync
if (setting.sweep_time_us < 2.5 * ONE_MS_TIME){ if (setting.sweep_time_us < 2.5 * ONE_MS_TIME){
setting.additional_step_delay_us = 0; setting.additional_step_delay_us = 0;
@ -1614,6 +1618,7 @@ again: // Waiting for a trigger jumps back to here
setting.additional_step_delay_us = 1; setting.additional_step_delay_us = 1;
setting.sweep_time_us = 3000; setting.sweep_time_us = 3000;
} }
#endif
if (MODE_OUTPUT(setting.mode) && setting.additional_step_delay_us < 500) // Minimum wait time to prevent LO from lockup during output frequency sweep if (MODE_OUTPUT(setting.mode) && setting.additional_step_delay_us < 500) // Minimum wait time to prevent LO from lockup during output frequency sweep
setting.additional_step_delay_us = 500; setting.additional_step_delay_us = 500;
// Update greed and status after // Update greed and status after
@ -1625,7 +1630,8 @@ again: // Waiting for a trigger jumps back to here
} }
} }
setting.measure_sweep_time_us = chVTGetSystemTimeX(); // start measure sweep time setting.measure_sweep_time_us = 0; // start measure sweep time
measure = chVTGetSystemTimeX();
sweep_again: // stay in sweep loop when output mode and modulation on. sweep_again: // stay in sweep loop when output mode and modulation on.
@ -1646,7 +1652,7 @@ sweep_again: // stay in sweep loop when output mo
// if break back to top level to handle ui operation // if break back to top level to handle ui operation
if ((operation_requested || shell_function) && break_on_operation) { // break loop if needed if ((operation_requested || shell_function) && break_on_operation) { // break loop if needed
if (setting.sweep_time_us > ONE_SECOND_TIME && MODE_INPUT(setting.mode)) { if (setting.actual_sweep_time_us > ONE_SECOND_TIME && MODE_INPUT(setting.mode)) {
ili9341_fill(OFFSETX, HEIGHT_NOSCROLL+1, WIDTH, 1, 0); ili9341_fill(OFFSETX, HEIGHT_NOSCROLL+1, WIDTH, 1, 0);
} }
return false; return false;
@ -1654,7 +1660,7 @@ sweep_again: // stay in sweep loop when output mo
if (MODE_INPUT(setting.mode)) { if (MODE_INPUT(setting.mode)) {
if (setting.sweep_time_us > ONE_SECOND_TIME && (i & 0x07) == 0) { // if required if (setting.actual_sweep_time_us > ONE_SECOND_TIME && (i & 0x07) == 0) { // if required
ili9341_fill(OFFSETX, HEIGHT_NOSCROLL+1, i, 1, BRIGHT_COLOR_GREEN); // update sweep progress bar ili9341_fill(OFFSETX, HEIGHT_NOSCROLL+1, i, 1, BRIGHT_COLOR_GREEN); // update sweep progress bar
ili9341_fill(OFFSETX+i, HEIGHT_NOSCROLL+1, WIDTH-i, 1, 0); ili9341_fill(OFFSETX+i, HEIGHT_NOSCROLL+1, WIDTH-i, 1, 0);
} }
@ -1765,7 +1771,7 @@ sweep_again: // stay in sweep loop when output mo
// ---------------------- process measured actual sweep time ----------------- // ---------------------- process measured actual sweep time -----------------
// For CW mode value calculated in SI4432_Fill // For CW mode value calculated in SI4432_Fill
if (setting.measure_sweep_time_us == 0) if (setting.measure_sweep_time_us == 0)
setting.measure_sweep_time_us = (chVTGetSystemTimeX() - setting.measure_sweep_time_us) * 100; setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure) * 100;
// Update actual time on change on status panel // Update actual time on change on status panel
uint32_t delta = abs((int)(setting.actual_sweep_time_us - setting.measure_sweep_time_us)); uint32_t delta = abs((int)(setting.actual_sweep_time_us - setting.measure_sweep_time_us));
@ -1773,6 +1779,7 @@ sweep_again: // stay in sweep loop when output mo
redraw_request|=REDRAW_CAL_STATUS; redraw_request|=REDRAW_CAL_STATUS;
} }
setting.actual_sweep_time_us = setting.measure_sweep_time_us; setting.actual_sweep_time_us = setting.measure_sweep_time_us;
// Not possible reduce sweep time, it minimum! // Not possible reduce sweep time, it minimum!
if (setting.sweep_time_us < setting.actual_sweep_time_us && setting.additional_step_delay_us == 0){ if (setting.sweep_time_us < setting.actual_sweep_time_us && setting.additional_step_delay_us == 0){
// Warning!! not correct set sweep time here, you get error!! // Warning!! not correct set sweep time here, you get error!!
@ -1788,8 +1795,10 @@ sweep_again: // stay in sweep loop when output mo
// selected time less then actual, need reduce delay // selected time less then actual, need reduce delay
if (setting.sweep_time_us < setting.actual_sweep_time_us){ if (setting.sweep_time_us < setting.actual_sweep_time_us){
dt = (setting.actual_sweep_time_us - setting.sweep_time_us)/(sweep_points - 1); dt = (setting.actual_sweep_time_us - setting.sweep_time_us)/(sweep_points - 1);
if (setting.additional_step_delay_us > dt) setting.additional_step_delay_us-=dt; if (setting.additional_step_delay_us > dt)
else setting.additional_step_delay_us = 0; setting.additional_step_delay_us-=dt;
else
setting.additional_step_delay_us = 0;
}// selected time greater then actual, need increase delay }// selected time greater then actual, need increase delay
else if (setting.sweep_time_us > setting.actual_sweep_time_us){ else if (setting.sweep_time_us > setting.actual_sweep_time_us){
dt = (setting.sweep_time_us - setting.actual_sweep_time_us)/(sweep_points - 1); dt = (setting.sweep_time_us - setting.actual_sweep_time_us)/(sweep_points - 1);

@ -425,7 +425,7 @@ void SI4432_Fill(int s, int start)
#else #else
shiftInBuf(sel, SI4432_REG_RSSI, (uint8_t *)&age[start], sweep_points - start, t); shiftInBuf(sel, SI4432_REG_RSSI, (uint8_t *)&age[start], sweep_points - start, t);
#endif #endif
setting.measure_sweep_time_us+= (chVTGetSystemTimeX() - measure)*100; setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure)*100;
buf_index = start; // Is used to skip 1st entry during level triggering buf_index = start; // Is used to skip 1st entry during level triggering
buf_read = true; buf_read = true;
} }

@ -1846,9 +1846,9 @@ static void fetch_numeric_target(void)
plot_printf(uistat.text, sizeof uistat.text, "%.1fdB", uistat.value); plot_printf(uistat.text, sizeof uistat.text, "%.1fdB", uistat.value);
break; break;
case KM_SWEEP_TIME: case KM_SWEEP_TIME:
if (setting.sweep_time_us < calc_min_sweep_time_us()) // if (setting.sweep_time_us < calc_min_sweep_time_us())
uistat.value = calc_min_sweep_time_us(); // uistat.value = calc_min_sweep_time_us();
else // else
uistat.value = setting.sweep_time_us; uistat.value = setting.sweep_time_us;
uistat.value /= (float)ONE_SECOND_TIME; uistat.value /= (float)ONE_SECOND_TIME;
plot_printf(uistat.text, sizeof uistat.text, "%.3Fs", uistat.value); plot_printf(uistat.text, sizeof uistat.text, "%.3Fs", uistat.value);

Loading…
Cancel
Save

Powered by TurnKey Linux.