Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rev2 reworking I2C to avoid IRQ stalling && adjusting thermal runaway for PinecilV2 #2049

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions source/Core/BSP/Pinecilv2/I2C_Wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_b
i2cCfg.data = p_buffer;
i2cCfg.subAddrSize = 1; // one byte address

taskENTER_CRITICAL();
vTaskSuspendAll();
/* --------------- */
err = I2C_MasterReceiveBlocking(I2C0_ID, &i2cCfg);
taskEXIT_CRITICAL();
xTaskResumeAll();
bool res = err == SUCCESS;
if (!res) {
I2C_Unstick();
Expand All @@ -65,10 +65,10 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_bu
i2cCfg.data = p_buffer;
i2cCfg.subAddrSize = 1; // one byte address

taskENTER_CRITICAL();
vTaskSuspendAll();
/* --------------- */
err = I2C_MasterSendBlocking(I2C0_ID, &i2cCfg);
taskEXIT_CRITICAL();
xTaskResumeAll();
bool res = err == SUCCESS;
if (!res) {
I2C_Unstick();
Expand Down
31 changes: 19 additions & 12 deletions source/Core/Threads/PIDThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#endif
#endif

static TickType_t powerPulseWaitUnit = 25 * TICKS_100MS; // 2.5 s
static TickType_t powerPulseDurationUnit = (5 * TICKS_100MS) / 2; // 250 ms
TaskHandle_t pidTaskNotification = NULL;
volatile TemperatureType_t currentTempTargetDegC = 0; // Current temperature target in C
int32_t powerSupplyWattageLimit = 0;
bool heaterThermalRunaway = false;
static TickType_t powerPulseWaitUnit = 25 * TICKS_100MS; // 2.5 s
static TickType_t powerPulseDurationUnit = (5 * TICKS_100MS) / 2; // 250 ms
TaskHandle_t pidTaskNotification = NULL;
volatile TemperatureType_t currentTempTargetDegC = 0; // Current temperature target in C
int32_t powerSupplyWattageLimit = 0;
uint8_t heaterThermalRunawayCounter = 0;

static int32_t getPIDResultX10Watts(TemperatureType_t set_point, TemperatureType_t current_value);
static void detectThermalRunaway(const TemperatureType_t currentTipTempInC, const uint32_t x10WattsOut);
Expand Down Expand Up @@ -71,7 +71,8 @@ void startPIDTask(void const *argument __unused) {
#endif
#endif

int32_t x10WattsOut = 0;
int32_t x10WattsOut = 0;
TickType_t lastThermalRunawayDecay = xTaskGetTickCount();

for (;;) {
x10WattsOut = 0;
Expand Down Expand Up @@ -105,6 +106,12 @@ void startPIDTask(void const *argument __unused) {
#ifdef DEBUG_UART_OUTPUT
log_system_state(x10WattsOut);
#endif
if (xTaskGetTickCount() - lastThermalRunawayDecay > TICKS_SECOND) {
lastThermalRunawayDecay = xTaskGetTickCount();
if (heaterThermalRunawayCounter > 0) {
heaterThermalRunawayCounter--;
}
}
}
}

Expand Down Expand Up @@ -249,8 +256,8 @@ void detectThermalRunaway(const TemperatureType_t currentTipTempInC, const uint3
static bool haveSeenDelta = false;

// Check for readings being pegged at the top of the ADC while the heater is off
if (!thisCycleIsHeating && (getTipRawTemp(0) > (0x7FFF - 16))) {
heaterThermalRunaway = true;
if (!thisCycleIsHeating && (getTipRawTemp(0) > (ADC_MAX_READING - 8)) && heaterThermalRunawayCounter < 255) {
heaterThermalRunawayCounter++;
}

if (haveSeenDelta) {
Expand All @@ -277,8 +284,8 @@ void detectThermalRunaway(const TemperatureType_t currentTipTempInC, const uint3
TemperatureType_t delta = tipTempMax - tiptempMin;
haveSeenDelta = true;

if (delta < THERMAL_RUNAWAY_TEMP_C) {
heaterThermalRunaway = true;
if (delta < THERMAL_RUNAWAY_TEMP_C && heaterThermalRunawayCounter < 255) {
heaterThermalRunawayCounter++;
}
}
}
Expand Down Expand Up @@ -322,7 +329,7 @@ void setOutputx10WattsViaFilters(int32_t x10WattsOut) {
if (getTipRawTemp(0) > (0x7FFF - 32)) {
x10WattsOut = 0;
}
if (heaterThermalRunaway) {
if (heaterThermalRunawayCounter > 8) {
x10WattsOut = 0;
}
#ifdef SLEW_LIMIT
Expand Down
2 changes: 1 addition & 1 deletion source/Core/Threads/UI/logic/OperatingModes.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ OperatingMode showWarnings(const ButtonState buttons, guiContext *cxt);
// Common helpers
int8_t getPowerSourceNumber(void); // Returns number ID of power source

extern bool heaterThermalRunaway;
extern uint8_t heaterThermalRunawayCounter;
#endif
8 changes: 4 additions & 4 deletions source/Core/Threads/UI/logic/Soldering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ OperatingMode gui_solderingMode(const ButtonState buttons, guiContext *cxt) {
return OperatingMode::Sleeping;
}

if (heaterThermalRunaway) {
currentTempTargetDegC = 0; // heater control off
heaterThermalRunaway = false;
cxt->transitionMode = TransitionAnimation::Right;
if (heaterThermalRunawayCounter > 8) {
currentTempTargetDegC = 0; // heater control off
heaterThermalRunawayCounter = 0;
cxt->transitionMode = TransitionAnimation::Right;
return OperatingMode::ThermalRunaway;
}
return handleSolderingButtons(buttons, cxt);
Expand Down
6 changes: 3 additions & 3 deletions source/Core/Threads/UI/logic/SolderingProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ OperatingMode gui_solderingProfileMode(const ButtonState buttons, guiContext *cx
setBuzzer(false);
return OperatingMode::HomeScreen;
}
if (heaterThermalRunaway) {
currentTempTargetDegC = 0; // heater control off
heaterThermalRunaway = false;
if (heaterThermalRunawayCounter > 8) {
currentTempTargetDegC = 0; // heater control off
heaterThermalRunawayCounter = 0;
return OperatingMode::ThermalRunaway;
}

Expand Down
2 changes: 1 addition & 1 deletion source/Core/Threads/UI/logic/utils/SolderingCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "history.hpp"
#include "ui_drawing.hpp"

extern bool heaterThermalRunaway;
extern uint8_t heaterThermalRunawayCounter;

bool checkExitSoldering(void) {
#ifdef POW_DC
Expand Down
Loading