From 73f07489fee90d35169dd6da2a7f2c9b685358c4 Mon Sep 17 00:00:00 2001 From: David P Hilton Date: Mon, 29 Oct 2018 08:17:58 -0600 Subject: [PATCH] PID works with max PWM of 255 --- workspace/TS100/inc/power.hpp | 4 +++- workspace/TS100/src/main.cpp | 5 +++-- workspace/TS100/src/power.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/workspace/TS100/inc/power.hpp b/workspace/TS100/inc/power.hpp index de4c35db..8959f1ba 100644 --- a/workspace/TS100/inc/power.hpp +++ b/workspace/TS100/inc/power.hpp @@ -11,7 +11,9 @@ #ifndef POWER_HPP_ #define POWER_HPP_ -extern history milliWattHistory; +const uint8_t hz = 32; +const uint8_t oscillationPeriod = 3.5 * hz; +extern history milliWattHistory; int32_t tempToMilliWatts(int32_t rawTemp, uint16_t mass, uint8_t rawC); void setTipMilliWatts(int32_t mw); diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp index 54589c25..6ddb7363 100644 --- a/workspace/TS100/src/main.cpp +++ b/workspace/TS100/src/main.cpp @@ -929,6 +929,7 @@ void startPIDTask(void const *argument __unused) { int32_t rawC = ctoTipMeasurement(100) - ctoTipMeasurement(101); // 1*C change in raw. currentlyActiveTemperatureTarget = 0; // Force start with no output (off). If in sleep / soldering this will // be over-ridden rapidly + history tempError = {{0}, 0, 0}; pidTaskNotification = xTaskGetCurrentTaskHandle(); @@ -955,8 +956,8 @@ void startPIDTask(void const *argument __unused) { // P term - total power needed to hit target temp next cycle. // thermal mass = 1690 milliJ/*C for my tip. // = Watts*Seconds to raise Temp from room temp to +100*C, divided by 100*C. - // divided by 4 to let I term dominate near set point. - const uint16_t mass = 1690 / 4; + // divided by 8 to let I term dominate near set point. + const uint16_t mass = 1690 / 8; int32_t milliWattsNeeded = tempToMilliWatts(tempError.average(), mass, rawC); milliWattsOut += milliWattsNeeded; diff --git a/workspace/TS100/src/power.cpp b/workspace/TS100/src/power.cpp index a249dc14..270d1132 100644 --- a/workspace/TS100/src/power.cpp +++ b/workspace/TS100/src/power.cpp @@ -9,11 +9,11 @@ #include #include -history milliWattHistory = {{0}, 0, 0}; - const uint8_t tipResistance = 87; -const uint8_t hz = 33; -const uint8_t maxPWM = 100; +const uint8_t maxPWM = 255; + +history milliWattHistory = {{0}, 0, 0}; + int32_t tempToMilliWatts(int32_t rawTemp, uint16_t mass, uint8_t rawC) { // mass is in milliJ/*C, rawC is raw per degree C