diff options
| author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-06-12 18:54:14 +0200 | 
|---|---|---|
| committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-06-12 18:54:14 +0200 | 
| commit | e20f8816f48aa80a82b241ef73e2d9ab92833f87 (patch) | |
| tree | 60cfd4d9fa7e3f3525df8ad98ddaa9cf65fe2825 /src | |
| parent | 6f95a22ce25839825c79d4529317984bd3e1b870 (diff) | |
| download | glutte-o-matic-e20f8816f48aa80a82b241ef73e2d9ab92833f87.tar.gz glutte-o-matic-e20f8816f48aa80a82b241ef73e2d9ab92833f87.tar.bz2 glutte-o-matic-e20f8816f48aa80a82b241ef73e2d9ab92833f87.zip | |
Fix analog supply voltage readout
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/includes/Core/fsm.h | 1 | ||||
| -rw-r--r-- | src/common/includes/GPIO/analog.h | 5 | ||||
| -rw-r--r-- | src/common/sourcelist.txt | 1 | ||||
| -rw-r--r-- | src/common/src/Core/main.c | 14 | ||||
| -rw-r--r-- | src/common/src/GPIO/usart.c | 11 | ||||
| -rw-r--r-- | src/glutt-o-logique/analog_input.c | 19 | ||||
| -rw-r--r-- | src/glutt-o-logique/usart.c | 1 | 
7 files changed, 37 insertions, 15 deletions
| diff --git a/src/common/includes/Core/fsm.h b/src/common/includes/Core/fsm.h index 75f1f46..94698b4 100644 --- a/src/common/includes/Core/fsm.h +++ b/src/common/includes/Core/fsm.h @@ -74,7 +74,6 @@ struct fsm_input_signals_t {  // All signals the FSM has to control  struct fsm_output_signals_t {      /* Signals to the repeater electronics */ -    int qrp;               // Place the repeater in QRP mode // TODO move out of FSM      int tx_on;             // Enable TX circuitry      int modulation;        // Enable repeater RX to TX modulation diff --git a/src/common/includes/GPIO/analog.h b/src/common/includes/GPIO/analog.h index 99404f6..54dfb5d 100644 --- a/src/common/includes/GPIO/analog.h +++ b/src/common/includes/GPIO/analog.h @@ -30,3 +30,8 @@ void analog_init(void);   * Returns 0.0f in case of error */  float analog_measure_12v(void); +/* Keep an average of measurements, and decide if the repeater should enter + * QRP. Returns 1 if low power must be activated + */ +int analog_supply_too_low(void); + diff --git a/src/common/sourcelist.txt b/src/common/sourcelist.txt index 0abc086..eada47f 100644 --- a/src/common/sourcelist.txt +++ b/src/common/sourcelist.txt @@ -1,3 +1,4 @@ +src/GPIO/analog.c  src/GPIO/usart.c  src/GPIO/temperature.c  src/GPS/gps.c diff --git a/src/common/src/Core/main.c b/src/common/src/Core/main.c index a30a3f6..22aca74 100644 --- a/src/common/src/Core/main.c +++ b/src/common/src/Core/main.c @@ -188,6 +188,7 @@ static void launcher_task(void __attribute__ ((unused))*pvParameters)      usart_debug_puts("Init done.\r\n"); +    int last_qrp = 0;      while(1) {          int i = 0;          vTaskDelay(pdMS_TO_TICKS(1000)); @@ -201,6 +202,14 @@ 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 should be %d\r\n", qrp); +            last_qrp = qrp; + +            pio_set_qrp(qrp); +        } +          const float supply_voltage = analog_measure_12v();          usart_debug("12V monitor %dmV\r\n", (int32_t)(supply_voltage * 1000.0f));      } @@ -232,10 +241,10 @@ static void detect_button_press(void __attribute__ ((unused))*pvParameters)              usart_debug_puts("Bouton bleu\r\n");              if (temperature_valid()) { -                  float temp = temperature_get(); +                int temp_decidegrees = temp * 10.0f; -                usart_debug("Temperature %f\r\n", temp); +                usart_debug("Temperature %d.%01d\r\n", temp_decidegrees / 10, temp_decidegrees % 10);              } else {                  usart_debug_puts("No temp\r\n"); @@ -434,7 +443,6 @@ static void exercise_fsm(void __attribute__ ((unused))*pvParameters)          pio_set_tx(fsm_out.tx_on);          pio_set_mod_off(!fsm_out.modulation); -        pio_set_qrp(fsm_out.qrp); // TODO move out of FSM          // Add message to CW generator only on rising edge of trigger          if (fsm_out.cw_psk31_trigger && !cw_last_trigger) { diff --git a/src/common/src/GPIO/usart.c b/src/common/src/GPIO/usart.c index ee7e96d..ee7ad9f 100644 --- a/src/common/src/GPIO/usart.c +++ b/src/common/src/GPIO/usart.c @@ -28,6 +28,7 @@  #include <inttypes.h>  #include "Core/common.h"  #include "GPIO/usart.h" +#include "GPIO/analog.h"  #include "FreeRTOS.h"  #include "task.h"  #include "queue.h" @@ -128,11 +129,15 @@ static void usart_clear_nmea_buffer(void) {  void usart_process_char(char c) {      if (c == 'h') { -        usart_debug_puts("help: no commands supported yet!\r\n"); -    } else { +        usart_debug_puts("help: commands: [v]oltage.\r\n"); +    } +    else if (c == 'v') { +        const float supply_voltage = analog_measure_12v(); +        usart_debug("12V monitor %dmV\r\n", (int32_t)(supply_voltage * 1000.0f)); +    } +    else {          usart_debug("Unknown command %c\r\n", c);      } -  }  void usart_gps_process_char(char c) { diff --git a/src/glutt-o-logique/analog_input.c b/src/glutt-o-logique/analog_input.c index 8b65cf8..d970238 100644 --- a/src/glutt-o-logique/analog_input.c +++ b/src/glutt-o-logique/analog_input.c @@ -39,7 +39,7 @@ void analog_init(void)      GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; -    GPIO_Init(GPIOC, &GPIO_InitStructure); +    GPIO_Init(GPIOA, &GPIO_InitStructure);      // Init ADC1 for supply measurement      ADC_CommonInitTypeDef ADC_CommonInitStruct; @@ -78,12 +78,15 @@ float analog_measure_12v(void)      // TODO add timeout      while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); -    const float raw_value = ADC_GetConversionValue(ADC1); +    const uint16_t raw_value = ADC_GetConversionValue(ADC1); -    // Voltage divider 22k / (82k + 22k) must be inverted here -    // Also, we round to steps of 0.5 -    float voltage = raw_value * (2.0f * 104.0f / 22.0f); -    voltage = roundf(voltage); -    voltage = voltage / 2.0f; -    return voltage; +    const float adc_max_value = (1 << 12); +    const float v_ref = 2.965f; + +    // Convert ADC measurement to voltage +    float voltage = ((float)raw_value*v_ref/adc_max_value); + +    // Compensate resistor divider on board (see schematic) +    return voltage * 202.0f / 22.0f;  } + diff --git a/src/glutt-o-logique/usart.c b/src/glutt-o-logique/usart.c index 0b02ec5..29943e9 100644 --- a/src/glutt-o-logique/usart.c +++ b/src/glutt-o-logique/usart.c @@ -38,6 +38,7 @@ const uint16_t GPIOA_PIN_USART2_TX = GPIO_Pin_2;  #include "../common/includes/GPIO/usart.h" +#define USART2_RECEIVE_ENABLE 0 // TODO something is not working  void USART2_IRQHandler(void);  void USART3_IRQHandler(void); | 
