Some fixes for timings

pull/4/head
DiSlord 6 years ago
parent 741ec58db9
commit 0c83dc063d

@ -1102,7 +1102,11 @@ set_sweep_frequency(int type, uint32_t freq)
freq = START_MIN; freq = START_MIN;
if (freq > STOP_MAX) if (freq > STOP_MAX)
freq = STOP_MAX; freq = STOP_MAX;
// CW mode if span freq = 0
if (type == ST_SPAN && freq == 0){
type = ST_CW;
freq = setting.frequency0 / 2 + setting.frequency1 / 2;
}
ensure_edit_config(); ensure_edit_config();
switch (type) { switch (type) {
case ST_START: case ST_START:
@ -1155,6 +1159,7 @@ set_sweep_frequency(int type, uint32_t freq)
if (setting.frequency0 != freq || setting.frequency1 != freq) { if (setting.frequency0 != freq || setting.frequency1 != freq) {
setting.frequency0 = freq; setting.frequency0 = freq;
setting.frequency1 = freq; setting.frequency1 = freq;
setting.sweep_time_us = 0; // use minimum as start
} }
break; break;
} }

@ -1612,11 +1612,10 @@ draw_all(bool flush)
// STOP_PROFILE // STOP_PROFILE
#endif #endif
} }
if (redraw_request & (REDRAW_CAL_STATUS | REDRAW_FREQUENCY) ) { if (redraw_request & REDRAW_CAL_STATUS)
draw_cal_status(); // calculates the actual sweep time, must be before draw_frequencies draw_cal_status(); // calculates the actual sweep time, must be before draw_frequencies
// if (redraw_request & REDRAW_FREQUENCY) if (redraw_request & REDRAW_FREQUENCY)
draw_frequencies(); draw_frequencies();
}
if (redraw_request & REDRAW_BATTERY) if (redraw_request & REDRAW_BATTERY)
draw_battery_status(); draw_battery_status();
redraw_request = 0; redraw_request = 0;
@ -2068,7 +2067,7 @@ draw_frequencies(void)
#endif #endif
if (FREQ_IS_CW()) { if (FREQ_IS_CW()) {
plot_printf(buf1, sizeof(buf1), " CW %qHz", get_sweep_frequency(ST_CW)); plot_printf(buf1, sizeof(buf1), " CW %qHz", get_sweep_frequency(ST_CW));
// Show user actual select sweep time?
uint32_t t = setting.actual_sweep_time_us; uint32_t t = setting.actual_sweep_time_us;
plot_printf(buf2, sizeof(buf2), " TIME %.3Fs", (float)t/ONE_SECOND_TIME); plot_printf(buf2, sizeof(buf2), " TIME %.3Fs", (float)t/ONE_SECOND_TIME);

@ -31,7 +31,6 @@ uint16_t actual_rbw_x10 = 0;
int vbwSteps = 1; int vbwSteps = 1;
uint32_t minFreq = 0; uint32_t minFreq = 0;
uint32_t maxFreq = 520000000; uint32_t maxFreq = 520000000;
uint32_t measured_sweep_time = 0;
//int setting.refer = -1; // Off by default //int setting.refer = -1; // Off by default
static const int reffer_freq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000}; static const int reffer_freq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000};
@ -900,7 +899,6 @@ void setupSA(void)
} }
extern int SI4432_frequency_changed; extern int SI4432_frequency_changed;
extern int SI4432_offset_changed; extern int SI4432_offset_changed;
static systime_t set_freq_time;
void set_freq(int V, unsigned long freq) // translate the requested frequency into a setting of the SI4432 void set_freq(int V, unsigned long freq) // translate the requested frequency into a setting of the SI4432
{ {
@ -933,7 +931,6 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency
} }
} }
#endif #endif
set_freq_time = chVTGetSystemTimeX();
SI4432_Set_Frequency(freq); // Impossible to use offset so set SI4432 to new frequency SI4432_Set_Frequency(freq); // Impossible to use offset so set SI4432 to new frequency
SI4432_Write_Byte(SI4432_FREQ_OFFSET1, 0); // set offset to zero SI4432_Write_Byte(SI4432_FREQ_OFFSET1, 0); // set offset to zero
SI4432_Write_Byte(SI4432_FREQ_OFFSET2, 0); SI4432_Write_Byte(SI4432_FREQ_OFFSET2, 0);
@ -1576,9 +1573,7 @@ int32_t estimated_sweep_time = 0;
static bool sweep(bool break_on_operation) static bool sweep(bool break_on_operation)
{ {
float RSSI; float RSSI;
// systime_t start_time = 0; systime_t measure;
// int start_index = -1;
int16_t downslope; int16_t downslope;
// if (setting.mode== -1) // if (setting.mode== -1)
// return; // return;
@ -1599,41 +1594,28 @@ again: // Waiting for a trigger jumps back to here
update_rbw(); update_rbw();
calculate_step_delay(); calculate_step_delay();
uint32_t t = calc_min_sweep_time_us(); uint32_t t = calc_min_sweep_time_us();
if (t < setting.sweep_time_us) { // User can select only for CW mode
setting.additional_step_delay_us = (setting.sweep_time_us - t) / (sweep_points - 1); if (setting.sweep_time_us > t && FREQ_IS_CW()){
t = setting.sweep_time_us; setting.additional_step_delay_us = (setting.sweep_time_us - t)/(sweep_points-1);
} else }
else{ // not add additional correction, apply recommend time
setting.additional_step_delay_us = 0; setting.additional_step_delay_us = 0;
setting.actual_sweep_time_us = t; setting.sweep_time_us = t;
}
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;
if (break_on_operation && MODE_INPUT(setting.mode)) { // during normal operation if (break_on_operation && MODE_INPUT(setting.mode)) { // during normal operation
redraw_request |= REDRAW_CAL_STATUS; redraw_request |= REDRAW_CAL_STATUS;
if (FREQ_IS_CW()) { // if zero span mode if (FREQ_IS_CW()) { // if zero span mode
update_grid(); // and update grid update_grid(); // and update grid and frequency
redraw_request |= REDRAW_FREQUENCY; // and time at bottom
} }
#if 0
draw_cal_status(); // show sweep time estimation
if (FREQ_IS_CW()) { // if zero span mode
update_grid(); // and update grid
//redraw_request |= REDRAW_FREQUENCY; // and time at bottom
draw_frequencies();
}
#endif
} }
} }
uint32_t prev_sweep_time = setting.actual_sweep_time_us; setting.actual_sweep_time_us = 0; // start measure sweep time
setting.actual_sweep_time_us = 0; // to signal need for measuring measure = chVTGetSystemTimeX();
// t = setting.additional_step_delay_us;
sweep_again: // stay in sweep loop when output mode and modulation on. sweep_again: // stay in sweep loop when output mode and modulation on.
set_freq_time = 0; // for predicting the weep time
// ------------------------- start sweep loop ----------------------------------- // ------------------------- start sweep loop -----------------------------------
START_PROFILE; // needed to measure actual sweep time
for (int i = 0; i < sweep_points; i++) { for (int i = 0; i < sweep_points; i++) {
// --------------------- measure ------------------------- // --------------------- measure -------------------------
@ -1648,18 +1630,17 @@ sweep_again: // stay in sweep loop when output mo
osalThreadSleepMilliseconds(setting.additional_step_delay_us / ONE_MS_TIME); osalThreadSleepMilliseconds(setting.additional_step_delay_us / ONE_MS_TIME);
} }
// if break back to toplevel 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 (prev_sweep_time > ONE_SECOND_TIME) { if (setting.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);
// } }
setting.actual_sweep_time_us = prev_sweep_time; // restore last sweep time when aborting
return false; return false;
} }
if (MODE_INPUT(setting.mode)) { if (MODE_INPUT(setting.mode)) {
if (prev_sweep_time > ONE_SECOND_TIME && (i & 0x07) == 0) { // if required if (setting.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);
} }
@ -1755,11 +1736,9 @@ sweep_again: // stay in sweep loop when output mo
if (MODE_OUTPUT(setting.mode) && setting.modulation != MO_NONE) // if in output mode with modulation if (MODE_OUTPUT(setting.mode) && setting.modulation != MO_NONE) // if in output mode with modulation
goto sweep_again; // Keep repeating sweep loop till user aborts by input goto sweep_again; // Keep repeating sweep loop till user aborts by input
// For CW mode value calculated in SI4432_Fill
if (setting.actual_sweep_time_us == 0) if (setting.actual_sweep_time_us == 0)
setting.actual_sweep_time_us = DELTA_TIME*100; setting.actual_sweep_time_us = (chVTGetSystemTimeX() - measure) * 100;
// --------------- check if maximum is above trigger level ----------------- // --------------- check if maximum is above trigger level -----------------
@ -1774,38 +1753,34 @@ sweep_again: // stay in sweep loop when output mo
} }
// ---------------------- process measured actual sweep time ----------------- // ---------------------- process measured actual sweep time -----------------
// Not possible reduce sweep time, it minimum!
int time_difference = ((int) prev_sweep_time) - (int)setting.actual_sweep_time_us; if (setting.sweep_time_us < setting.actual_sweep_time_us && setting.additional_step_delay_us == 0){
if (time_difference < 0) // Warning!! not correct set sweep time here, you get error!!
time_difference = -time_difference; // value update to real and after + recalculated additional delay
// setting.sweep_time_us = setting.actual_sweep_time_us;
if ( time_difference >=1000) { // Update scan time if more then 1ms error // redraw_request |= REDRAW_CAL_STATUS;
redraw_request |= REDRAW_CAL_STATUS; // if (FREQ_IS_CW()) // if zero span mode
if (FREQ_IS_CW()) { // if zero span mode // update_grid();
update_grid(); // and update grid }
redraw_request |= REDRAW_FREQUENCY; // and time at bottom else{
} uint32_t dt = 0;
} static uint32_t last_dt = 0;
int correction = 0; // calculate correction to delay to match requested sweep time // selected time less then actual, need reduce delay
if (setting.actual_sweep_time_us < setting.sweep_time_us || if (setting.sweep_time_us < setting.actual_sweep_time_us){
((setting.actual_sweep_time_us > setting.sweep_time_us) && setting.additional_step_delay_us > 0) ) dt = (setting.actual_sweep_time_us - setting.sweep_time_us)/(sweep_points - 1);
correction = ((int32_t)setting.sweep_time_us - (int32_t)setting.actual_sweep_time_us ) / (sweep_points - 1); if (setting.additional_step_delay_us > dt) setting.additional_step_delay_us-=dt;
if (correction < - (int)setting.additional_step_delay_us) // ensure delay never gets negative else setting.additional_step_delay_us = 0;
correction = - (int)setting.additional_step_delay_us; }// selected time greater then actual, need increase delay
if (correction != 0) { else if (setting.sweep_time_us > setting.actual_sweep_time_us){
setting.additional_step_delay_us += correction; // correct with half the time difference to prevent overshoot dt = (setting.sweep_time_us - setting.actual_sweep_time_us)/(sweep_points - 1);
if (break_on_operation && MODE_INPUT(setting.mode) && setting.additional_step_delay_us+=dt;
(correction < -3 || correction > 3)) { // during normal operation if change is more then 1ms
redraw_request |= REDRAW_CAL_STATUS;
// draw_cal_status(); // updated actual sweep time
if (FREQ_IS_CW()) { // if zero span mode
update_grid(); // and update grid
redraw_request |= REDRAW_FREQUENCY; // and time at bottom
}
} }
// Update info on correction on next step, after apply this one
if (last_dt && dt == 0)
redraw_request|=REDRAW_CAL_STATUS|REDRAW_FREQUENCY;
last_dt = dt;
} }
// ---------------------- sweep finished, do all postprocessing --------------------- // ---------------------- sweep finished, do all postprocessing ---------------------
if (scandirty) { if (scandirty) {
@ -2325,17 +2300,24 @@ void draw_cal_status(void)
strcpy(&buf[1],"Scan:"); strcpy(&buf[1],"Scan:");
ili9341_drawstring(buf, x, y); ili9341_drawstring(buf, x, y);
y += YSTEP;
plot_printf(buf, BLEN, "%.3Fs", (float)setting.sweep_time_us/ONE_SECOND_TIME);
ili9341_drawstring(buf, x, y);
y += YSTEP; y += YSTEP;
plot_printf(buf, BLEN, "%.3Fs", (float)setting.actual_sweep_time_us/ONE_SECOND_TIME); plot_printf(buf, BLEN, "%.3Fs", (float)setting.actual_sweep_time_us/ONE_SECOND_TIME);
ili9341_drawstring(buf, x, y); ili9341_drawstring(buf, x, y);
#if 0 #if 1
y += YSTEP; y += YSTEP;
uint32_t t = calc_min_sweep_time_us(); uint32_t t = calc_min_sweep_time_us();
if (t < setting.sweep_time_us) // if (t < setting.sweep_time_us)
t = setting.sweep_time_us; // t = setting.sweep_time_us;
// setting.actual_sweep_time_us = t; // setting.actual_sweep_time_us = t;
plot_printf(buf, BLEN, "%.3Fs", (float)t/ONE_SECOND_TIME); plot_printf(buf, BLEN, "%.3Fs", (float)t/ONE_SECOND_TIME);
ili9341_drawstring(buf, x, y); ili9341_drawstring(buf, x, y);
y += YSTEP;
plot_printf(buf, BLEN, "%.3Fs", (float)setting.additional_step_delay_us/ONE_SECOND_TIME);
ili9341_drawstring(buf, x, y);
#endif #endif
// Cal output // Cal output

@ -409,7 +409,7 @@ void SI4432_Fill(int s, int start)
t = 0; t = 0;
#endif #endif
uint32_t t = setting.additional_step_delay_us; uint32_t t = setting.additional_step_delay_us;
START_PROFILE; systime_t measure = chVTGetSystemTimeX();
#if 0 #if 0
SPI2_CLK_LOW; SPI2_CLK_LOW;
int i = start; int i = start;
@ -425,11 +425,9 @@ 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
// STOP_PROFILE; setting.actual_sweep_time_us+= (chVTGetSystemTimeX() - measure)*100;
setting.actual_sweep_time_us = DELTA_TIME*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;
} }
#endif #endif

Loading…
Cancel
Save

Powered by TurnKey Linux.