From 90f23a9228efebbe23456b767ba55cd7ad3927b7 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 27 Apr 2021 21:35:07 +1000 Subject: [PATCH] WiP on hotplate temp reading --- Documentation/Hardware.md | 8 +++ source/Core/Drivers/FUSB302/int_n.cpp | 2 +- source/Core/Drivers/MSA301.cpp | 2 +- source/Core/Drivers/TipThermoModel.cpp | 87 ++++++++++---------------- source/Core/Inc/configuration.h | 4 +- source/Makefile | 41 ++++++++++-- 6 files changed, 82 insertions(+), 62 deletions(-) create mode 100644 Documentation/Hardware.md diff --git a/Documentation/Hardware.md b/Documentation/Hardware.md new file mode 100644 index 00000000..15454b31 --- /dev/null +++ b/Documentation/Hardware.md @@ -0,0 +1,8 @@ +## Notes on the various supported hardware + +### MHP30 + +- Accelerometer is the MSA301, this is mounted roughly in the middle of the unit +- USB-PD is using the FUSB302 +- The hardware I2C bus on PB6/7 is used for the MSA301 and FUSB302 +- The OLED is the same SSD1306 as everything else, but its on a bit-banged bus diff --git a/source/Core/Drivers/FUSB302/int_n.cpp b/source/Core/Drivers/FUSB302/int_n.cpp index 418e74c2..f571913d 100644 --- a/source/Core/Drivers/FUSB302/int_n.cpp +++ b/source/Core/Drivers/FUSB302/int_n.cpp @@ -57,7 +57,7 @@ void InterruptHandler::readPendingMessage() { } } -void InterruptHandler::Thread(const void *arg) { +void InterruptHandler::Thread(const void *arg) { (void)arg; union fusb_status status; for (;;) { diff --git a/source/Core/Drivers/MSA301.cpp b/source/Core/Drivers/MSA301.cpp index 97bb4a9d..3e1b9e46 100644 --- a/source/Core/Drivers/MSA301.cpp +++ b/source/Core/Drivers/MSA301.cpp @@ -7,7 +7,7 @@ #include "MSA301_defines.h" #include -#define MSA301_I2C_ADDRESS 0x26<<1 +#define MSA301_I2C_ADDRESS 0x26 << 1 bool MSA301::detect() { return FRToSI2C::probe(MSA301_I2C_ADDRESS); } static const FRToSI2C::I2C_REG i2c_registers[] = { diff --git a/source/Core/Drivers/TipThermoModel.cpp b/source/Core/Drivers/TipThermoModel.cpp index 8caac0ff..626cc0f4 100644 --- a/source/Core/Drivers/TipThermoModel.cpp +++ b/source/Core/Drivers/TipThermoModel.cpp @@ -27,8 +27,8 @@ * * This was bought to my attention by */ - -uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC, bool skipCalOffset) { +volatile uint32_t lastuv = 0; +uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC, bool skipCalOffset) { // This takes the raw ADC samples, converts these to uV // Then divides this down by the gain to convert to the uV on the input to the op-amp (A+B terminals) // Then remove the calibration value that is stored as a tip offset @@ -48,7 +48,7 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC, bool skipCalOffse else valueuV = 0; } - + lastuv = valueuV; return valueuV; } @@ -126,56 +126,34 @@ const uint16_t uVtoDegC[] = { // // 0, 0, // - 266, 10, // - 522, 20, // - 770, 30, // - 1010, 40, // - 1244, 50, // - 1473, 60, // - 1697, 70, // - 1917, 80, // - 2135, 90, // - 2351, 100, // - 2566, 110, // - 2780, 120, // - 2994, 130, // - 3209, 140, // - 3426, 150, // - 3644, 160, // - 3865, 170, // - 4088, 180, // - 4314, 190, // - 4544, 200, // - 4777, 210, // - 5014, 220, // - 5255, 230, // - 5500, 240, // - 5750, 250, // - 6003, 260, // - 6261, 270, // - 6523, 280, // - 6789, 290, // - 7059, 300, // - 7332, 310, // - 7609, 320, // - 7889, 330, // - 8171, 340, // - 8456, 350, // - 8742, 360, // - 9030, 370, // - 9319, 380, // - 9607, 390, // - 9896, 400, // - 10183, 410, // - 10468, 420, // - 10750, 430, // - 11029, 440, // - 11304, 450, // - 11573, 460, // - 11835, 470, // - 12091, 480, // - 12337, 490, // - 12575, 500, // + 397, 10, // + 798, 20, /// + 1203, 30, // + 1612, 40, // + 2023, 50, // + 2436, 60, // + 3225, 79, // + 4013, 98, // + 4756, 116, // + 5491, 134, // + 5694, 139, // + 6339, 155, // + 7021, 172, // + 7859, 193, // + 8619, 212, // + 9383, 231, // + 10153, 250, // + 10930, 269, // + 11712, 288, // + 12499, 307, // + 13290, 326, // + 14084, 345, // + 14881, 364, // + 15680, 383, // + 16482, 402, // + 17285, 421, // + 18091, 440, // + 18898, 459, // }; #endif @@ -266,9 +244,10 @@ uint32_t TipThermoModel::convertFtoC(uint32_t degF) { } return ((degF - 32) * 5) / 9; } - +volatile uint32_t lastTemp=0; uint32_t TipThermoModel::getTipInC(bool sampleNow) { int32_t currentTipTempInC = TipThermoModel::convertTipRawADCToDegC(getTipRawTemp(sampleNow)); + lastTemp=currentTipTempInC; currentTipTempInC += getHandleTemperature() / 10; // Add handle offset // Power usage indicates that our tip temp is lower than our thermocouple temp. // I found a number that doesn't unbalance the existing PID, causing overshoot. diff --git a/source/Core/Inc/configuration.h b/source/Core/Inc/configuration.h index 98b36747..99714f99 100644 --- a/source/Core/Inc/configuration.h +++ b/source/Core/Inc/configuration.h @@ -166,7 +166,7 @@ #ifdef MODEL_MHP30 #define VOLTAGE_DIV 350 // Default for MHP30 #define PID_POWER_LIMIT 65 // Sets the max pwm power limit -#define CALIBRATION_OFFSET 900 // the adc offset in uV +#define CALIBRATION_OFFSET 0 // the adc offset in uV #define POWER_LIMIT 65 // 65 watts default power limit #define MAX_POWER_LIMIT 65 // #define POWER_LIMIT_STEPS 2 // @@ -197,5 +197,5 @@ const uint8_t tipResistance = 45; // x10 ohms, 4.5 typical for ts80 tips #ifdef MODEL_MHP30 const uint32_t tipMass = 100; // TODO -const uint8_t tipResistance = 75; // x10 ohms, ~6 typical +const uint8_t tipResistance = 75; // x10 ohms, ~6 typical #endif diff --git a/source/Makefile b/source/Makefile index b86c3c88..57273fea 100644 --- a/source/Makefile +++ b/source/Makefile @@ -5,7 +5,8 @@ endif ALL_MINIWARE_MODELS=TS100 TS80 TS80P ALL_PINE_MODELS=Pinecil -ALL_MODELS=$(ALL_MINIWARE_MODELS) $(ALL_PINE_MODELS) +ALL_MHP30_MODELS=MHP30 +ALL_MODELS=$(ALL_MINIWARE_MODELS) $(ALL_PINE_MODELS) $(ALL_MHP30_MODELS) ifneq ($(model),$(filter $(model),$(ALL_MODELS))) $(error Invalid model '$(model)', valid options are: $(ALL_MODELS)) endif @@ -27,9 +28,15 @@ MINIWARE_INC_CMSIS_DEVICE = ./Core/BSP/Miniware/Vendor/CMSIS/Device/ST/STM32F1xx MINIWARE_CMSIS_CORE_INC_DIR = ./Core/BSP/Miniware/Vendor/CMSIS/Include MINIWARE_HAL_INC_DIR = ./Core/BSP/Miniware/Vendor/STM32F1xx_HAL_Driver/Inc MINIWARE_HAL_LEGACY_INC_DIR = ./Core/BSP/Miniware/Vendor/STM32F1xx_HAL_Driver/Inc/Legacy +MINIWARE_STARTUP_DIR = ./Startup +MHP30_INC_CMSIS_DEVICE = ./Core/BSP/MHP30/Vendor/CMSIS/Device/ST/STM32F1xx/Include +MHP30_CMSIS_CORE_INC_DIR = ./Core/BSP/MHP30/Vendor/CMSIS/Include +MHP30_HAL_INC_DIR = ./Core/BSP/MHP30/Vendor/STM32F1xx_HAL_Driver/Inc +MHP30_HAL_LEGACY_INC_DIR = ./Core/BSP/MHP30/Vendor/STM32F1xx_HAL_Driver/Inc/Legacy +MHP30_STARTUP_DIR = ./Startup + FRTOS_CMIS_INC_DIR = ./Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS FRTOS_INC_DIR = ./Middlewares/Third_Party/FreeRTOS/Source/include -MINIWARE_STARTUP_DIR = ./Startup DRIVER_INC_DIR =./Core/Drivers BSP_INC_DIR = ./Core/BSP THREADS_INC_DIR = ./Core/Threads @@ -80,7 +87,33 @@ CPUFLAGS= -mcpu=cortex-m3 \ flash_size=64k bootldr_size=0x4000 endif - +ifeq ($(model),$(filter $(model),$(ALL_MHP30_MODELS))) +$(info Building for MHP30 ) +DEVICE_INCLUDES = -I$(MHP30_INC_DIR) \ + -I$(MHP30_INC_CMSIS_DEVICE)\ + -I$(MHP30_CMSIS_CORE_INC_DIR) \ + -I$(MHP30_HAL_INC_DIR) \ + -I$(MHP30_HAL_LEGACY_INC_DIR) +DEVICE_BSP_DIR = ./Core/BSP/MHP30 +S_SRCS := $(shell find $(MHP30_STARTUP_DIR) -type f -name '*.S') +LDSCRIPT=stm32f103.ld +DEV_GLOBAL_DEFS= -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D GCC_ARMCM3 \ + -D ARM_MATH_CM3 \ + -D STM32F10X_MD +DEV_LDFLAGS=-lm -Wl,--gc-sections +DEV_AFLAGS= +DEV_CFLAGS= -D GCC_ARMCM3 \ + -D ARM_MATH_CM3 \ + -D STM32F10X_MD +DEV_CXXFLAGS= -D GCC_ARMCM3 \ + -D ARM_MATH_CM3 \ + -D STM32F10X_MD +CPUFLAGS= -mcpu=cortex-m3 \ + -mthumb \ + -mfloat-abi=soft +flash_size=128k +bootldr_size=0x0000 +endif ifeq ($(model),$(ALL_PINE_MODELS)) $(info Building for Pine64 ) DEVICE_INCLUDES = -I$(PINE_INC_DIR) \ @@ -158,7 +191,7 @@ COMPILER=gcc # arm-none-eabi is the general ARM compiler, # riscv-none-embed is the riscv compiler # riscv-nuclei-elf is the nuclei tuned one for their cores -ifeq ($(model),$(filter $(model),$(ALL_MINIWARE_MODELS))) +ifeq ($(model),$(filter $(model),$(ALL_MINIWARE_MODELS) $(ALL_MHP30_MODELS))) COMPILER_PREFIX=arm-none-eabi endif ifeq ($(model),$(ALL_PINE_MODELS))