mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Far better tip resistance measurement
This commit is contained in:
@@ -227,7 +227,8 @@ void setStatusLED(const enum StatusLED state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t lastTipResistance = 0; // default to unknown
|
uint8_t lastTipResistance = 0; // default to unknown
|
||||||
uint32_t tipResistanceReadings[4] = {0, 0, 0, 0};
|
const uint8_t numTipResistanceReadings = 3;
|
||||||
|
uint32_t tipResistanceReadings[3] = {0, 0, 0};
|
||||||
uint8_t tipResistanceReadingSlot = 0;
|
uint8_t tipResistanceReadingSlot = 0;
|
||||||
uint8_t getTipResitanceX10() {
|
uint8_t getTipResitanceX10() {
|
||||||
// Return tip resistance in x10 ohms
|
// Return tip resistance in x10 ohms
|
||||||
@@ -255,30 +256,25 @@ uint8_t getTipThermalMass() {
|
|||||||
void performTipResistanceSampleReading() {
|
void performTipResistanceSampleReading() {
|
||||||
// 0 = read then turn on pullup, 1 = read then turn off pullup, 2 = read then turn on pullup, 3 = final read + turn off pullup
|
// 0 = read then turn on pullup, 1 = read then turn off pullup, 2 = read then turn on pullup, 3 = final read + turn off pullup
|
||||||
tipResistanceReadings[tipResistanceReadingSlot] = TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0));
|
tipResistanceReadings[tipResistanceReadingSlot] = TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0));
|
||||||
gpio_write(TIP_RESISTANCE_SENSE, (tipResistanceReadingSlot % 2) ? 0 : 1);
|
gpio_write(TIP_RESISTANCE_SENSE, tipResistanceReadingSlot == 0);
|
||||||
tipResistanceReadingSlot++;
|
tipResistanceReadingSlot++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinishMeasureTipResistance() {
|
void FinishMeasureTipResistance() {
|
||||||
|
|
||||||
// Otherwise we now have the 4 samples;
|
// Otherwise we now have the 4 samples;
|
||||||
// _^_^ order, 3 delta's, combine these
|
// _^_ order, 2 delta's, combine these
|
||||||
|
|
||||||
int32_t steps[4] = {
|
int32_t calculatedSkew = tipResistanceReadings[0] - tipResistanceReadings[2]; // If positive tip is cooling
|
||||||
// Close samples
|
calculatedSkew /= 2; // divide by two to get offset per time constant
|
||||||
tipResistanceReadings[1] - tipResistanceReadings[0],
|
|
||||||
tipResistanceReadings[3] - tipResistanceReadings[2],
|
|
||||||
tipResistanceReadings[1] - tipResistanceReadings[2],
|
|
||||||
// Longer time span samples
|
|
||||||
tipResistanceReadings[3] - tipResistanceReadings[0],
|
|
||||||
|
|
||||||
};
|
int32_t reading = (((tipResistanceReadings[1] - tipResistanceReadings[0]) + calculatedSkew) // jump 1 - skew
|
||||||
// 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
|
((tipResistanceReadings[1] - tipResistanceReadings[2]) + calculatedSkew) // jump 2 - skew
|
||||||
auto reading = (steps[0] + steps[1] + steps[2] + steps[3]) / 4;
|
) //
|
||||||
// MSG("Tip reading %lu \r\n");
|
/ 2; // Take average
|
||||||
|
// lastTipResistance = reading / 100;
|
||||||
// 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 (reading > 8000) {
|
if (reading > 8000) {
|
||||||
// return; // Change nothing as probably disconnected tip
|
// return; // Change nothing as probably disconnected tip
|
||||||
@@ -299,7 +295,7 @@ void performTipMeasurementStep() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nextTipMeasurement = xTaskGetTickCount() + TICKS_100MS;
|
nextTipMeasurement = xTaskGetTickCount() + TICKS_100MS;
|
||||||
if (tipResistanceReadingSlot < 4) {
|
if (tipResistanceReadingSlot < numTipResistanceReadings) {
|
||||||
performTipResistanceSampleReading();
|
performTipResistanceSampleReading();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -314,7 +310,7 @@ uint8_t preStartChecks() {
|
|||||||
performTipMeasurementStep();
|
performTipMeasurementStep();
|
||||||
return preStartChecksDone();
|
return preStartChecksDone();
|
||||||
}
|
}
|
||||||
uint8_t preStartChecksDone() { return (lastTipResistance == 0 || tipResistanceReadingSlot < 4 || tipMeasurementOccuring) ? 0 : 1; }
|
uint8_t preStartChecksDone() { return (lastTipResistance == 0 || tipResistanceReadingSlot < numTipResistanceReadings || tipMeasurementOccuring) ? 0 : 1; }
|
||||||
|
|
||||||
// Return hardware unique ID if possible
|
// Return hardware unique ID if possible
|
||||||
uint64_t getDeviceID() {
|
uint64_t getDeviceID() {
|
||||||
|
|||||||
Reference in New Issue
Block a user