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/glutt-o-logique | |
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/glutt-o-logique')
-rw-r--r-- | src/glutt-o-logique/analog_input.c | 19 | ||||
-rw-r--r-- | src/glutt-o-logique/usart.c | 1 |
2 files changed, 12 insertions, 8 deletions
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); |