adjust watts for PWM duty cycle
This commit is contained in:
@@ -977,10 +977,10 @@ void startPIDTask(void const *argument __unused) {
|
|||||||
// Once we have feed-forward temp estimation we should be able to better tune this.
|
// Once we have feed-forward temp estimation we should be able to better tune this.
|
||||||
|
|
||||||
#ifdef MODEL_TS100
|
#ifdef MODEL_TS100
|
||||||
const uint16_t mass = 1690 / 20; // divide here so division is compile-time.
|
const uint16_t mass = 2020 / 20; // divide here so division is compile-time.
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODEL_TS80
|
#ifdef MODEL_TS80
|
||||||
const uint16_t mass = 1690 / 50;
|
const uint16_t mass = 2020 / 50;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t milliWattsNeeded = tempToMilliWatts(tempError.average(),
|
int32_t milliWattsNeeded = tempToMilliWatts(tempError.average(),
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
#include <hardware.h>
|
#include <hardware.h>
|
||||||
|
|
||||||
uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80
|
uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80
|
||||||
const uint8_t maxPWM = 255;
|
const uint16_t powerPWM = 255;
|
||||||
|
const uint16_t totalPWM = 255+50; // Setup.c:sConfigOC.Pulse, the full PWM cycle
|
||||||
|
|
||||||
history<uint16_t, oscillationPeriod> milliWattHistory = { { 0 }, 0, 0 };
|
history<uint16_t, oscillationPeriod> milliWattHistory = { { 0 }, 0, 0 };
|
||||||
|
|
||||||
@@ -42,10 +43,10 @@ uint8_t milliWattsToPWM(int32_t milliWatts, uint8_t divisor) {
|
|||||||
// Scale input milliWatts to the pwm rate
|
// Scale input milliWatts to the pwm rate
|
||||||
int32_t v = getInputVoltageX10(divisor);// 100 = 10v
|
int32_t v = getInputVoltageX10(divisor);// 100 = 10v
|
||||||
int32_t availableMilliWatts = v * v / tipResistance;
|
int32_t availableMilliWatts = v * v / tipResistance;
|
||||||
int32_t pwm = maxPWM * milliWatts / availableMilliWatts;
|
int32_t pwm = (powerPWM * totalPWM / powerPWM) * milliWatts / availableMilliWatts;
|
||||||
|
|
||||||
if (pwm > maxPWM) {
|
if (pwm > powerPWM) {
|
||||||
pwm = maxPWM;
|
pwm = powerPWM;
|
||||||
} else if (pwm < 0) {
|
} else if (pwm < 0) {
|
||||||
pwm = 0;
|
pwm = 0;
|
||||||
}
|
}
|
||||||
@@ -54,5 +55,5 @@ uint8_t milliWattsToPWM(int32_t milliWatts, uint8_t divisor) {
|
|||||||
|
|
||||||
int32_t PWMToMilliWatts(uint8_t pwm, uint8_t divisor) {
|
int32_t PWMToMilliWatts(uint8_t pwm, uint8_t divisor) {
|
||||||
int32_t v = getInputVoltageX10(divisor);
|
int32_t v = getInputVoltageX10(divisor);
|
||||||
return pwm * (v * v / tipResistance) / maxPWM;
|
return pwm * (v * v / tipResistance) / (powerPWM * totalPWM / powerPWM);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user