diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-07-10 09:39:45 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-07-10 09:39:45 +0200 |
commit | e6e3f8ff2690fe8a05658d58a13288f14bd1f461 (patch) | |
tree | 2fb594d965cd4362d9a67a53c28dbfe4e8c3f37c | |
parent | 16367c2a9da68c6c813537ea905a227864aec30f (diff) | |
download | glutte-o-matic-e6e3f8ff2690fe8a05658d58a13288f14bd1f461.tar.gz glutte-o-matic-e6e3f8ff2690fe8a05658d58a13288f14bd1f461.tar.bz2 glutte-o-matic-e6e3f8ff2690fe8a05658d58a13288f14bd1f461.zip |
Add reflected power handling with fixed threshold
-rw-r--r-- | src/common/includes/GPIO/analog.h | 4 | ||||
-rw-r--r-- | src/common/src/Core/main.c | 57 | ||||
-rw-r--r-- | src/glutt-o-logique/analog_input.c | 13 | ||||
-rw-r--r-- | src/simulator/src/GPIO/analog_input.c | 6 |
4 files changed, 57 insertions, 23 deletions
diff --git a/src/common/includes/GPIO/analog.h b/src/common/includes/GPIO/analog.h index 0c45f0c..375708f 100644 --- a/src/common/includes/GPIO/analog.h +++ b/src/common/includes/GPIO/analog.h @@ -32,10 +32,10 @@ void analog_init(void); */ float analog_measure_12v(void); -/* Measure SWR, and return raw values. +/* Measure SWR, and return voltages in mV. * Returns 0 in case of error, 1 in case of success */ -int analog_measure_swr(uint16_t *forward, uint16_t* reflected); +int analog_measure_swr(int *forward_mv, int* reflected_mv); /* Keep an average of measurements, and decide if the repeater should enter * QRP. Returns 1 if low power must be activated diff --git a/src/common/src/Core/main.c b/src/common/src/Core/main.c index 8db5f20..48a77c9 100644 --- a/src/common/src/Core/main.c +++ b/src/common/src/Core/main.c @@ -53,6 +53,19 @@ static int tm_trigger_button = 0; static int tm_trigger = 0; +/* Saturating counter for SWR measurement + * + * Hysteresis: + * If the counter reaches the max value, the + * SWR Error is triggered. Once the counter + * reaches the min value, the error is + * cleared again. + */ +#define SWR_ERROR_COUNTER_MIN 0 +#define SWR_ERROR_COUNTER_MAX 10 +static int swr_error_counter = 0; +static int swr_error_flag = 0; + // Platform specific init function void init(void); @@ -188,7 +201,7 @@ static void launcher_task(void __attribute__ ((unused))*pvParameters) usart_debug_puts("Init done.\r\n"); - int last_qrp = 0; + int last_qrp_from_supply = 0; while(1) { int i = 0; vTaskDelay(pdMS_TO_TICKS(1000)); @@ -202,20 +215,42 @@ static void launcher_task(void __attribute__ ((unused))*pvParameters) leds_turn_off(LED_GREEN); } - const int qrp = analog_supply_too_low(); - if (qrp != last_qrp) { - usart_debug("QRP = %d\r\n", qrp); - last_qrp = qrp; + const int qrp_from_supply = analog_supply_too_low(); + if (swr_error_flag) { + pio_set_qrp(1); + } + else if (qrp_from_supply != last_qrp_from_supply) { + usart_debug("QRP = %d\r\n", qrp_from_supply); + last_qrp_from_supply = qrp_from_supply; - pio_set_qrp(qrp); + pio_set_qrp(qrp_from_supply); } struct fsm_output_signals_t fsm_out; fsm_get_outputs(&fsm_out); - if (1) { - //if (fsm_out.tx_on) { - uint16_t swr_fwd, swr_refl; - analog_measure_swr(&swr_fwd, &swr_refl); + + if (fsm_out.tx_on) { + int swr_fwd_mv, swr_refl_mv; + const int swr_refl_threshold = 10; // mV + if (analog_measure_swr(&swr_fwd_mv, &swr_refl_mv)) { + if (swr_refl_mv > swr_refl_threshold) { + usart_debug("SWR meas %d mV\r\n", swr_refl_mv); + swr_error_counter++; + } + else { + swr_error_counter--; + } + + if (swr_error_counter > SWR_ERROR_COUNTER_MAX) { + swr_error_counter = SWR_ERROR_COUNTER_MAX; + swr_error_flag = 1; + } + + if (swr_error_counter < SWR_ERROR_COUNTER_MIN) { + swr_error_counter = SWR_ERROR_COUNTER_MIN; + swr_error_flag = 0; + } + } } } } @@ -497,6 +532,8 @@ static void exercise_fsm(void __attribute__ ((unused))*pvParameters) leds_turn_on(LED_ORANGE); } + fsm_input.swr_high = swr_error_flag; + fsm_update_inputs(&fsm_input); fsm_update(); diff --git a/src/glutt-o-logique/analog_input.c b/src/glutt-o-logique/analog_input.c index 103d933..307eff1 100644 --- a/src/glutt-o-logique/analog_input.c +++ b/src/glutt-o-logique/analog_input.c @@ -98,16 +98,11 @@ float analog_measure_12v(void) } -int analog_measure_swr(uint16_t *forward, uint16_t* reflected) +int analog_measure_swr(int *forward_mv, int* reflected_mv) { const uint16_t raw_swr_fwd_value = analog_read_channel(ADC_CHANNEL_SWR_FWD); const uint16_t raw_swr_refl_value = analog_read_channel(ADC_CHANNEL_SWR_REFL); - *forward = raw_swr_fwd_value; - *reflected = raw_swr_refl_value; - - const int supply_decivolts = analog_measure_12v() * 10.0f; - const float adc_max_value = (1 << 12); const float v_ref = 2.965f; @@ -115,8 +110,10 @@ int analog_measure_swr(uint16_t *forward, uint16_t* reflected) const int swr_fwd = ((float)raw_swr_fwd_value*10.0f*v_ref/adc_max_value); const int swr_refl = ((float)raw_swr_refl_value*10.0f*v_ref/adc_max_value); - usart_debug("RAW Meas %d dV - %d mV - %d mV\r\n", - supply_decivolts, + *forward_mv = swr_fwd; + *reflected_mv = swr_refl; + + usart_debug("RAW Meas %d mV - %d mV\r\n", swr_fwd, swr_refl); diff --git a/src/simulator/src/GPIO/analog_input.c b/src/simulator/src/GPIO/analog_input.c index 1fc8ed1..98f64c6 100644 --- a/src/simulator/src/GPIO/analog_input.c +++ b/src/simulator/src/GPIO/analog_input.c @@ -38,10 +38,10 @@ float analog_measure_12v(void) return gui_measured_voltage; } -int analog_measure_swr(uint16_t *forward, uint16_t* reflected) +int analog_measure_swr(int *forward_mv, int *reflected_mv) { - *forward = gui_swr_forward; - *reflected = gui_swr_reflected; + *forward_mv = gui_swr_forward; + *reflected_mv = gui_swr_reflected; return 1; } |