mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Rewrite tip resistance measurement
This commit is contained in:
@@ -226,8 +226,9 @@ void setStatusLED(const enum StatusLED state) {
|
|||||||
// Dont have one
|
// Dont have one
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t lastTipResistance = 0; // default to unknown
|
uint8_t lastTipResistance = 0; // default to unknown
|
||||||
uint32_t lastTipReadinguV = 0;
|
uint32_t tipResistanceReadings[4] = {0, 0, 0, 0};
|
||||||
|
uint8_t tipResistanceReadingSlot = 0;
|
||||||
uint8_t getTipResitanceX10() {
|
uint8_t getTipResitanceX10() {
|
||||||
// Return tip resistance in x10 ohms
|
// Return tip resistance in x10 ohms
|
||||||
// We can measure this using the op-amp
|
// We can measure this using the op-amp
|
||||||
@@ -240,70 +241,69 @@ uint8_t getTipThermalMass() {
|
|||||||
}
|
}
|
||||||
return (TIP_THERMAL_MASS * 25) / 10;
|
return (TIP_THERMAL_MASS * 25) / 10;
|
||||||
}
|
}
|
||||||
void startMeasureTipResistance() {
|
// We want to calculate lastTipResistance
|
||||||
// We want to calculate lastTipResistance
|
// If tip is connected, and the tip is cold and the tip is not being heated
|
||||||
// If tip is connected, and the tip is cold and the tip is not being heated
|
// We can use the GPIO to inject a small current into the tip and measure this
|
||||||
// We can use the GPIO to inject a small current into the tip and measure this
|
// The gpio is 5.1k -> diode -> tip -> gnd
|
||||||
// The gpio is 5.1k -> diode -> tip -> gnd
|
// Source is 3.3V-0.5V
|
||||||
// Source is 3.3V-0.5V
|
// Which is around 0.54mA this will induce:
|
||||||
// Which is around 0.54mA this will induce:
|
// 6 ohm tip -> 3.24mV (Real world ~= 3320)
|
||||||
// 6 ohm tip -> 3.24mV (Real world ~= 3320)
|
// 8 ohm tip -> 4.32mV (Real world ~= 4500)
|
||||||
// 8 ohm tip -> 4.32mV (Real world ~= 4500)
|
// Which is definitely measureable
|
||||||
// Which is definitely measureable
|
// Taking shortcuts here as we know we only really have to pick apart 6 and 8 ohm tips
|
||||||
// Taking shortcuts here as we know we only really have to pick apart 6 and 8 ohm tips
|
// These are reported as 60 and 75 respectively
|
||||||
// These are reported as 60 and 75 respectively
|
void performTipResistanceSampleReading() {
|
||||||
lastTipReadinguV = TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0));
|
// 0 = read then turn on pullup, 1 = read then turn off pullup, 2 = read then turn on pullup, 3 = final read + turn off pullup
|
||||||
gpio_write(TIP_RESISTANCE_SENSE, 1);
|
tipResistanceReadings[tipResistanceReadingSlot] = TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0));
|
||||||
|
gpio_write(TIP_RESISTANCE_SENSE, (tipResistanceReadingSlot % 2) ? 0 : 1);
|
||||||
|
tipResistanceReadingSlot++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinishMeasureTipResistance() {
|
void FinishMeasureTipResistance() {
|
||||||
gpio_write(TIP_RESISTANCE_SENSE, 0);
|
|
||||||
// read the tip uV with the current source on
|
// Otherwise we now have the 4 samples;
|
||||||
uint32_t newReading = (TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0)));
|
// _^_^ order, 3 delta's, combine these
|
||||||
if (newReading < lastTipReadinguV) {
|
|
||||||
return;
|
int32_t steps[4] = {
|
||||||
}
|
// Close samples
|
||||||
// newReading -= lastTipReadinguV;
|
tipResistanceReadings[1] - tipResistanceReadings[0],
|
||||||
// MSG("Tip Delta %lu, %lu %lu \r\n", newReading - lastTipReadinguV, newReading, lastTipReadinguV);
|
tipResistanceReadings[3] - tipResistanceReadings[2],
|
||||||
newReading -= lastTipReadinguV;
|
tipResistanceReadings[1] - tipResistanceReadings[2],
|
||||||
|
// Longer time span samples
|
||||||
|
tipResistanceReadings[3] - tipResistanceReadings[0],
|
||||||
|
|
||||||
|
};
|
||||||
|
// The steps array now contains all 4 changes, these _should_ all be basically the same, but they may not be
|
||||||
|
// For example, a hot tip cooling down. In this case there will a difference in them proportional to the temp drop during that time
|
||||||
|
auto reading = (steps[0] + steps[1] + steps[2] + steps[3]) / 4;
|
||||||
|
// MSG("Tip reading %lu \r\n");
|
||||||
|
|
||||||
// As we are only detecting two resistances; we can split the difference for now
|
// As we are only detecting two resistances; we can split the difference for now
|
||||||
uint8_t newRes = 0;
|
uint8_t newRes = 0;
|
||||||
if (newReading > 8000) {
|
if (reading > 8000) {
|
||||||
return; // Change nothing as probably disconnected tip
|
// return; // Change nothing as probably disconnected tip
|
||||||
} else if (newReading < 5000) {
|
} else if (reading < 5000) {
|
||||||
newRes = 62;
|
newRes = 62;
|
||||||
} else {
|
} else {
|
||||||
newRes = 80;
|
newRes = 80;
|
||||||
}
|
}
|
||||||
lastTipResistance = newRes;
|
lastTipResistance = newRes;
|
||||||
}
|
}
|
||||||
volatile bool tipMeasurementOccuring = false;
|
volatile bool tipMeasurementOccuring = true;
|
||||||
|
volatile TickType_t nextTipMeasurement = 100;
|
||||||
|
|
||||||
void performTipMeasurementStep(bool start) {
|
void performTipMeasurementStep() {
|
||||||
static TickType_t lastMeas = 0;
|
|
||||||
// Inter state that performs the steps to measure the resistor on the tip
|
|
||||||
// Return 1 if a measurement is ongoing
|
|
||||||
|
|
||||||
// We want to perform our startup measurements of the tip resistance until we detect one fitted
|
|
||||||
|
|
||||||
// Step 1; if not setup, we turn on pullup and then wait
|
|
||||||
if (tipMeasurementOccuring == false && (start || lastTipResistance == 0 || lastMeas == 0)) {
|
|
||||||
// Block starting if tip removed
|
|
||||||
if (isTipDisconnected()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tipMeasurementOccuring = true;
|
|
||||||
lastTipResistance = 0;
|
|
||||||
lastMeas = xTaskGetTickCount();
|
|
||||||
startMeasureTipResistance();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait 100ms for settle time
|
// Wait 100ms for settle time
|
||||||
if ((xTaskGetTickCount() - lastMeas) < (TICKS_100MS)) {
|
if (xTaskGetTickCount() < (nextTipMeasurement)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nextTipMeasurement = xTaskGetTickCount() + TICKS_100MS;
|
||||||
|
if (tipResistanceReadingSlot < 4) {
|
||||||
|
performTipResistanceSampleReading();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastMeas = xTaskGetTickCount();
|
|
||||||
// We are sensing the resistance
|
// We are sensing the resistance
|
||||||
FinishMeasureTipResistance();
|
FinishMeasureTipResistance();
|
||||||
|
|
||||||
@@ -311,10 +311,10 @@ void performTipMeasurementStep(bool start) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t preStartChecks() {
|
uint8_t preStartChecks() {
|
||||||
performTipMeasurementStep(false);
|
performTipMeasurementStep();
|
||||||
return tipMeasurementOccuring ? 1 : 0;
|
return preStartChecksDone();
|
||||||
}
|
}
|
||||||
uint8_t preStartChecksDone() { return (lastTipResistance == 0 || tipMeasurementOccuring) ? 0 : 1; }
|
uint8_t preStartChecksDone() { return (lastTipResistance == 0 || tipResistanceReadingSlot < 4 || tipMeasurementOccuring) ? 0 : 1; }
|
||||||
|
|
||||||
// Return hardware unique ID if possible
|
// Return hardware unique ID if possible
|
||||||
uint64_t getDeviceID() {
|
uint64_t getDeviceID() {
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ void startPIDTask(void const *argument __unused) {
|
|||||||
getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 1);
|
getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (preStartChecks() != 0) {
|
while (preStartChecks() == 0) {
|
||||||
|
resetWatchdog();
|
||||||
ulTaskNotifyTake(pdTRUE, 2000);
|
ulTaskNotifyTake(pdTRUE, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user