From 3f4a8718aa24b7e4ff517d0f2c8d80f5b40e28fc Mon Sep 17 00:00:00 2001 From: TaaraLabs Date: Sun, 4 Apr 2021 19:16:14 +0300 Subject: [PATCH] Added support for P-Channel Mosfets Added link to the working PID library archive since the original library has changed and does not work anymore --- .../sources/SolderingStation2_u8glib_v1.7.ino | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/software/original/sources/SolderingStation2_u8glib_v1.7.ino b/software/original/sources/SolderingStation2_u8glib_v1.7.ino index 318b51a..12ff025 100644 --- a/software/original/sources/SolderingStation2_u8glib_v1.7.ino +++ b/software/original/sources/SolderingStation2_u8glib_v1.7.ino @@ -17,6 +17,7 @@ // - Calibrating and managing different soldering tips // - Storing user settings into the EEPROM // - Tip change detection +// - Can be used with either N or P channel mosfets // // Power supply should be in the range of 16V/2A to 24V/3A and well // stabilized. @@ -39,7 +40,7 @@ // Libraries #include // https://github.com/olikraus/u8glib -#include // https://github.com/mblythe86/C-PID-Library/tree/master/PID_v1 +#include // https://github.com/wagiminator/ATmega-Soldering-Station/blob/master/software/libraries/Arduino-PID-Library.zip (old cpp version of https://github.com/mblythe86/C-PID-Library/tree/master/PID_v1) #include // for storing user settings into EEPROM #include // for sleeping during ADC sampling @@ -91,6 +92,18 @@ // EEPROM identifier #define EEPROM_IDENT 0xE76C // to identify if EEPROM was written by this program +// Mosfet selection and control definitions +#define P_MOSFET false // false for N-Channel sosfet and true for P-Channel mosfet +#ifdef P_MOSFET // P-Channel mosfet +#define HEATER_ON 255 +#define HEATER_OFF 0 +#define HEATER_PWM 255 - Output +#elif // N-Channel mosfet +#define HEATER_ON 0 +#define HEATER_OFF 255 +#define HEATER_PWM Output +#endif + // Define the aggressive and conservative PID tuning parameters double aggKp=11, aggKi=0.5, aggKd=1; double consKp=11, consKi=3, consKd=5; @@ -186,7 +199,7 @@ void setup() { pinMode(BUTTON_PIN, INPUT_PULLUP); pinMode(SWITCH_PIN, INPUT_PULLUP); - analogWrite(CONTROL_PIN, 255); // this shuts off the heater + analogWrite(CONTROL_PIN, HEATER_OFF); // this shuts off the heater digitalWrite(BUZZER_PIN, LOW); // must be LOW when buzzer not in use // setup ADC @@ -218,7 +231,7 @@ void setup() { calculateTemp(); // turn on heater if iron temperature is well below setpoint - if ((CurrentTemp + 20) < DefaultTemp) analogWrite(CONTROL_PIN, 0); + if ((CurrentTemp + 20) < DefaultTemp) analogWrite(CONTROL_PIN, HEATER_ON); // set PID output range and start the PID ctrl.SetOutputLimits(0, 255); @@ -284,7 +297,7 @@ void SLEEPCheck() { if (handleMoved) { // if handle was moved if (inSleepMode) { // in sleep or off mode? if ((CurrentTemp + 20) < SetTemp) // if temp is well below setpoint - analogWrite(CONTROL_PIN, 0); // then start the heater right now + analogWrite(CONTROL_PIN, HEATER_ON); // then start the heater right now beep(); // beep on wake-up beepIfWorky = true; // beep again when working temperature is reached } @@ -303,7 +316,7 @@ void SLEEPCheck() { // reads temperature, vibration switch and supply voltages void SENSORCheck() { - analogWrite(CONTROL_PIN, 255); // shut off heater in order to measure temperature + analogWrite(CONTROL_PIN, HEATER_OFF); // shut off heater in order to measure temperature delayMicroseconds(TIME2SETTLE); // wait for voltage to settle double temp = denoiseAnalog(SENSOR_PIN); // read ADC value for temperature @@ -311,7 +324,7 @@ void SENSORCheck() { if (d != d0) {handleMoved = true; d0 = d;} // set flag if handle was moved if (! SensorCounter--) Vin = getVIN(); // get Vin every now and then - analogWrite(CONTROL_PIN, Output); // turn on again heater + analogWrite(CONTROL_PIN, HEATER_PWM); // turn on again heater RawTemp += (temp - RawTemp) * SMOOTHIE; // stabilize ADC temperature reading calculateTemp(); // calculate real temperature value @@ -332,7 +345,7 @@ void SENSORCheck() { // checks if tip is present or currently inserted if (ShowTemp > 500) TipIsPresent = false; // tip removed ? if (!TipIsPresent && (ShowTemp < 500)) { // new tip inserted ? - analogWrite(CONTROL_PIN, 255); // shut off heater + analogWrite(CONTROL_PIN, HEATER_OFF); // shut off heater beep(); // beep for info TipIsPresent = true; // tip is present now ChangeTipScreen(); // show tip selection screen @@ -372,7 +385,7 @@ void Thermostat() { // turn on heater if current temperature is below setpoint if ((CurrentTemp + 0.5) < Setpoint) Output = 0; else Output = 255; } - analogWrite(CONTROL_PIN, Output); // set heater PWM + analogWrite(CONTROL_PIN, HEATER_PWM); // set heater PWM } @@ -512,7 +525,7 @@ void MainScreen() { // setup screen void SetupScreen() { - analogWrite(CONTROL_PIN, 255); // shut off heater + analogWrite(CONTROL_PIN, HEATER_OFF); // shut off heater beep(); uint16_t SaveSetTemp = SetTemp; uint8_t selection = 0; @@ -761,7 +774,7 @@ void CalibrationScreen() { beep(); delay (10); } - analogWrite(CONTROL_PIN, 255); // shut off heater + analogWrite(CONTROL_PIN, HEATER_OFF); // shut off heater delayMicroseconds(TIME2SETTLE); // wait for voltage to settle CalTempNew[3] = getChipTemp(); // read chip temperature if ((CalTempNew[0] + 10 < CalTempNew[1]) && (CalTempNew[1] + 10 < CalTempNew[2])) {