mirror of
https://github.com/arwidcool/Solder-Plate.git
synced 2024-11-12 01:10:52 +01:00
Tuning the weighting factor of bottom placed thermistors and set resistence
This commit is contained in:
parent
24e93d0af5
commit
2a78a70c19
@ -39,26 +39,10 @@ void PidController::debug()
|
||||
void PidController::loop()
|
||||
{
|
||||
data->targetTemp = chosenReflowProfile.getTargetTemp();
|
||||
|
||||
data->currentTemp = thermistor1.getTemperature();
|
||||
// debug();
|
||||
|
||||
float sysVoltage = analogRef.calculateSystemVoltage();
|
||||
|
||||
// // Serial.print("Sys Voltage: ");
|
||||
// // Serial.println(sysVoltage);
|
||||
|
||||
|
||||
// if (sysVoltage < 10.5)
|
||||
// {
|
||||
|
||||
// controller.setWindUpLimits(-20, 50);
|
||||
|
||||
|
||||
// }else{
|
||||
// controller.setWindUpLimits(-100, 185);
|
||||
|
||||
// }
|
||||
|
||||
compute();
|
||||
analogWrite(MOSTFET_PIN, data->setPoint);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
return this->state;
|
||||
}
|
||||
|
||||
StateChangeEvent<State>* getSince(unsigned long time) const
|
||||
StateChangeEvent<State> *getSince(unsigned long time) const
|
||||
{
|
||||
if (this->lastStateChangeTime < time)
|
||||
{
|
||||
@ -64,9 +64,10 @@ enum ThermistorZ_Placement
|
||||
enum ThermistorXY_Placement
|
||||
{
|
||||
MIDDLE,
|
||||
SIDE
|
||||
SIDE,
|
||||
MIDDLE_LOW_TEMP,
|
||||
MIDDLE_HIGH_TEMP
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -97,12 +97,26 @@ void OledDisplay::handleDrawThermistorMenu(OledMenuItem menuItem)
|
||||
}
|
||||
else if (thermistorIndex == 7)
|
||||
{
|
||||
uint8_t decimalPlaces;
|
||||
display.setTextSize(1, 2);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
float thermR = thermistors[i].getResistance() / 1000;
|
||||
display.setCursor(i < 3 ? 0 : (SCREEN_WIDTH / 2 + 20), 20 * (i % 3));
|
||||
display.println(String(i + 1) + ":" + String(thermR));
|
||||
//A bit more data if it is a small number
|
||||
if (thermR < 100)
|
||||
{
|
||||
decimalPlaces = 2;
|
||||
}
|
||||
else if (thermR < 10)
|
||||
{
|
||||
decimalPlaces = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
decimalPlaces = 1;
|
||||
}
|
||||
display.println(String(i + 1) + ":" + String(thermR, decimalPlaces));
|
||||
}
|
||||
centerText(menuItem.title);
|
||||
displayIndicators();
|
||||
@ -110,7 +124,7 @@ void OledDisplay::handleDrawThermistorMenu(OledMenuItem menuItem)
|
||||
else
|
||||
{
|
||||
int thermistorTemp = thermistors[thermistorIndex].getTemperature();
|
||||
centerText((String(menuItem.title) + ": " + String(thermistorTemp)).c_str());
|
||||
centerText((String(menuItem.title) + ":" + String(thermistorTemp)).c_str());
|
||||
displayIndicators();
|
||||
}
|
||||
display.display();
|
||||
@ -309,7 +323,6 @@ void OledDisplay::handleReflowState()
|
||||
|
||||
display.setTextSize(1, 2);
|
||||
|
||||
|
||||
// Remaining time center left + bottom left
|
||||
uint32_t elapsedStep = chosenReflowProfile.getCurrentStepRelativeTime();
|
||||
drawPositionedText("Remaining", DisplayTextAlignment::START, DisplayTextAlignment::CENTER);
|
||||
|
@ -28,15 +28,15 @@ TempCalibration calibration_100K_3950 = {25, 100000, 107, 4957, 167, 1000};
|
||||
// To measure the resistence turn off the controller completley and measure between GND and the left pin of the connector with the thermistor unplugged
|
||||
|
||||
// 2.5k reference = Best accuracy around 138C
|
||||
Thermistor thermistor1(THERMISTOR1_PIN, 2570, ThermistorZ_Placement::TOP, ThermistorXY_Placement::MIDDLE);
|
||||
Thermistor thermistor1(THERMISTOR1_PIN, 2465 , ThermistorZ_Placement::TOP, ThermistorXY_Placement::MIDDLE);
|
||||
Thermistor thermistor2(THERMISTOR2_PIN, 2520, ThermistorZ_Placement::BOTTOM, ThermistorXY_Placement::MIDDLE);
|
||||
Thermistor thermistor3(THERMISTOR3_PIN, 2542, ThermistorZ_Placement::TOP, ThermistorXY_Placement::MIDDLE);
|
||||
Thermistor thermistor3(THERMISTOR3_PIN, 9040, ThermistorZ_Placement::BOTTOM, ThermistorXY_Placement::MIDDLE_LOW_TEMP);
|
||||
// 1k reference = Best accuracy around 173c
|
||||
Thermistor thermistor4(THERMISTOR4_PIN, 2545, ThermistorZ_Placement::TOP, ThermistorXY_Placement::MIDDLE);
|
||||
Thermistor thermistor4(THERMISTOR4_PIN, 573, ThermistorZ_Placement::BOTTOM, ThermistorXY_Placement::MIDDLE_HIGH_TEMP);
|
||||
// 515R reference = Best accuracy around 210C
|
||||
Thermistor thermistor5(THERMISTOR5_PIN, 515, ThermistorZ_Placement::TOP, ThermistorXY_Placement::MIDDLE);
|
||||
Thermistor thermistor5(THERMISTOR5_PIN, 8111, ThermistorZ_Placement::TOP, ThermistorXY_Placement::MIDDLE_LOW_TEMP);
|
||||
// 9k reference = Best accuracy around 90C -> This thermistor is used for the preheat phase if attached
|
||||
Thermistor thermistor6(THERMISTOR6_PIN, 9000, ThermistorZ_Placement::TOP, ThermistorXY_Placement::MIDDLE);
|
||||
Thermistor thermistor6(THERMISTOR6_PIN, 526, ThermistorZ_Placement::TOP, ThermistorXY_Placement::MIDDLE_HIGH_TEMP);
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -20,6 +20,10 @@
|
||||
#define debugC(x)
|
||||
#endif
|
||||
|
||||
#define START_TEMP 20
|
||||
#define LOW_TEMP_THRESHOLD 102
|
||||
#define MIDDLE_TEMP_THRESHOLD 120
|
||||
#define HIGH_TEMP_THRESHOLD 150
|
||||
|
||||
|
||||
|
||||
|
51
src/main.cpp
51
src/main.cpp
@ -61,7 +61,7 @@ void setup()
|
||||
tftDisplay.start();
|
||||
|
||||
thermTimer.setResolution(StopWatch::Resolution::MILLIS);
|
||||
thermTimer.start();
|
||||
|
||||
thermMilisTimer.setResolution(StopWatch::Resolution::MILLIS);
|
||||
}
|
||||
void loop()
|
||||
@ -109,7 +109,8 @@ void loop()
|
||||
// Start the PID
|
||||
pidController.start();
|
||||
thermMilisTimer.start();
|
||||
Serial.println("Time,Therm1,Therm2,Therm3,Therm4");
|
||||
thermTimer.start();
|
||||
Serial.println("Time,Therm1,Therm2,Therm3,Therm4,Therm5,Therm6,,Scaling1,Scaling2,Scaling3,Scaling4,Scaling5,Scaling6,Averaged1,Weighting1,Weighting2,Weighting3");
|
||||
}
|
||||
}
|
||||
state = newState;
|
||||
@ -128,18 +129,28 @@ void loop()
|
||||
ReflowStep step = chosenReflowProfile.reflowStep();
|
||||
// Here we draw the actual temp vs time to the display
|
||||
|
||||
if (thermTimer.elapsed() > 500)
|
||||
if (thermTimer.elapsed() > 1)
|
||||
{
|
||||
|
||||
Serial.print(thermTimer.elapsed());
|
||||
Serial.print(",");
|
||||
Serial.print(thermistor1.getTemperature());
|
||||
float temp1 = thermistor1.getTemperature();
|
||||
float temp2 = thermistor2.getTemperature();
|
||||
float temp3 = thermistor3.getTemperature();
|
||||
float temp4 = thermistor4.getTemperature();
|
||||
float temp5 = thermistor5.getTemperature();
|
||||
float temp6 = thermistor6.getTemperature();
|
||||
Serial.print(temp1);
|
||||
Serial.print(",");
|
||||
Serial.print(thermistor2.getTemperature());
|
||||
Serial.print(temp2);
|
||||
Serial.print(",");
|
||||
Serial.print(thermistor3.getTemperature());
|
||||
Serial.print(temp3);
|
||||
Serial.print(",");
|
||||
Serial.print(thermistor4.getTemperature());
|
||||
Serial.print(temp4);
|
||||
Serial.print(",");
|
||||
Serial.print(temp5);
|
||||
Serial.print(",");
|
||||
Serial.print(temp6);
|
||||
Serial.print(",");
|
||||
Serial.print(thermistor1.scalingFactor);
|
||||
Serial.print(",");
|
||||
@ -148,7 +159,33 @@ void loop()
|
||||
Serial.print(thermistor3.scalingFactor);
|
||||
Serial.print(",");
|
||||
Serial.print(thermistor4.scalingFactor);
|
||||
Serial.print(",");
|
||||
Serial.print(thermistor5.scalingFactor);
|
||||
Serial.print(",");
|
||||
Serial.print(thermistor6.scalingFactor);
|
||||
Serial.print(",");
|
||||
|
||||
float values[] = {temp2,temp3,temp4};
|
||||
float weights[] = {thermistor2.getWeightingFactor(),thermistor3.getWeightingFactor(),thermistor4.getWeightingFactor()};
|
||||
uint8_t length = 3;
|
||||
float averaged = TemperatureController::getWeightedAverage(values, weights, length);
|
||||
Serial.print(averaged);
|
||||
Serial.print(",");
|
||||
Serial.print(weights[0]);
|
||||
Serial.print(",");
|
||||
Serial.print(weights[1]);
|
||||
Serial.print(",");
|
||||
Serial.print(weights[2]);
|
||||
Serial.print(",");
|
||||
Serial.println();
|
||||
// Serial.print(",");
|
||||
// Serial.print(thermistor1.getWeightingFactor());
|
||||
// Serial.print(",");
|
||||
// Serial.print(thermistor2.getWeightingFactor());
|
||||
// Serial.print(",");
|
||||
// Serial.print(thermistor3.getWeightingFactor());
|
||||
// Serial.print(",");
|
||||
// Serial.print(thermistor4.getWeightingFactor());
|
||||
}
|
||||
|
||||
if (step.state != newState)
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "TemperatureController.h"
|
||||
|
||||
|
||||
TemperatureController::TemperatureController()
|
||||
{
|
||||
}
|
||||
@ -42,11 +41,29 @@ void TemperatureController::checkPluggedInThermistors()
|
||||
|
||||
float TemperatureController::getThermistorTempFast(uint8_t thermistorIndex)
|
||||
{
|
||||
|
||||
|
||||
return thermistors[thermistorIndex].getTemperatureFast();
|
||||
}
|
||||
|
||||
float TemperatureController::getWeightedAverage(float *values, float *weights, uint8_t length)
|
||||
{
|
||||
float sum = 0.0;
|
||||
float weightSum = 0.0;
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
sum += values[i] * weights[i];
|
||||
weightSum += weights[i];
|
||||
}
|
||||
|
||||
// Avoid division by zero
|
||||
if (weightSum == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sum / weightSum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates and returns the average temperature of the solder plate based on the active thermistors.
|
||||
|
@ -15,10 +15,15 @@ public:
|
||||
float getPlateTemperature();
|
||||
void checkPluggedInThermistors();
|
||||
float static getThermistorTempFast(uint8_t thermistorIndex);
|
||||
float static getWeightedAverage(float* values, float* weights, uint8_t length);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
bool thermistorIsActive[6];
|
||||
uint8_t activeThermistorCount =0 ;
|
||||
float weightFactor;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
@ -49,94 +49,200 @@ float Thermistor::getTemperature()
|
||||
scalingFactor = thermistorLookup.getFactor(zPlacement, xyPlacment, temp);
|
||||
temp = temp * scalingFactor;
|
||||
|
||||
weightFactor = getWeightingFactor();
|
||||
|
||||
currenTemperature = temp;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the coefficients for the thermistor based on the given temperature calibration.
|
||||
*
|
||||
* @param calibration The temperature calibration data.
|
||||
* @brief Returns the weighting factor for the thermistor based on its most accurate temperature range and current temp.
|
||||
* The range is based on reference resistor values.
|
||||
* This should only be called after getTemperature() has been called.
|
||||
* @return The scaling factor.
|
||||
*/
|
||||
void Thermistor::calculateCoefficents(TempCalibration calibration)
|
||||
// float Thermistor::getWeightingFactor()
|
||||
// {
|
||||
// switch (xyPlacment)
|
||||
// {
|
||||
|
||||
// // Middle always have weighting factor of 1 and the factor can only increase for the other sensors
|
||||
// case MIDDLE:
|
||||
|
||||
// return 1;
|
||||
// break;
|
||||
|
||||
// case MIDDLE_LOW_TEMP:
|
||||
|
||||
// if (currenTemperature > START_TEMP && currenTemperature < LOW_TEMP_THRESHOLD)
|
||||
// {
|
||||
// return ThermistorLookup::interpolate(currenTemperature, START_TEMP, LOW_TEMP_THRESHOLD, 1, 1.5);
|
||||
// }
|
||||
|
||||
// else if (currenTemperature > LOW_TEMP_THRESHOLD && currenTemperature < MIDDLE_TEMP_THRESHOLD)
|
||||
// {
|
||||
// return ThermistorLookup::interpolate(currenTemperature, LOW_TEMP_THRESHOLD, MIDDLE_TEMP_THRESHOLD, 1.5, 1);
|
||||
// }
|
||||
|
||||
// else if (currenTemperature > MIDDLE_TEMP_THRESHOLD && currenTemperature < HIGH_TEMP_THRESHOLD)
|
||||
// {
|
||||
// return ThermistorLookup::interpolate(currenTemperature, MIDDLE_TEMP_THRESHOLD, HIGH_TEMP_THRESHOLD, 1, 0.1);
|
||||
// }
|
||||
// else if (currenTemperature < START_TEMP)
|
||||
// {
|
||||
// return 1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return 0.1;
|
||||
// }
|
||||
|
||||
|
||||
// case MIDDLE_HIGH_TEMP:
|
||||
|
||||
// if (currenTemperature > MIDDLE_TEMP_THRESHOLD && currenTemperature < HIGH_TEMP_THRESHOLD)
|
||||
// {
|
||||
// return ThermistorLookup::interpolate(currenTemperature, MIDDLE_TEMP_THRESHOLD, HIGH_TEMP_THRESHOLD, 1, 1.5);
|
||||
// }
|
||||
|
||||
// else if (currenTemperature > HIGH_TEMP_THRESHOLD)
|
||||
// {
|
||||
// return 1.5;
|
||||
// }
|
||||
// else if (currenTemperature < MIDDLE_TEMP_THRESHOLD)
|
||||
// {
|
||||
// return ThermistorLookup::interpolate(currenTemperature, START_TEMP, MIDDLE_TEMP_THRESHOLD, 0.1, 1);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return 0.1;
|
||||
// }
|
||||
// break;
|
||||
|
||||
// default:
|
||||
// return 1;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
float Thermistor::getWeightingFactor()
|
||||
{
|
||||
float start = 1, end = 1;
|
||||
float temp_start = START_TEMP, temp_end = LOW_TEMP_THRESHOLD;
|
||||
|
||||
float lowK = calibration.lowC + K;
|
||||
float midK = calibration.midC + K;
|
||||
float highK = calibration.highC + K;
|
||||
if (xyPlacment == MIDDLE_HIGH_TEMP) {
|
||||
temp_start = MIDDLE_TEMP_THRESHOLD;
|
||||
temp_end = HIGH_TEMP_THRESHOLD;
|
||||
|
||||
float lowLnr = log(calibration.lowR);
|
||||
float midLnr = log(calibration.midR);
|
||||
float highLnr = log(calibration.highR);
|
||||
if (currenTemperature > HIGH_TEMP_THRESHOLD)
|
||||
return 1.5;
|
||||
|
||||
if (currenTemperature < MIDDLE_TEMP_THRESHOLD)
|
||||
return ThermistorLookup::interpolate(currenTemperature, START_TEMP, MIDDLE_TEMP_THRESHOLD, 0.1, 1);
|
||||
}
|
||||
|
||||
float ln1 = lowLnr - midLnr;
|
||||
float ln2 = lowLnr - highLnr;
|
||||
float t1 = (1 / lowK) - (1 / midK);
|
||||
float t2 = (1 / lowK) - (1 / highK);
|
||||
if (xyPlacment == MIDDLE_LOW_TEMP || xyPlacment == MIDDLE_HIGH_TEMP) {
|
||||
if (currenTemperature > temp_start && currenTemperature < temp_end)
|
||||
return ThermistorLookup::interpolate(currenTemperature, temp_start, temp_end, start, 1.5);
|
||||
|
||||
if (currenTemperature > temp_end && currenTemperature < HIGH_TEMP_THRESHOLD)
|
||||
return ThermistorLookup::interpolate(currenTemperature, temp_end, HIGH_TEMP_THRESHOLD, 1.5, 1);
|
||||
|
||||
if (currenTemperature > HIGH_TEMP_THRESHOLD && currenTemperature < HIGH_TEMP_THRESHOLD)
|
||||
return ThermistorLookup::interpolate(currenTemperature, HIGH_TEMP_THRESHOLD, HIGH_TEMP_THRESHOLD, 1, 0.1);
|
||||
|
||||
return (currenTemperature < START_TEMP) ? 1 : 0.1;
|
||||
}
|
||||
|
||||
float c = (t1 - ln1 * t2 / ln2) / ((pow(lowLnr, 3) - pow(midLnr, 3)) - ln1 * (pow(lowLnr, 3) - pow(highLnr, 3)) / ln2);
|
||||
float b = (t1 - c * (pow(lowLnr, 3) - pow(midLnr, 3))) / ln1;
|
||||
float a = 1 / lowK - c * pow(lowLnr, 3) - b * lowLnr;
|
||||
|
||||
coefficents.a = (a);
|
||||
coefficents.b = (b);
|
||||
coefficents.c = (c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool Thermistor::isPluggedIn()
|
||||
{
|
||||
// check if the resistnece is INF is so then the thermistor is not plugged in
|
||||
if (getResistance() == INFINITY)
|
||||
/**
|
||||
* Calculates the coefficients for the thermistor based on the given temperature calibration.
|
||||
*
|
||||
* @param calibration The temperature calibration data.
|
||||
*/
|
||||
void Thermistor::calculateCoefficents(TempCalibration calibration)
|
||||
{
|
||||
return false;
|
||||
|
||||
float lowK = calibration.lowC + K;
|
||||
float midK = calibration.midC + K;
|
||||
float highK = calibration.highC + K;
|
||||
|
||||
float lowLnr = log(calibration.lowR);
|
||||
float midLnr = log(calibration.midR);
|
||||
float highLnr = log(calibration.highR);
|
||||
|
||||
float ln1 = lowLnr - midLnr;
|
||||
float ln2 = lowLnr - highLnr;
|
||||
float t1 = (1 / lowK) - (1 / midK);
|
||||
float t2 = (1 / lowK) - (1 / highK);
|
||||
|
||||
float c = (t1 - ln1 * t2 / ln2) / ((pow(lowLnr, 3) - pow(midLnr, 3)) - ln1 * (pow(lowLnr, 3) - pow(highLnr, 3)) / ln2);
|
||||
float b = (t1 - c * (pow(lowLnr, 3) - pow(midLnr, 3))) / ln1;
|
||||
float a = 1 / lowK - c * pow(lowLnr, 3) - b * lowLnr;
|
||||
|
||||
coefficents.a = (a);
|
||||
coefficents.b = (b);
|
||||
coefficents.c = (c);
|
||||
}
|
||||
else
|
||||
|
||||
bool Thermistor::isPluggedIn()
|
||||
{
|
||||
return true;
|
||||
// check if the resistnece is INF is so then the thermistor is not plugged in
|
||||
if (getResistance() == INFINITY)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the scaling factor for the thermistor based on its placement in the 3D space.
|
||||
* The scaling factor is used to adjust the temperature readings of the thermistor.
|
||||
*/
|
||||
/**
|
||||
* Calculates the scaling factor for the thermistor based on its placement in the 3D space.
|
||||
* The scaling factor is used to adjust the temperature readings of the thermistor.
|
||||
*/
|
||||
|
||||
float Thermistor::getTemperatureFast()
|
||||
{
|
||||
float Thermistor::getTemperatureFast()
|
||||
{
|
||||
|
||||
// Get only one reading
|
||||
getResistance();
|
||||
// Get only one reading
|
||||
getResistance();
|
||||
|
||||
float temp = (int)1 / (coefficents.a + coefficents.b * log(sensorResistance) + coefficents.c * (pow(log(sensorResistance), 3))) - K;
|
||||
float temp = (int)1 / (coefficents.a + coefficents.b * log(sensorResistance) + coefficents.c * (pow(log(sensorResistance), 3))) - K;
|
||||
|
||||
// The scaling factor should only be applied when the plate is being heated up -> 60C seems like a good threshold unless you live in the sahara desert with no AC
|
||||
// The scaling factor should only be applied when the plate is being heated up -> 60C seems like a good threshold unless you live in the sahara desert with no AC
|
||||
|
||||
// Its non-linear so it will be more accurate so we will probably need to impliment a refrence table for the scaling factor this is just a rough estimate it will be based on a sensor calibrated on the top middle of the plate
|
||||
// Its non-linear so it will be more accurate so we will probably need to impliment a refrence table for the scaling factor this is just a rough estimate it will be based on a sensor calibrated on the top middle of the plate
|
||||
|
||||
// float scalingFactor = ThermistorLookup::getFactor(thermistorPin, temp);
|
||||
return temp;
|
||||
}
|
||||
// float scalingFactor = ThermistorLookup::getFactor(thermistorPin, temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
float Thermistor::getResistance()
|
||||
{
|
||||
float Thermistor::getResistance()
|
||||
{
|
||||
|
||||
float systemVoltage = analogRef.calculateSystemVoltage();
|
||||
float systemVoltage = analogRef.calculateSystemVoltage();
|
||||
|
||||
// int raw = analogRead(thermistorPin);
|
||||
// int raw = analogRead(thermistorPin);
|
||||
|
||||
// // Get resistance value
|
||||
// float buffer = raw * systemVoltage;
|
||||
// float vOut = (buffer) / 1023;
|
||||
// // Get resistance value
|
||||
// float buffer = raw * systemVoltage;
|
||||
// float vOut = (buffer) / 1023;
|
||||
|
||||
// // Calculate the resistance of the thermistor with the system voltage accounted for
|
||||
// buffer = (systemVoltage / vOut) - 1;
|
||||
// // Calculate the resistance of the thermistor with the system voltage accounted for
|
||||
// buffer = (systemVoltage / vOut) - 1;
|
||||
|
||||
// // return the resistence
|
||||
// sensorResistance = setRes * buffer;
|
||||
// // return the resistence
|
||||
// sensorResistance = setRes * buffer;
|
||||
|
||||
int sensorValue = analogRead(thermistorPin); // Read the analog value (0-1023)
|
||||
float voltage = sensorValue * (systemVoltage / 1023.0); // Convert to voltage
|
||||
float R_unknown = (setRes * (systemVoltage - voltage)) / voltage; // Calculate the unknown resistor's value
|
||||
sensorResistance = R_unknown;
|
||||
int sensorValue = analogRead(thermistorPin); // Read the analog value (0-1023)
|
||||
float voltage = sensorValue * (systemVoltage / 1023.0); // Convert to voltage
|
||||
float R_unknown = (setRes * (systemVoltage - voltage)) / voltage; // Calculate the unknown resistor's value
|
||||
sensorResistance = R_unknown;
|
||||
|
||||
return sensorResistance;
|
||||
}
|
||||
return sensorResistance;
|
||||
}
|
||||
|
@ -5,8 +5,6 @@
|
||||
#include <voltageReference/AnalogRef.h>
|
||||
#include <common.h>
|
||||
|
||||
|
||||
|
||||
struct Coefficents
|
||||
{
|
||||
float a;
|
||||
@ -33,6 +31,9 @@ extern TempCalibration calibration_100K_3950;
|
||||
#define THERMISTOR5_PIN 33
|
||||
#define THERMISTOR6_PIN 32
|
||||
|
||||
|
||||
|
||||
|
||||
extern AnalogRef analogRef;
|
||||
|
||||
class Thermistor
|
||||
@ -43,8 +44,8 @@ public:
|
||||
|
||||
Thermistor(uint8_t pin, uint16_t resistance, TempCalibration calibration, ThermistorZ_Placement zPlacement1, ThermistorXY_Placement xyPlacment1);
|
||||
|
||||
Thermistor(uint8_t pin, uint16_t resistance, ThermistorZ_Placement zPlacement1, ThermistorXY_Placement xyPlacment1) ;
|
||||
|
||||
Thermistor(uint8_t pin, uint16_t resistance, ThermistorZ_Placement zPlacement1, ThermistorXY_Placement xyPlacment1);
|
||||
|
||||
// Public Methods
|
||||
float getTemperature();
|
||||
float getResistance();
|
||||
@ -55,9 +56,11 @@ public:
|
||||
|
||||
bool isPluggedIn();
|
||||
float getTemperatureFast();
|
||||
float getWeightingFactor();
|
||||
ThermistorXY_Placement xyPlacment;
|
||||
ThermistorZ_Placement zPlacement;
|
||||
float scalingFactor ;
|
||||
float scalingFactor;
|
||||
float currenTemperature;
|
||||
|
||||
private:
|
||||
const double K = 273.15;
|
||||
@ -67,7 +70,7 @@ private:
|
||||
Coefficents coefficents;
|
||||
float referenceResistance;
|
||||
TempCalibration calibration;
|
||||
|
||||
float weightFactor;
|
||||
};
|
||||
|
||||
#endif // THERMISTOR_H
|
||||
|
@ -65,6 +65,7 @@ const LookupEntry *ThermistorLookup::getTable(ThermistorZ_Placement zPlacement,
|
||||
|
||||
tableSize = sizeof(lookupTopSide) / sizeof(LookupEntry);
|
||||
return lookupTopSide;
|
||||
|
||||
}
|
||||
case BOTTOM:
|
||||
|
||||
@ -78,6 +79,17 @@ const LookupEntry *ThermistorLookup::getTable(ThermistorZ_Placement zPlacement,
|
||||
|
||||
tableSize = sizeof(lookupTopSide) / sizeof(LookupEntry);
|
||||
return lookupTopSide;
|
||||
|
||||
case MIDDLE_LOW_TEMP:
|
||||
|
||||
tableSize = sizeof(lookupBottomMiddle) / sizeof(LookupEntry);
|
||||
return lookupBottomMiddle;
|
||||
|
||||
case MIDDLE_HIGH_TEMP:
|
||||
|
||||
tableSize = sizeof(lookupBottomMiddle) / sizeof(LookupEntry);
|
||||
return lookupBottomMiddle;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,38 +11,112 @@ struct LookupEntry
|
||||
};
|
||||
|
||||
const LookupEntry lookupBottomMiddle[] = {
|
||||
{30, 0.995205469483767},
|
||||
{35, 1.11724354649558},
|
||||
{40, 1.16221262415921},
|
||||
{45, 1.12448359746383},
|
||||
{50, 1.14499238909032},
|
||||
{55, 1.12793950375559},
|
||||
{60, 1.12337287712101},
|
||||
{65, 1.10545110139771},
|
||||
{70, 1.10234749124935},
|
||||
{75, 1.08567465426014},
|
||||
{80, 1.07869989037226},
|
||||
{85, 1.06930433073885},
|
||||
{90, 1.0538318430518},
|
||||
{95, 1.03201418470286},
|
||||
{100, 1.01896914997622},
|
||||
{105, 1.03251768817139},
|
||||
{110, 1.04022066012968},
|
||||
{115, 1.03674422635691},
|
||||
{120, 1.04064666742085},
|
||||
{125, 1.03913188754372},
|
||||
{130, 1.0442917352224},
|
||||
{135, 1.04499116157739},
|
||||
{140, 1.04135817519154},
|
||||
{145, 1.03658285343317},
|
||||
{150, 1.0259509365488},
|
||||
{155, 1.02598110989319},
|
||||
{160, 1.03930608139151},
|
||||
{165, 1.03583584549012},
|
||||
{170, 1.03308702915583},
|
||||
{175, 1.03114013373797},
|
||||
{180, 1.01800272746916},
|
||||
{185, 1.0084029872169},
|
||||
|
||||
// {20, 1},
|
||||
// {25, 1},
|
||||
// {30, 1.05421},
|
||||
// {35, 1.15779326424813},
|
||||
// {40, 1.07137955413676},
|
||||
// {45, 1.02848510334699},
|
||||
// {50, 1.0166963542828},
|
||||
// {55, 1.00055351519777},
|
||||
// {60, 0.998966148199037},
|
||||
// {65, 1.00436499654204},
|
||||
// {70, 0.994176485727482},
|
||||
// {75, 0.996391553112729},
|
||||
// {80, 1.00113614372955},
|
||||
// {85, 1.00053768922283},
|
||||
// {90, 1.00020751145521},
|
||||
// {95, 1.00128249791913},
|
||||
// {100, 1.0025246862876},
|
||||
// {105, 1.01020841898173},
|
||||
// {110, 1.00848854034523},
|
||||
// {115, 1.00896686906428},
|
||||
// {120, 1.04794644679831},
|
||||
// {125, 1.01523894946},
|
||||
// {130, 1.03214558479698},
|
||||
// {135, 1.02223637810346},
|
||||
// {140, 1.02095852249947},
|
||||
// {145, 1.03452569295212},
|
||||
// {150, 1.03344468755321},
|
||||
// {155, 1.02978238847957},
|
||||
// {160, 1.03050853971874},
|
||||
// {165, 1.0362899703462},
|
||||
// {170, 1.02896213350023},
|
||||
// {175, 1.03246206505197},
|
||||
// {180, 1.03511815797411},
|
||||
// {185, 1.0386550768334},
|
||||
// {0, 1},
|
||||
// {25, 1.00715513834484},
|
||||
// {35, 1.12484607155925},
|
||||
// {40, 1.13743718719145},
|
||||
// {45, 1.13506399305814},
|
||||
// {50, 1.13067636137849},
|
||||
// {55, 1.11648433361902},
|
||||
// {60, 1.08544627050144},
|
||||
// {65, 1.08660293694492},
|
||||
// {70, 1.08001421226446},
|
||||
// {75, 1.06027464588806},
|
||||
// {80, 1.05704474661452},
|
||||
// {85, 1.0483519592037},
|
||||
// {90, 1.03590936413276},
|
||||
// {95, 1.01755407120932},
|
||||
// {100, 0.997970532804681},
|
||||
// {105, 1.0022625340138},
|
||||
// {110, 1.00477823648416},
|
||||
// {115, 1.01527755445145},
|
||||
// {120, 1.01340733480523},
|
||||
// {125, 1.01488197269303},
|
||||
// {130, 1.01527719047251},
|
||||
// {135, 1.01613530209391},
|
||||
// {140, 1.01503246127647},
|
||||
// {145, 1.00589573878646},
|
||||
// {150, 0.99704724078137},
|
||||
// {155, 0.989621222331136},
|
||||
// {160, 0.997298663304549},
|
||||
// {165, 1.00001826143415},
|
||||
// {170, 0.994369457141502},
|
||||
// {175, 0.997960941911383},
|
||||
// {180, 1.00465186375123},
|
||||
// {185, 1.00123672344689},
|
||||
{0, 1},
|
||||
{25, 1.00715513834484},
|
||||
{35, 1.12484607155925},
|
||||
{40, 1.13743718719145},
|
||||
{45, 1.13506399305814},
|
||||
{50, 1.13067636137849},
|
||||
{55, 1.11648433361902},
|
||||
{60, 1.08544627050144},
|
||||
{65, 1.08660293694492},
|
||||
{70, 1.08001421226446},
|
||||
{75, 1.06027464588806},
|
||||
{80, 1.05704474661452},
|
||||
{85, 1.0483519592037},
|
||||
{90, 1.03590936413276},
|
||||
{95, 1.01755407120932},
|
||||
{100, 0.998508196505047},
|
||||
{105, 1.0022625340138},
|
||||
{110, 1.00477823648416},
|
||||
{115, 1.01527755445145},
|
||||
{120, 1.01340733480523},
|
||||
{125, 1.01488197269303},
|
||||
{130, 1.01527719047251},
|
||||
{135, 1.01613530209391},
|
||||
{140, 1.01503246127647},
|
||||
{145, 1.00589573878646},
|
||||
{150, 0.99704724078137},
|
||||
{155, 0.99429110718977},
|
||||
{160, 0.997298663304549},
|
||||
{165, 1.00001826143415},
|
||||
{170, 0.994369457141502},
|
||||
{175, 0.997960941911383},
|
||||
{180, 1.00465186375123},
|
||||
{185, 1.00123672344689},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -82,11 +156,11 @@ const LookupEntry lookupTopSide[] = {
|
||||
|
||||
const LookupEntry noScaling[]{
|
||||
|
||||
{100, 1.4},
|
||||
{0, 1},
|
||||
|
||||
{423, 5342},
|
||||
{100, 1},
|
||||
|
||||
{423, 532}
|
||||
{200, 1}
|
||||
|
||||
};
|
||||
|
||||
@ -109,7 +183,7 @@ public:
|
||||
{
|
||||
return N;
|
||||
}
|
||||
float interpolate(float x, float x0, float x1, float y0, float y1);
|
||||
float static interpolate(float x, float x0, float x1, float y0, float y1);
|
||||
uint8_t tableSize;
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user