From 226750df4c4f40c39c422ec225057d446cebf813 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 23 May 2022 19:34:33 +1000 Subject: [PATCH] Correct adc gain --- source/Core/BSP/Magic/BSP.cpp | 4 ++-- source/Core/BSP/Magic/IRQ.cpp | 10 ++-------- source/Core/BSP/Magic/Pins.h | 20 +++++++++----------- source/Core/BSP/Magic/Setup.cpp | 3 +-- source/Core/BSP/Magic/configuration.h | 3 ++- source/Core/Drivers/TipThermoModel.cpp | 3 ++- 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/source/Core/BSP/Magic/BSP.cpp b/source/Core/BSP/Magic/BSP.cpp index 64011ad5..4325569d 100644 --- a/source/Core/BSP/Magic/BSP.cpp +++ b/source/Core/BSP/Magic/BSP.cpp @@ -12,8 +12,8 @@ // These control the period's of time used for the PWM const uint16_t powerPWM = 255; -const uint8_t holdoffTicks = 3; // This is the tick delay -const uint8_t tempMeasureTicks = 4; +const uint8_t holdoffTicks = 5; // This is the tick delay +const uint8_t tempMeasureTicks = 5; uint16_t totalPWM = 255; // Total length of the cycle's ticks diff --git a/source/Core/BSP/Magic/IRQ.cpp b/source/Core/BSP/Magic/IRQ.cpp index 75dda176..d7b6dcef 100644 --- a/source/Core/BSP/Magic/IRQ.cpp +++ b/source/Core/BSP/Magic/IRQ.cpp @@ -173,16 +173,10 @@ bool getFUS302IRQLow() { // Return true if the IRQ line is still held low return !gpio_read(FUSB302_IRQ_Pin); } -uint16_t rescaleADC(const uint16_t value) { - // TODO This can be removed once we figure out final op-amp scaling - // return value; - uint32_t temp = value * 33; - uint16_t res = temp / 32; - return res; -} + uint16_t getADCHandleTemp(uint8_t sample) { return ADC_Temp.average(); } uint16_t getADCVin(uint8_t sample) { return ADC_Vin.average(); } // Returns either average or instant value. When sample is set the samples from the injected ADC are copied to the filter and then the raw reading is returned -uint16_t getTipRawTemp(uint8_t sample) { return rescaleADC(ADC_Tip.average() >> 1); } +uint16_t getTipRawTemp(uint8_t sample) { return ADC_Tip.average() >> 1; } diff --git a/source/Core/BSP/Magic/Pins.h b/source/Core/BSP/Magic/Pins.h index 45ff2565..3baf060c 100644 --- a/source/Core/BSP/Magic/Pins.h +++ b/source/Core/BSP/Magic/Pins.h @@ -16,17 +16,15 @@ #define TIP_TEMP_Pin GPIO_PIN_19 #define TIP_TEMP_ADC_CHANNEL ADC_CHAN9 -#define Debug_Pin GPIO_PIN_14 -#define Debug2_Pin GPIO_PIN_15 - -#define VIN_Pin GPIO_PIN_18 -#define VIN_ADC_CHANNEL ADC_CHAN8 -#define OLED_RESET_Pin GPIO_PIN_3 -#define KEY_A_Pin GPIO_PIN_25 -#define PWM_Out_Pin GPIO_PIN_21 -#define PWM_Channel PWM_CH1 -#define SCL_Pin GPIO_PIN_11 -#define SDA_Pin GPIO_PIN_10 +#define TIP_RESISTANCE_SENSE GPIO_PIN_24 +#define VIN_Pin GPIO_PIN_18 +#define VIN_ADC_CHANNEL ADC_CHAN8 +#define OLED_RESET_Pin GPIO_PIN_3 +#define KEY_A_Pin GPIO_PIN_25 +#define PWM_Out_Pin GPIO_PIN_21 +#define PWM_Channel PWM_CH1 +#define SCL_Pin GPIO_PIN_11 +#define SDA_Pin GPIO_PIN_10 #define USB_DM_Pin GPIO_PIN_8 #define QC_DP_LOW_Pin GPIO_PIN_5 diff --git a/source/Core/BSP/Magic/Setup.cpp b/source/Core/BSP/Magic/Setup.cpp index 52124f12..c843f669 100644 --- a/source/Core/BSP/Magic/Setup.cpp +++ b/source/Core/BSP/Magic/Setup.cpp @@ -29,8 +29,7 @@ void hardware_init() { gpio_set_mode(TMP36_INPUT_Pin, GPIO_INPUT_MODE); gpio_set_mode(TIP_TEMP_Pin, GPIO_INPUT_MODE); gpio_set_mode(VIN_Pin, GPIO_INPUT_MODE); - gpio_set_mode(Debug_Pin, GPIO_OUTPUT_MODE); - gpio_set_mode(Debug2_Pin, GPIO_OUTPUT_MODE); + gpio_set_mode(TIP_RESISTANCE_SENSE, GPIO_INPUT_MODE); setup_timer_scheduler(); setup_adc(); diff --git a/source/Core/BSP/Magic/configuration.h b/source/Core/BSP/Magic/configuration.h index 69742d6e..c98a566a 100644 --- a/source/Core/BSP/Magic/configuration.h +++ b/source/Core/BSP/Magic/configuration.h @@ -104,7 +104,7 @@ #define ANIMATION_LOOP 1 // 0: off 1: on #define ANIMATION_SPEED settingOffSpeed_t::MEDIUM -#define OP_AMP_Rf_Pinecil 850 * 1000 // 750 Kilo-ohms -> From schematic, R1 +#define OP_AMP_Rf_Pinecil 866 * 1000 // 750 Kilo-ohms -> From schematic, R1 #define OP_AMP_Rin_Pinecil 2370 // 2.37 Kilo-ohms -> From schematic, R2 #define OP_AMP_GAIN_STAGE_PINECIL (1 + (OP_AMP_Rf_Pinecil / OP_AMP_Rin_Pinecil)) @@ -114,6 +114,7 @@ #endif #ifdef MODEL_Magic +#define ADC_VDD_MV 3200 // ADC max reading millivolts #define SOLDERING_TEMP 320 // Default soldering temp is 320.0 °C #define VOLTAGE_DIV 600 // 290 - Default divider from schematic #define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV diff --git a/source/Core/Drivers/TipThermoModel.cpp b/source/Core/Drivers/TipThermoModel.cpp index 4e708d54..9c41bcec 100644 --- a/source/Core/Drivers/TipThermoModel.cpp +++ b/source/Core/Drivers/TipThermoModel.cpp @@ -9,6 +9,7 @@ #include "BSP.h" #include "Settings.h" #include "Utils.h" +#include "configuration.h" #include "main.hpp" #include "power.hpp" /* @@ -32,7 +33,7 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC, bool ski // 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 - uint32_t vddRailmVX10 = 33000; // The vreg is +-2%, but we have no higher accuracy available + uint32_t vddRailmVX10 = ADC_VDD_MV * 10; // The vreg is +-2%, but we have no higher accuracy available // 4096 * 8 readings for full scale // Convert the input ADC reading back into mV times 10 format. uint32_t rawInputmVX10 = (rawADC * vddRailmVX10) / (4096 * 8);