diff --git a/source/Core/BSP/Sequre/Pins.h b/source/Core/BSP/Sequre/Pins.h index 183c3700..46ee1291 100644 --- a/source/Core/BSP/Sequre/Pins.h +++ b/source/Core/BSP/Sequre/Pins.h @@ -73,16 +73,13 @@ #ifdef MODEL_T55 -#define KEY_B_Pin GPIO_PIN_1 -#define KEY_B_GPIO_Port GPIOB -#define TMP36_INPUT_Pin GPIO_PIN_5 -#define TMP36_INPUT_GPIO_Port GPIOA -#define TMP36_ADC1_CHANNEL ADC_CHANNEL_5 -#define TMP36_ADC2_CHANNEL ADC_CHANNEL_5 -#define TIP_TEMP_Pin GPIO_PIN_0 +#define KEY_B_Pin GPIO_PIN_1 +#define KEY_B_GPIO_Port GPIOB +// No cold junction compensation as its a PT1000 +#define TIP_TEMP_Pin GPIO_PIN_5 #define TIP_TEMP_GPIO_Port GPIOA -#define TIP_TEMP_ADC1_CHANNEL ADC_CHANNEL_0 -#define TIP_TEMP_ADC2_CHANNEL ADC_CHANNEL_0 +#define TIP_TEMP_ADC1_CHANNEL ADC_CHANNEL_5 +#define TIP_TEMP_ADC2_CHANNEL ADC_CHANNEL_5 #define VIN_Pin GPIO_PIN_4 #define VIN_GPIO_Port GPIOA #define VIN_ADC1_CHANNEL ADC_CHANNEL_4 diff --git a/source/Core/BSP/Sequre/Setup.cpp b/source/Core/BSP/Sequre/Setup.cpp index a5d5845e..2f999fe4 100644 --- a/source/Core/BSP/Sequre/Setup.cpp +++ b/source/Core/BSP/Sequre/Setup.cpp @@ -63,6 +63,7 @@ void Setup_HAL() { } uint16_t getADCHandleTemp(uint8_t sample) { +#ifdef TMP36_ADC1_CHANNEL static history filter = {{0}, 0, 0}; if (sample) { uint32_t sum = 0; @@ -72,6 +73,9 @@ uint16_t getADCHandleTemp(uint8_t sample) { filter.update(sum); } return filter.average() >> 1; +#else + return 0; +#endif } uint16_t getADCVin(uint8_t sample) { @@ -165,13 +169,19 @@ static void MX_ADC1_Init(void) { hadc1.Init.NbrOfConversion = 1; HAL_ADC_Init(&hadc1); - /**Configure Regular Channel - */ +/**Configure Regular Channel + */ +#ifdef TMP36_ADC1_CHANNEL sConfig.Channel = TMP36_ADC1_CHANNEL; sConfig.Rank = ADC_REGULAR_RANK_1; sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5; HAL_ADC_ConfigChannel(&hadc1, &sConfig); - +#else + sConfig.Channel = VIN_ADC1_CHANNEL; // Filler + sConfig.Rank = ADC_REGULAR_RANK_1; + sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5; + HAL_ADC_ConfigChannel(&hadc1, &sConfig); +#endif /**Configure Injected Channel */ // F in = 10.66 MHz diff --git a/source/Core/BSP/Sequre/ThermoModel.cpp b/source/Core/BSP/Sequre/ThermoModel.cpp index bf5973f8..9fe38597 100644 --- a/source/Core/BSP/Sequre/ThermoModel.cpp +++ b/source/Core/BSP/Sequre/ThermoModel.cpp @@ -8,9 +8,78 @@ #include "Utils.h" #include "configuration.h" -#ifdef TEMP_uV_LOOKUP_PT100_1K_PULLUP +#ifdef TEMP_uV_LOOKUP_PT1000 +// Use https://br.flukecal.com/pt100-table-generator to make table for resistance to temp +const int32_t ohmsToDegC[] = { + // + // Resistance (ohms x10) Temperature (Celsius) + + 10000, 0, // + 10390, 10, // + 10779, 20, // + 11167, 30, // + 11554, 40, // + 11940, 50, // + 12324, 60, // + 12708, 70, // + 13090, 80, // + 13471, 90, // + 13851, 100, // + 14229, 110, // + 14607, 120, // + 14983, 130, // + 15358, 140, // + 15733, 150, // + 16105, 160, // + 16477, 170, // + 16848, 180, // + 17217, 190, // + 17586, 200, // + 17953, 210, // + 18319, 220, // + 18684, 230, // + 19047, 240, // + 19410, 250, // + 19771, 260, // + 20131, 270, // + 20490, 280, // + 20848, 290, // + 21205, 300, // + 21561, 310, // + 21915, 320, // + 22268, 330, // + 22621, 340, // + 22972, 350, // + 23321, 360, // + 23670, 370, // + 24018, 380, // + 24364, 390, // + 24709, 400, // + 25053, 410, // + 25396, 420, // + 25738, 430, // + 26078, 440, // + 26418, 450, // + 26756, 460, // + 27093, 470, // + 27429, 480, // + 27764, 490, // + 28098, 500, // + +}; + +TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { + + // 3.3V -> 1K ->(ADC) <- PT1000 <- GND + // PT100 = (adc*r1)/(3.3V-adc) + uint32_t reading_mv = tipuVDelta / 1000; + uint32_t resistance_x10 = (reading_mv * 10000) / (3300 - reading_mv); + + return Utils::InterpolateLookupTable(ohmsToDegC, sizeof(ohmsToDegC) / (2 * sizeof(int32_t)), resistance_x10); +} + +#endif // TEMP_uV_LOOKUP_PT1000 -#endif // TEMP_uV_LOOKUP_PT100_1K_PULLUP #ifdef TEMP_uV_LOOKUP_S60 TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return (tipuVDelta * 50) / 485; } #endif // TEMP_uV_LOOKUP_S60 diff --git a/source/Core/BSP/Sequre/configuration.h b/source/Core/BSP/Sequre/configuration.h index 9a1cb770..66357022 100644 --- a/source/Core/BSP/Sequre/configuration.h +++ b/source/Core/BSP/Sequre/configuration.h @@ -212,7 +212,7 @@ #define MAX_POWER_LIMIT 70 #define POWER_LIMIT_STEPS 5 #define OP_AMP_GAIN_STAGE 536 -#define TEMP_uV_LOOKUP_PT100_1K_PULLUP +#define TEMP_uV_LOOKUP_PT1000 #define USB_PD_VMAX 20 // Maximum voltage for PD to negotiate #define NO_DISPLAY_ROTATE // Disable OLED rotation by accel diff --git a/source/Core/BSP/Sequre/stm32f1xx_hal_msp.c b/source/Core/BSP/Sequre/stm32f1xx_hal_msp.c index 6610a0d4..9a19a7c5 100644 --- a/source/Core/BSP/Sequre/stm32f1xx_hal_msp.c +++ b/source/Core/BSP/Sequre/stm32f1xx_hal_msp.c @@ -56,12 +56,15 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) { PB0 ------> ADC2_IN8 PB1 ------> ADC2_IN9 */ + GPIO_InitStruct.Pin = TIP_TEMP_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; HAL_GPIO_Init(TIP_TEMP_GPIO_Port, &GPIO_InitStruct); +#ifdef TMP36_INPUT_Pin GPIO_InitStruct.Pin = TMP36_INPUT_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; HAL_GPIO_Init(TMP36_INPUT_GPIO_Port, &GPIO_InitStruct); +#endif GPIO_InitStruct.Pin = VIN_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; HAL_GPIO_Init(VIN_GPIO_Port, &GPIO_InitStruct);