mirror of
https://github.com/arwidcool/Solder-Plate.git
synced 2024-11-12 01:10:52 +01:00
refactor reflow on millis for better resolution + fix led + pinleds +
This commit is contained in:
parent
7d6fe95ff9
commit
86f1f8ac73
@ -37,7 +37,7 @@ void PidController::loop()
|
||||
{
|
||||
data->targetTemp = chosenReflowProfile.getTargetTemp();
|
||||
data->currentTemp = thermistor1.getTemperature();
|
||||
debug();
|
||||
// debug();
|
||||
compute();
|
||||
analogWrite(MOSTFET_PIN, data->setPoint);
|
||||
}
|
||||
|
@ -67,6 +67,11 @@ void OledDisplay::handleButtonStateChange(Pair<ButtonKind, StateChangeEvent<Butt
|
||||
curMenu->goNextItem();
|
||||
}
|
||||
}
|
||||
} else if (state == DONE) {
|
||||
// GO back to iniital state
|
||||
if (change.second.to == ButtonState::PRESSED) {
|
||||
reflowProcessState.set(USER_INPUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,13 +179,30 @@ void OledDisplay::loop()
|
||||
{
|
||||
|
||||
ReflowProcessState state = reflowProcessState.get();
|
||||
if (state == USER_INPUT)
|
||||
if (state == ReflowProcessState::USER_INPUT)
|
||||
{
|
||||
handleUserInputState();
|
||||
}
|
||||
else if (state >= PREHEAT && state <= DONE)
|
||||
else if (state >= ReflowProcessState::PREHEAT && state < ReflowProcessState::DONE)
|
||||
{
|
||||
handleReflowState();
|
||||
} else if (state == ReflowProcessState::DONE) {
|
||||
// Traverse back to root menu
|
||||
while (curMenu->parent != NULL) {
|
||||
curMenu = curMenu->parent;
|
||||
}
|
||||
display.clearDisplay();
|
||||
display.setRotation(0);
|
||||
display.setTextSize(2);
|
||||
drawPositionedText("DONE :)", DisplayTextAlignment::CENTER, DisplayTextAlignment::START);
|
||||
uint8_t curTemp = thermistor1.getTemperature();
|
||||
display.setTextSize(1,2);
|
||||
drawPositionedText("Temperature", DisplayTextAlignment::START, DisplayTextAlignment::CENTER);
|
||||
drawPositionedText((String(curTemp)+" C").c_str(), DisplayTextAlignment::END, DisplayTextAlignment::CENTER);
|
||||
|
||||
display.display();
|
||||
|
||||
// This is not super efficient but it's fine for now
|
||||
}
|
||||
// Loop implementation
|
||||
}
|
||||
@ -215,7 +237,7 @@ void OledDisplay::displayIndicators()
|
||||
display.setCursor(SCREEN_HEIGHT - 14, SCREEN_WIDTH / 2 - 5);
|
||||
display.print(">");
|
||||
}
|
||||
void OledDisplay::centerText(const char *txt, DisplayTextAlignment horizontal, DisplayTextAlignment vertical)
|
||||
void OledDisplay::drawPositionedText(const char *txt, DisplayTextAlignment horizontal, DisplayTextAlignment vertical)
|
||||
{
|
||||
int16_t x1, y1;
|
||||
uint16_t w, h;
|
||||
@ -273,23 +295,29 @@ void OledDisplay::handleReflowState()
|
||||
display.setCursor(0, 0);
|
||||
display.setTextSize(2);
|
||||
ReflowProcessState state = reflowProcessState.get();
|
||||
centerText(STATE_STR(state), DisplayTextAlignment::CENTER, DisplayTextAlignment::START);
|
||||
|
||||
// Title topleft
|
||||
drawPositionedText(STATE_STR(state), DisplayTextAlignment::CENTER, DisplayTextAlignment::START);
|
||||
|
||||
display.setTextSize(1, 2);
|
||||
// SysV topright
|
||||
#ifdef DEBUG
|
||||
drawPositionedText((String(analogRef.calculateInputVoltage())+"V").c_str(), DisplayTextAlignment::END, DisplayTextAlignment::START);
|
||||
#endif
|
||||
|
||||
|
||||
// Remaining time center left + bottom left
|
||||
uint32_t elapsedStep = chosenReflowProfile.getCurrentStepRelativeTime();
|
||||
centerText("Remaining", DisplayTextAlignment::START, DisplayTextAlignment::CENTER);
|
||||
centerText((String(chosenReflowProfile.curReflowStep().duration - elapsedStep) + "s").c_str(), DisplayTextAlignment::START, DisplayTextAlignment::END);
|
||||
drawPositionedText("Remaining", DisplayTextAlignment::START, DisplayTextAlignment::CENTER);
|
||||
drawPositionedText((String(chosenReflowProfile.curReflowStep().duration - elapsedStep) + "s").c_str(), DisplayTextAlignment::START, DisplayTextAlignment::END);
|
||||
|
||||
// Current temp center right + bottom right
|
||||
uint8_t curTemp = thermistor1.getTemperature();
|
||||
uint8_t targetTemp = pidControllerData.targetTemp;
|
||||
centerText(("Curr.: " + String(curTemp)).c_str(), DisplayTextAlignment::END, DisplayTextAlignment::CENTER);
|
||||
centerText(("Target: " + String(targetTemp)).c_str(), DisplayTextAlignment::END, DisplayTextAlignment::END);
|
||||
drawPositionedText(("Curr.: " + String(curTemp)).c_str(), DisplayTextAlignment::END, DisplayTextAlignment::CENTER);
|
||||
drawPositionedText(("Target: " + String(targetTemp)).c_str(), DisplayTextAlignment::END, DisplayTextAlignment::END);
|
||||
|
||||
display.setTextSize(1, 1);
|
||||
display.setCursor(15, 16);
|
||||
float systemVoltage = analogRef.calculateInputVoltage();
|
||||
display.println("In Voltage:"+String(systemVoltage));
|
||||
|
||||
// display.println("In Voltage:"+String(systemVoltage));
|
||||
|
||||
display.display();
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ class OledDisplay {
|
||||
void handleUserInputState();
|
||||
void handleReflowState();
|
||||
void centerText(const char * text) {
|
||||
centerText(text, DisplayTextAlignment::CENTER, DisplayTextAlignment::CENTER);
|
||||
drawPositionedText(text, DisplayTextAlignment::CENTER, DisplayTextAlignment::CENTER);
|
||||
}
|
||||
void centerText(const char * text, DisplayTextAlignment horizontal, DisplayTextAlignment vertical);
|
||||
void drawPositionedText(const char * text, DisplayTextAlignment horizontal, DisplayTextAlignment vertical);
|
||||
void displayIndicators();
|
||||
void handleDrawThermistorMenu(OledMenuItem item);
|
||||
};
|
||||
|
@ -51,7 +51,7 @@ Thermistor thermistors[6] = {thermistor1, thermistor2, thermistor3, thermistor4,
|
||||
|
||||
// These are the reflow profiles that you can choose from, you can add more if you want (up to 5) but you will have to change the nReflowProfiles variable to the number of profiles you have
|
||||
|
||||
int nReflowProfiles = 2;
|
||||
int nReflowProfiles = 3;
|
||||
|
||||
ReflowProfile reflowProfiles[] = {
|
||||
// 138c profile Sn42Bi58
|
||||
@ -70,6 +70,13 @@ ReflowProfile reflowProfiles[] = {
|
||||
ReflowStep(ReflowProcessState::COOL, 30, 183),
|
||||
ReflowStep(ReflowProcessState::DONE, 0, 0)},
|
||||
"183C Sn63 Pb37 \0"),
|
||||
ReflowProfile(new ReflowStep[5]{
|
||||
ReflowStep(ReflowProcessState::PREHEAT, 5, 150),
|
||||
ReflowStep(ReflowProcessState::SOAK, 5, 180),
|
||||
ReflowStep(ReflowProcessState::REFLOW, 5, 220, EASE_IN_OUT),
|
||||
ReflowStep(ReflowProcessState::COOL, 5, 183),
|
||||
ReflowStep(ReflowProcessState::DONE, 0, 0)},
|
||||
"debug profi \0"),
|
||||
|
||||
|
||||
};
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
// If you didnt solder the LEDS in order, change the order here just change the pin numbers till it matches your board
|
||||
#define LEFT_LED_PIN 20 //Should be RED
|
||||
#define MID_LED_PIN 18 //Should be YELLOW
|
||||
#define RIGHT_LED_PIN 19 //Should be GREEN
|
||||
#define MID_LED_PIN 19 //Should be YELLOW
|
||||
#define RIGHT_LED_PIN 18 //Should be GREEN
|
||||
#define GREEN_LED_PIN RIGHT_LED_PIN
|
||||
|
||||
|
||||
|
34
src/main.cpp
34
src/main.cpp
@ -41,10 +41,6 @@ OledDisplay oled = OledDisplay();
|
||||
|
||||
TemperatureController temperatureController ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
@ -62,7 +58,7 @@ void setup()
|
||||
oled.setup();
|
||||
eepromDataManager.setup();
|
||||
|
||||
reflowProcessState.set(USER_INPUT);
|
||||
reflowProcessState.set(ReflowProcessState::USER_INPUT);
|
||||
|
||||
temperatureController.checkPluggedInThermistors();
|
||||
}
|
||||
@ -74,19 +70,21 @@ void loop()
|
||||
ReflowProcessState state = reflowProcessState.get();
|
||||
if (k != NULL)
|
||||
{
|
||||
if (state == USER_INPUT)
|
||||
if (state == ReflowProcessState::USER_INPUT)
|
||||
{
|
||||
leds.handleButtonStateChange(*k);
|
||||
oled.handleButtonStateChange(*k);
|
||||
}
|
||||
else if (state >= PREHEAT && state <= COOL)
|
||||
else if (state >= ReflowProcessState::PREHEAT && state <= ReflowProcessState::COOL)
|
||||
{
|
||||
if (k->first == ButtonKind::BACK && k->second.to == ButtonState::PRESSED)
|
||||
{
|
||||
// STOP REFLOW and restart
|
||||
reflowProcessState.set(USER_INPUT);
|
||||
reflowProcessState.set(ReflowProcessState::USER_INPUT);
|
||||
pidController.stop();
|
||||
}
|
||||
} else if (state == ReflowProcessState::DONE) {
|
||||
oled.handleButtonStateChange(*k);
|
||||
}
|
||||
}
|
||||
ReflowProcessState newState = reflowProcessState.get();
|
||||
@ -94,7 +92,7 @@ void loop()
|
||||
if (newState != state) {
|
||||
Serial.println("State changed from " + String(STATE_STR(state)) + " to " + String(STATE_STR(newState)));
|
||||
// State changed from state to newState (user input or wifi input needs to be above here)
|
||||
if (newState == PREHEAT) {
|
||||
if (newState == ReflowProcessState::PREHEAT) {
|
||||
chosenReflowProfile.start();
|
||||
pidController.start();
|
||||
}
|
||||
@ -104,7 +102,7 @@ void loop()
|
||||
leds.loop();
|
||||
oled.loop();
|
||||
|
||||
if (state >= PREHEAT && state <= COOL)
|
||||
if (state >= ReflowProcessState::PREHEAT && state <= ReflowProcessState::COOL)
|
||||
{
|
||||
pidController.loop();
|
||||
ReflowStep step = chosenReflowProfile.curReflowStep();
|
||||
@ -112,20 +110,12 @@ void loop()
|
||||
if (step.state != newState)
|
||||
{
|
||||
reflowProcessState.set(step.state);
|
||||
if (step.state == ReflowProcessState::DONE)
|
||||
{
|
||||
pidController.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state == DONE)
|
||||
{
|
||||
// TODO: BUZZER
|
||||
pidController.stop();
|
||||
reflowProcessState.set(USER_INPUT);
|
||||
}
|
||||
|
||||
|
||||
// if (step.state == ReflowProcessState::DONE) {
|
||||
// profile.start();
|
||||
// return;
|
||||
// }
|
||||
// Serial.print(String(STATE_STR(step.state)) + " " + String(step.duration) + " " + String(step.targetTempAtEnd) + " " + String(profile.getTargetTemp())+"\r");
|
||||
}
|
||||
|
20
src/reflow.h
20
src/reflow.h
@ -97,7 +97,7 @@ public:
|
||||
|
||||
void start()
|
||||
{
|
||||
timer = StopWatch(StopWatch::Resolution::SECONDS);
|
||||
timer = StopWatch(StopWatch::Resolution::MILLIS);
|
||||
timer.start();
|
||||
calculateTimes();
|
||||
}
|
||||
@ -122,10 +122,10 @@ public:
|
||||
if (!timer.isRunning()) {
|
||||
return steps[0];
|
||||
}
|
||||
uint8_t elapsed = timer.elapsed();
|
||||
uint32_t elapsedMS = timer.elapsed();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
if (elapsed >= startTimes[i] && elapsed < endTimes[i])
|
||||
if (elapsedMS >= startTimes[i] *1000 && elapsedMS < endTimes[i] * 1000)
|
||||
{
|
||||
return steps[i];
|
||||
}
|
||||
@ -135,7 +135,7 @@ public:
|
||||
|
||||
float getTargetTemp()
|
||||
{
|
||||
uint32_t elapsedTime = timer.elapsed();
|
||||
uint32_t elapsedMS = timer.elapsed();
|
||||
uint8_t startTemp = 20; // always assume 20 degrees at the start
|
||||
|
||||
ReflowStep curStep = curReflowStep();
|
||||
@ -146,19 +146,19 @@ public:
|
||||
|
||||
// startTemp => 20 or the targetTempAtEnd of the previous step
|
||||
|
||||
uint16_t startTime = startTimes[STEPINDEX(curStep)];
|
||||
uint16_t startTimeMS = startTimes[STEPINDEX(curStep)] * 1000;
|
||||
|
||||
uint32_t relativeElapsedTime = elapsedTime - startTime;
|
||||
uint32_t relativeElapsedTime = elapsedMS - startTimeMS;
|
||||
|
||||
percentage = (float)relativeElapsedTime / (float)(curStep.duration);
|
||||
percentage = (float)relativeElapsedTime / (float)(curStep.duration * 1000);
|
||||
|
||||
return curStep.calcTempAtPercentage(startTemp, percentage);
|
||||
}
|
||||
|
||||
uint8_t getCurrentStepRelativeTime() {
|
||||
uint32_t elapsedTime = timer.elapsed();
|
||||
uint16_t startTime = startTimes[STEPINDEX(curReflowStep())];
|
||||
return elapsedTime - startTime;
|
||||
uint32_t elapsedMS = timer.elapsed();
|
||||
uint16_t startTimeMS = startTimes[STEPINDEX(curReflowStep())] * 1000;
|
||||
return (elapsedMS - startTimeMS) / 1000;
|
||||
}
|
||||
|
||||
void toBuffer(uint8_t *b)
|
||||
|
BIN
src/reflow.rar
BIN
src/reflow.rar
Binary file not shown.
BIN
src/reflow2.rar
BIN
src/reflow2.rar
Binary file not shown.
Loading…
Reference in New Issue
Block a user