temp_sensor: internal temperature sensor is not available on STM32F010 :(

This commit is contained in:
Thomas Kolb 2023-10-01 20:32:52 +02:00
parent 860ea0e768
commit 99a5f2bda2

View file

@ -7,7 +7,7 @@
#include <libopencm3/stm32/adc.h> #include <libopencm3/stm32/adc.h>
#include <libopencm3/stm32/dma.h> #include <libopencm3/stm32/dma.h>
#define ADC_NUM_CHANNELS 2 #define ADC_NUM_CHANNELS 1
static volatile int16_t adc_values[ADC_NUM_CHANNELS]; static volatile int16_t adc_values[ADC_NUM_CHANNELS];
static fxp_t m_temperature_internal = 0; static fxp_t m_temperature_internal = 0;
@ -49,7 +49,7 @@ static fxp_t calc_temperature_ntc(uint16_t adc_val)
// note: all resistor values in kΩ! The factor 1000 is removed from the numbers! // note: all resistor values in kΩ! The factor 1000 is removed from the numbers!
static const fxp_t ln_r_ntc_nom = 252323; // ln(47 kΩ) converted to fxp_t with 16 fractional bits static const fxp_t ln_r_ntc_nom = 252323; // ln(47 kΩ) converted to fxp_t with 16 fractional bits
static const fxp_t r1 = FXP_FROM_INT(10); static const fxp_t r1 = FXP_FROM_INT(10);
static const fxp_t b_constant = FXP_FROM_INT(4125); static const fxp_t b_constant = FXP_FROM_INT(4450);
static const fxp_t ntc_temp_nom_inv = 220; // 1/(273.15+25) * 2**16 static const fxp_t ntc_temp_nom_inv = 220; // 1/(273.15+25) * 2**16
static const fxp_t celsius2kelvin = 17901158; // (273.15) * 2**16 static const fxp_t celsius2kelvin = 17901158; // (273.15) * 2**16
@ -76,7 +76,7 @@ void temp_sensor_init(void)
{ {
uint8_t channels[ADC_NUM_CHANNELS] = { uint8_t channels[ADC_NUM_CHANNELS] = {
0, // The NTC is connected to ADC_IN0 0, // The NTC is connected to ADC_IN0
ADC_CHANNEL_TEMP // Temperature sensor //ADC_CHANNEL_TEMP // Temperature sensor
}; };
// Prepare the ADC // Prepare the ADC
@ -101,7 +101,7 @@ void temp_sensor_init(void)
// configure DMA for ADC // configure DMA for ADC
//nvic_enable_irq(NVIC_DMA1_CHANNEL1_IRQ); //nvic_enable_irq(NVIC_DMA1_CHANNEL1_IRQ);
//dma_channel_reset(DMA1, DMA_CHANNEL1); dma_channel_reset(DMA1, DMA_CHANNEL1);
dma_set_priority(DMA1, DMA_CHANNEL1, DMA_CCR_PL_LOW); dma_set_priority(DMA1, DMA_CHANNEL1, DMA_CCR_PL_LOW);
dma_set_memory_size(DMA1, DMA_CHANNEL1, DMA_CCR_MSIZE_16BIT); dma_set_memory_size(DMA1, DMA_CHANNEL1, DMA_CCR_MSIZE_16BIT);
dma_set_peripheral_size(DMA1, DMA_CHANNEL1, DMA_CCR_PSIZE_16BIT); dma_set_peripheral_size(DMA1, DMA_CHANNEL1, DMA_CCR_PSIZE_16BIT);
@ -136,7 +136,7 @@ bool temp_sensor_has_new_values(void)
// calculate temperature values and cache them. // calculate temperature values and cache them.
m_temperature_ntc = calc_temperature_ntc(adc_values[0]); m_temperature_ntc = calc_temperature_ntc(adc_values[0]);
m_temperature_internal = calc_temperature(adc_values[1]); //m_temperature_internal = calc_temperature(adc_values[1]);
return true; return true;
} else { } else {
return false; return false;