Temperature code updates (#1814)

* Create a typedef for temperatures

* Quick parse replace temp types

* Fixup for fast/slow PWM on PinecilV2

* Update PIDThread.cpp

* Pinecil small tips need less smoothing

* Remove incorrect comment

* Remove unused function

* Update PinecilV2 Tune as well
This commit is contained in:
Ben V. Brown
2023-09-22 10:19:50 +10:00
committed by GitHub
parent f99aed5785
commit c0a5e244b9
19 changed files with 116 additions and 108 deletions

View File

@@ -3,9 +3,11 @@
#include "BSP_Power.h"
#include "BSP_QC.h"
#include "Defines.h"
#include "Types.h"
#include "configuration.h"
#include <stdbool.h>
#include <stdint.h>
/*
* BSP.h -- Board Support
*

View File

@@ -6,10 +6,12 @@
*/
#include "Setup.h"
#include "TipThermoModel.h"
#include "Types.h"
#include "Utils.h"
#include "configuration.h"
extern uint16_t tipSenseResistancex10Ohms;
uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
extern uint16_t tipSenseResistancex10Ohms;
TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
// For the MHP30, we are mimicing the original code and using the resistor fitted to the base of the heater head,
// this is measured at boot in pid task and in the disconnected tip check if tip is removed
if (tipSenseResistancex10Ohms > 900 && tipSenseResistancex10Ohms <= 1100) {

View File

@@ -127,4 +127,4 @@ const int32_t uVtoDegC[] = {
#endif
const int uVtoDegCItems = sizeof(uVtoDegC) / (2 * sizeof(uVtoDegC[0]));
uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }
TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }

View File

@@ -69,4 +69,4 @@ const int32_t uVtoDegC[] = {
const int uVtoDegCItems = sizeof(uVtoDegC) / (2 * sizeof(uVtoDegC[0]));
uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }
TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }

View File

@@ -17,8 +17,8 @@
// These control the period's of time used for the PWM
const uint16_t powerPWM = 255;
const uint8_t holdoffTicks = 25; // This is the tick delay before temp measure starts (i.e. time for op-amp recovery)
const uint8_t tempMeasureTicks = 25;
uint8_t holdoffTicks = 25; // This is the tick delay before temp measure starts (i.e. time for op-amp recovery)
uint8_t tempMeasureTicks = 25;
uint16_t totalPWM = 255; // Total length of the cycle's ticks
@@ -162,13 +162,13 @@ uint8_t getTipResistanceX10() {
uint8_t getTipThermalMass() {
if (lastTipResistance >= 80) {
return TIP_THERMAL_MASS;
return 65;
}
return 45;
}
uint8_t getTipInertia() {
if (lastTipResistance >= 80) {
return TIP_THERMAL_MASS;
return 90;
}
return 10;
}

View File

@@ -19,7 +19,7 @@ extern "C" {
}
void start_PWM_output(void);
#define ADC_Filter_Smooth 4
#define ADC_Filter_Smooth 1
history<uint16_t, ADC_Filter_Smooth> ADC_Vin;
history<uint16_t, ADC_Filter_Smooth> ADC_Temp;
history<uint16_t, ADC_Filter_Smooth> ADC_Tip;
@@ -67,19 +67,21 @@ void adc_fifo_irq(void) {
ADC_IntClr(ADC_INT_ALL);
}
static bool fastPWM = false;
static void switchToFastPWM(void);
volatile bool inFastPWMMode = false;
volatile uint16_t PWMSafetyTimer = 0;
volatile uint8_t pendingPWM = 0;
volatile bool lastPeriodWasFast = false;
static void switchToFastPWM(void);
static void switchToSlowPWM(void);
volatile uint16_t PWMSafetyTimer = 0;
volatile uint8_t pendingPWM = 0;
volatile bool pendingNextPeriodIsFast = false;
void start_PWM_output(void) {
if (PWMSafetyTimer) {
PWMSafetyTimer--;
if (lastPeriodWasFast != fastPWM) {
if (fastPWM) {
if (pendingNextPeriodIsFast != inFastPWMMode) {
if (pendingNextPeriodIsFast) {
switchToFastPWM();
} else {
switchToSlowPWM();
@@ -96,6 +98,7 @@ void start_PWM_output(void) {
}
} else {
PWM_Channel_Disable(PWM_Channel);
switchToFastPWM();
}
TIMER_Enable(TIMER_CH0);
}
@@ -108,43 +111,47 @@ void timer0_comp0_callback(void) {
void timer0_comp1_callback(void) { PWM_Channel_Disable(PWM_Channel); } // Trigged at end of output cycle; turn off the tip PWM
void switchToFastPWM(void) {
fastPWM = true;
totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
inFastPWMMode = true;
holdoffTicks = 10;
tempMeasureTicks = 10;
totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_2, totalPWM);
// ~10Hz
TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_0, powerPWM + holdoffTicks);
// Set divider to 11
// Set divider to 10 ~= 10.5Hz
uint32_t tmpVal = BL_RD_REG(TIMER_BASE, TIMER_TCDR);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, TIMER_TCDR2, 11);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, TIMER_TCDR2, 10);
BL_WR_REG(TIMER_BASE, TIMER_TCDR, tmpVal);
}
void switchToSlowPWM(void) {
// 5Hz
fastPWM = false;
totalPWM = powerPWM + tempMeasureTicks / 2 + holdoffTicks / 2;
inFastPWMMode = false;
holdoffTicks = 5;
tempMeasureTicks = 5;
totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_2, totalPWM);
// Adjust ADC
TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_0, powerPWM + (holdoffTicks / 2));
TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_0, powerPWM + holdoffTicks);
// Set divider to 22
uint32_t tmpVal = BL_RD_REG(TIMER_BASE, TIMER_TCDR);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, TIMER_TCDR2, 22);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, TIMER_TCDR2, 20);
BL_WR_REG(TIMER_BASE, TIMER_TCDR, tmpVal);
}
void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
PWMSafetyTimer = 10; // This is decremented in the handler for PWM so that the tip pwm is
// disabled if the PID task is not scheduled often enough.
pendingPWM = pulse;
fastPWM = shouldUseFastModePWM;
pendingPWM = pulse;
pendingNextPeriodIsFast = shouldUseFastModePWM;
}
extern osThreadId POWTaskHandle;

View File

@@ -21,7 +21,6 @@ void timer0_comp1_callback(void);
void timer0_comp2_callback(void);
void adc_fifo_irq(void);
void GPIO_IRQHandler(void);
void switchToSlowPWM(void);
#ifdef __cplusplus
}
#endif

View File

@@ -29,7 +29,7 @@ uint16_t getADCVin(uint8_t sample);
#ifdef __cplusplus
}
#endif
void setupFUSBIRQ();
extern const uint8_t holdoffTicks;
extern const uint8_t tempMeasureTicks;
void setupFUSBIRQ();
extern uint8_t holdoffTicks;
extern uint8_t tempMeasureTicks;
#endif /* PINE_SETUP_H_ */

View File

@@ -69,4 +69,4 @@ const int32_t uVtoDegC[] = {
const int uVtoDegCItems = sizeof(uVtoDegC) / (2 * sizeof(int32_t));
uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }
TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); }

View File

@@ -161,7 +161,6 @@
#define DEBUG_UART_OUTPUT
#define HAS_POWER_DEBUG_MENU
#define HARDWARE_MAX_WATTAGE_X10 750
#define TIP_THERMAL_MASS 65 // X10 watts to raise 1 deg C in 1 second
#define BLE_ENABLED
#define NEEDS_VBUS_PROBE 0
#define CANT_DIRECT_READ_SETTINGS

View File

@@ -8,4 +8,4 @@
#include "Utils.h"
#include "configuration.h"
uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return (tipuVDelta * 50) / 485; }
TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return (tipuVDelta * 50) / 485; }