Improved level sweep, RSSI, mute on ADF step

Removed_REF_marker
erikkaashoek 5 years ago
parent 8790f22a27
commit 7fb1895f75

@ -2509,7 +2509,7 @@ static const VNAShellCommand commands[] =
#endif
{ "e", cmd_e, CMD_WAIT_MUTEX },
{ "s", cmd_s, CMD_WAIT_MUTEX },
{ "m", cmd_m, CMD_WAIT_MUTEX },
{ "m", cmd_m, 0 },
{ "p", cmd_p, CMD_WAIT_MUTEX },
{ "w", cmd_w, CMD_WAIT_MUTEX },
{ "o", cmd_o, CMD_WAIT_MUTEX },

@ -80,6 +80,9 @@
#define __HARMONIC__
#define __VBW__
#define __SWEEP_RESTART__
#define DB_PER_DEGREE_BELOW 0.056
#define DB_PER_DEGREE_ABOVE 0.069
#define CENTER_TEMPERATURE 34.0
#else
#endif
@ -305,6 +308,7 @@ extern int test_output;
extern int test_output_switch;
extern int test_output_drive;
extern int test_output_attenuate;
extern bool level_error;
#else
extern const int8_t drive_dBm [];
#endif

@ -808,7 +808,9 @@ VNA_SHELL_FUNCTION(cmd_m)
// update_rbw();
chThdSleepMilliseconds(10);
sweep_mode = SWEEP_REMOTE;
// update_rbw();
while (sweep_mode != 0)
chThdSleepMilliseconds(10);
// update_rbw();
}
VNA_SHELL_FUNCTION(cmd_p)
@ -1000,7 +1002,7 @@ VNA_SHELL_FUNCTION(cmd_q)
switch (m) {
case -1: goto usage;
case 0: test_output_switch = true; break;
case 1: test_output_drive = MAX_DRIVE - atoi(argv[i++]); argc--; break;
case 1: test_output_drive = atoi(argv[i++]); argc--; break;
case 2: test_output_attenuate = atoi(argv[i++]); argc--; break;
}
goto again;
@ -1009,8 +1011,9 @@ VNA_SHELL_FUNCTION(cmd_q)
extern float Si446x_get_temp(void);
VNA_SHELL_FUNCTION(cmd_k)
{
float value;
shell_printf("temperature: %f\r\n", Si446x_get_temp());
(void)argc;
(void)argv;
shell_printf("%.2f\r\n", Si446x_get_temp());
}

@ -285,7 +285,7 @@ void reset_settings(int m)
break;
case M_GENLOW:
#ifdef TINYSA4
setting.rx_drive=MAX_DRIVE;
setting.rx_drive= MAX_DRIVE;
setting.lo_drive=1;
#else
// setting.rx_drive=8;
@ -2513,6 +2513,7 @@ int test_output_switch = false;
int test_output_drive = 0;
int test_output_attenuate = 0;
int start_temperature = 0;
bool level_error = false;
#endif
pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup
@ -2629,7 +2630,13 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) /
correct_RSSI_freq = get_frequency_correction(f);
a += PURE_TO_float(correct_RSSI_freq);
#ifdef TINYSA4
a += (Si446x_get_temp() - 34.0) * 0.0433; // Temperature correction
{
float dt = Si446x_get_temp() - CENTER_TEMPERATURE;
if (dt > 0)
a += dt * DB_PER_DEGREE_ABOVE; // Temperature correction
else
a += dt * DB_PER_DEGREE_BELOW; // Temperature correction
}
a += 3.0; // Always 3dB in attenuator
#endif
if (a != old_a) {
@ -2671,7 +2678,7 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) /
while (a - BELOW_MAX_DRIVE(d) > 0 && d < MAX_DRIVE) { // Increase if needed
d++;
}
while (a - BELOW_MAX_DRIVE(d) < - 31 && d > LOWEST_LEVEL) { // reduce till it fits attenuator
while (a - BELOW_MAX_DRIVE(d) < - 28 && d > LOWEST_LEVEL) { // reduce till it fits attenuator (31 - 3)
d--;
}
a -= BELOW_MAX_DRIVE(d);
@ -2685,8 +2692,18 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) /
#ifdef TINYSA4
a -= 3.0; // Always at least 3dB attenuation
#endif
if (a > 0)
if (a > 0) {
a = 0;
#ifdef TINYSA4
if (!level_error) redraw_request |= REDRAW_CAL_STATUS;
level_error = true;
#endif
} else {
#ifdef TINYSA4
if (level_error) redraw_request |= REDRAW_CAL_STATUS;
level_error = false;
#endif
}
if (a < -31.5)
a = -31.5;
a = -a - 0.25; // Rounding
@ -2698,10 +2715,22 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) /
}
}
else if (setting.mode == M_GENHIGH) {
#ifdef TINYSA4
if (test_output) {
enable_rx_output(!test_output_switch);
SI4463_set_output_level(test_output_drive);
} else
#endif
{
float a = setting.level - level_max();
#ifdef TINYSA4
if (!config.high_out_adf4350)
a += (Si446x_get_temp() - 34.0) * 0.0433; // Temperature correction
if (!config.high_out_adf4350) {
float dt = Si446x_get_temp() - CENTER_TEMPERATURE;
if (dt > 0)
a += dt * DB_PER_DEGREE_ABOVE; // Temperature correction
else
a += dt * DB_PER_DEGREE_BELOW; // Temperature correction
}
#endif
if (a <= -SWITCH_ATTENUATION) {
setting.atten_step = true;
@ -2745,7 +2774,7 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) /
else
SI4463_set_output_level(d);
#endif
}
}
}
#ifdef __SI4432__

@ -108,7 +108,7 @@ void stop_SI4432_SPI_mode(void){
static void shiftOut(uint8_t val)
{
#ifdef USE_HARDWARE_SPI_MODE
// while (SPI_TX_IS_NOT_EMPTY(SI4432_SPI));
while (SPI_TX_IS_NOT_EMPTY(SI4432_SPI));
SPI_WRITE_8BIT(SI4432_SPI, val);
while (SPI_IS_BUSY(SI4432_SPI)) // drop rx and wait tx
(void)SPI_READ_8BIT(SI4432_SPI);
@ -130,8 +130,8 @@ static uint8_t shiftIn(void)
#ifdef USE_HARDWARE_SPI_MODE
// while (SPI_TX_IS_NOT_EMPTY(SI4432_SPI));
SPI_WRITE_8BIT(SI4432_SPI, 0xFF);
while (SPI_IS_BUSY(SI4432_SPI)) // drop rx and wait tx
while (SPI_RX_IS_EMPTY(SI4432_SPI)); //wait rx data in buffer
while (SPI_IS_BUSY(SI4432_SPI) || SPI_RX_IS_EMPTY(SI4432_SPI)) ; // drop rx and wait tx
// while (); //wait rx data in buffer
return SPI_READ_8BIT(SI4432_SPI);
#else
uint32_t value = 0;
@ -703,6 +703,8 @@ uint64_t ADF4351_prepare_frequency(int channel, uint64_t freq) // freq / 10Hz
// my_microsecond_delay(10);
// }
bitWrite (registers[4], 10, 1); // Mute till lock detect
registers[0] = 0;
registers[0] = INTA << 15; // OK
registers[0] = registers[0] + (FRAC << 3);
@ -868,7 +870,7 @@ static uint8_t SI4463_wait_response(void* buff, uint8_t len, uint8_t use_timeout
return 1;
}
#define SI_FAST_SPEED SPI_BR_DIV2
#define SI_FAST_SPEED SPI_BR_DIV4
void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen)
{
@ -883,8 +885,10 @@ void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen)
__disable_irq();
SI_CS_LOW;
while(SPI_RX_IS_NOT_EMPTY(SI4432_SPI)) (void)SPI_READ_8BIT(SI4432_SPI); // Remove lingering bytes
for(uint8_t i=0;i<len;i++) {
#if 1 // Inline transfer
#if 0 // Inline transfer
// while (SPI_TX_IS_NOT_EMPTY(SI4432_SPI));
SPI_WRITE_8BIT(SI4432_SPI, ((uint8_t*)data)[i]);
while (SPI_IS_BUSY(SI4432_SPI)) // drop rx and wait tx
@ -902,7 +906,7 @@ void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen)
if(out != NULL) { // If we have an output buffer then read command response into it
SI_CS_LOW;
SPI_BR_SET(SI4432_SPI, SI4432_SPI_SPEED);
#if 1
#if 0
SPI_WRITE_8BIT(SI4432_SPI,SI446X_CMD_READ_CMD_BUFF);
while (SPI_IS_BUSY(SI4432_SPI)) // drop rx and wait tx
SPI_READ_8BIT(SI4432_SPI);
@ -911,11 +915,11 @@ void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen)
SPI_READ_8BIT(SI4432_SPI);
#else
shiftOut( SI446X_CMD_READ_CMD_BUFF );
shiftIn(); // Should always be 0xFF
while (shiftIn() != 0xff); // Should always be 0xFF
#endif
// Get response data
for(uint8_t i=0;i<outLen;i++) {
#if 1 // Inline transfer
#if 0 // Inline transfer
SPI_WRITE_8BIT(SI4432_SPI, 0xFF);
while (SPI_IS_BUSY(SI4432_SPI)) // drop rx and wait tx
while (SPI_RX_IS_EMPTY(SI4432_SPI)); //wait rx data in buffer
@ -1035,8 +1039,23 @@ static void SI4463_clear_FIFO(void)
void SI4463_set_output_level(int t)
{
SI4463_output_level = t;
if (SI4463_in_tx_mode)
if (SI4463_in_tx_mode) {
#if 1
{
uint8_t data[] =
{
0x11, 0x22, 0x04, 0x00, // PA_MODE
0x08, // Coarse PA mode and class E PA Fine PA mode = 0x04
(uint8_t)SI4463_output_level, // Level
0x00, // Duty
0x00 // Ramp
};
SI4463_do_api(data, sizeof(data), NULL, 0);
}
#else
SI4463_start_tx(0); // Refresh output level
#endif
}
}
void SI4463_start_tx(uint8_t CHANNEL)
{
@ -1067,7 +1086,7 @@ void SI4463_start_tx(uint8_t CHANNEL)
uint8_t data[] =
{
0x11, 0x22, 0x04, 0x00, // PA_MODE
0x08, // Coarse PA mode and class E PA
0x08, // Coarse PA mode and class E PA Fine PA mode = 0x04
(uint8_t)SI4463_output_level, // Level
0x00, // Duty
0x00 // Ramp
@ -1374,7 +1393,7 @@ void SI446x_Fill(int s, int start)
#endif
uint32_t t = setting.additional_step_delay_us;
if (t < old_t +100 && t + 100 > old_t) {
if (t < old_t +100 && t + 100 > old_t) { // avoid oscillation
t = (t + old_t) >> 1;
}
old_t = t;
@ -1397,6 +1416,7 @@ again:
data[0] = SI446X_CMD_GET_MODEM_STATUS;
data[1] = 0xFF;
SI4463_do_api(data, 1, data, 3); // TODO no clear of interrups
#if 0
if (data[2] == 0) {
if (i > 0)
data[2] = age[i-1];
@ -1404,6 +1424,7 @@ again:
goto again;
}
if (data[2] == 255) goto again;
#endif
if (i >= 0)
age[i]=(char)data[2]; // Skip first RSSI
#else
@ -1513,7 +1534,7 @@ int16_t Si446x_RSSI(void)
int32_t RSSI_RAW = 0;
do{
// if (MODE_INPUT(setting.mode) && RSSI_R
uint8_t data[3] = {
uint8_t data[4] = {
SI446X_CMD_GET_MODEM_STATUS,
0xFF
};
@ -1527,14 +1548,15 @@ int16_t Si446x_RSSI(void)
// __disable_irq();
data[0] = SI446X_CMD_GET_MODEM_STATUS;
data[1] = 0xFF;
SI4463_do_api(data, 2, data, 3); // TODO no clear of interrupts
SI4463_do_api(data, 2, data, 4); // TODO no clear of interrupts
// __enable_irq();
#else
data[2] = getFRR(SI446X_CMD_READ_FRR_A);
#endif
if (data[2] == 255) {
if (data[0] == 255) {
my_microsecond_delay(10);
goto again;
// data[2] = data[3];
}
#if 0
if (data[2] == 0) {

@ -3114,6 +3114,14 @@ redraw_cal_status:
ili9341_fill(0, 0, OFFSETX, LCD_HEIGHT);
max_quick_menu = 0;
if (MODE_OUTPUT(setting.mode)) { // No cal status during output
#ifdef TINYSA4
if (level_error) {
color = LCD_BRIGHT_COLOR_RED;
ili9341_set_foreground(color);
ili9341_drawstring("LEVEL", 0 , 80);
ili9341_drawstring("ERROR", 0 , 90);
}
#endif
return;
}

Loading…
Cancel
Save

Powered by TurnKey Linux.