aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBen V. Brown <[email protected]>2017-05-18 19:51:47 +1000
committerBen V. Brown <[email protected]>2017-05-18 19:51:47 +1000
commitebfe457f65d9a877ad3b7abd324f305de75d71c9 (patch)
tree84aa1441b76f35987e2eaa964a1c304f59676895
parent8c73aa0de4a5c7bf453773259c66c6f6814c8025 (diff)
downloadIronOS-ebfe457f65d9a877ad3b7abd324f305de75d71c9.tar.gz
IronOS-ebfe457f65d9a877ad3b7abd324f305de75d71c9.zip
Add Temperature calibration, improve temp accuracy
-rw-r--r--workspace/ts100/inc/Analog.h2
-rw-r--r--workspace/ts100/inc/Modes.h1
-rw-r--r--workspace/ts100/src/Analog.c22
-rw-r--r--workspace/ts100/src/Main.c10
-rw-r--r--workspace/ts100/src/Modes.c50
-rw-r--r--workspace/ts100/src/Oled.c6
-rw-r--r--workspace/ts100/src/PID.c4
7 files changed, 75 insertions, 20 deletions
diff --git a/workspace/ts100/inc/Analog.h b/workspace/ts100/inc/Analog.h
index d4bae0d8..f36a0310 100644
--- a/workspace/ts100/inc/Analog.h
+++ b/workspace/ts100/inc/Analog.h
@@ -15,6 +15,6 @@
extern volatile uint16_t ADC1ConvertedValue[2];
uint16_t Get_ADC1Value(uint8_t i);
-uint16_t readIronTemp(uint16_t calibration,uint8_t read);//read the iron temp in C X10
+uint16_t readIronTemp(uint16_t calibration_temp, uint8_t read,uint16_t setPointTemp); //read the iron temp in C X10
uint16_t readDCVoltage();/*Get the system voltage X10*/
#endif /* ANALOG_H_ */
diff --git a/workspace/ts100/inc/Modes.h b/workspace/ts100/inc/Modes.h
index bcfb4624..7c91d49d 100644
--- a/workspace/ts100/inc/Modes.h
+++ b/workspace/ts100/inc/Modes.h
@@ -26,6 +26,7 @@ enum {
UVLOWARN,
THERMOMETER,
DCINDISP,
+ TEMPCAL,
} operatingMode;
enum {
diff --git a/workspace/ts100/src/Analog.c b/workspace/ts100/src/Analog.c
index 591d3e96..4d071162 100644
--- a/workspace/ts100/src/Analog.c
+++ b/workspace/ts100/src/Analog.c
@@ -105,16 +105,30 @@ uint16_t Get_ADC1Value(uint8_t i) {
}
//This returns the calibrated temperature reading of the iron temp
//inputs : calibration value / wether to take a new reading or not
-uint16_t readIronTemp(uint16_t calibration_temp, uint8_t read) {
+uint16_t readIronTemp(uint16_t calibration_temp, uint8_t read,
+ uint16_t setPointTemp) {
static uint16_t calTemp = 0;
static uint16_t lastVal = 0;
-
+ static uint16_t lastSetTemp;
+ if(setPointTemp!=0xFFFF)
+ lastSetTemp = setPointTemp;
if (calibration_temp != 0)
calTemp = calibration_temp;
if (read) {
- lastVal = (readTipTemp() * 1000 + 806 * readSensorTemp()
- - calTemp * 1000) / 806;
+ int16_t compensation = 80 + 150 * (lastSetTemp - 1000) / 3000;
+ int16_t tipTemp = readTipTemp();
+ int16_t ColdJTemp = readSensorTemp();
+ if (lastSetTemp == 1000)
+ compensation -= 10;
+
+ if (lastSetTemp != 0) {
+ if (tipTemp > (compensation + calTemp))
+ tipTemp -= compensation;
+ }
+ if (ColdJTemp > 400)
+ ColdJTemp = 400;
+ lastVal = (tipTemp * 1000 + 807 * ColdJTemp - calTemp * 1000) / 807;
}
diff --git a/workspace/ts100/src/Main.c b/workspace/ts100/src/Main.c
index d32ed3b3..5c8e29b2 100644
--- a/workspace/ts100/src/Main.c
+++ b/workspace/ts100/src/Main.c
@@ -24,18 +24,18 @@ void setup() {
RCC_Config(); //setup system clock
NVIC_Config(0x4000); //this shifts the NVIC table to be offset, for the usb bootloader's size
GPIO_Config(); //setup all the GPIO pins
- Init_EXTI(); //init the EXTI inputs
+ Init_EXTI(); //Init the EXTI inputs
Init_Timer3(); //Used for the soldering iron tip
- Adc_Init(); //init adc and dma
+ Adc_Init(); //Init adc and DMA
I2C_Configuration(); //Start the I2C hardware
GPIO_Init_OLED(); //Init the GPIO ports for the OLED
restoreSettings(); //Load settings
StartUp_Accelerometer(systemSettings.sensitivity); //start the accelerometer
- setupPID(); //init the PID values
- readIronTemp(239, 0); //load the default calibration value
- Init_Oled(systemSettings.flipDisplay); //init the OLED display
+ setupPID(); //Init the PID values
+ readIronTemp(systemSettings.tempCalibration, 0,0); //load the default calibration value
+ Init_Oled(systemSettings.flipDisplay); //Init the OLED display
OLED_DrawString("VER 1.03", 8); //1.settings version as of current
delayMs(800); //Pause to show version number
diff --git a/workspace/ts100/src/Modes.c b/workspace/ts100/src/Modes.c
index 6fc463fc..a925a131 100644
--- a/workspace/ts100/src/Modes.c
+++ b/workspace/ts100/src/Modes.c
@@ -5,6 +5,7 @@
* Author: Ralim <[email protected]>
*/
#include "Modes.h"
+uint8_t tempCalStatus = 0;
//This does the required processing and state changes
void ProcessUI() {
uint8_t Buttons = getButtons(); //read the buttons status
@@ -158,7 +159,7 @@ void ProcessUI() {
case COOLING: {
setIronTimer(0); //turn off heating
//This mode warns the user the iron is still cooling down
- uint16_t temp = readIronTemp(0, 1); //take a new reading as the heater code is not taking new readings
+ uint16_t temp = readIronTemp(0, 1, 0xFFFF); //take a new reading as the heater code is not taking new readings
if (temp < 400) { //if the temp is < 40C then we can go back to IDLE
operatingMode = STARTUP;
} else if (Buttons & (BUT_A | BUT_B)) { //we check if the user has pushed a button to ack
@@ -177,9 +178,12 @@ void ProcessUI() {
case THERMOMETER: {
//This lets the user check the tip temp without heating the iron.. And eventually calibration will be added here
- if ((Buttons == BUT_A) | (Buttons == BUT_B)) {
+ if (Buttons == BUT_A) {
//Single button press, cycle over to the DC display
operatingMode = DCINDISP;
+ } else if (Buttons == BUT_B) {
+ tempCalStatus = 0;
+ operatingMode = TEMPCAL;
} else if (Buttons == (BUT_A | BUT_B)) {
//If the user is holding both button, exit the screen
operatingMode = STARTUP;
@@ -190,7 +194,7 @@ void ProcessUI() {
case DCINDISP: {
//This lets the user check the input voltage
- if ((Buttons == BUT_A) | (Buttons == BUT_B)) {
+ if (Buttons == BUT_A) {
//Single button press, cycle over to the temp display
operatingMode = THERMOMETER;
} else if (Buttons == (BUT_A | BUT_B)) {
@@ -200,6 +204,28 @@ void ProcessUI() {
}
break;
+ case TEMPCAL: {
+ if (Buttons == BUT_B) {
+ //Single button press, cycle over to the DC IN
+ operatingMode = THERMOMETER;
+ } else if (Buttons == BUT_A) {
+ //Try and calibrate
+ if (tempCalStatus == 0) {
+ if (readTipTemp() < 300 && readSensorTemp() < 300) {
+ tempCalStatus = 1;
+ systemSettings.tempCalibration = readTipTemp();
+ saveSettings();
+ } else {
+ tempCalStatus = 2;
+ }
+ }
+ } else if (Buttons == (BUT_A | BUT_B)) {
+ //If the user is holding both button, exit the screen
+ operatingMode = STARTUP;
+ }
+
+ }
+ break;
default:
break;
}
@@ -210,6 +236,8 @@ void ProcessUI() {
void drawTemp(uint16_t temp, uint8_t x) {
if (systemSettings.displayTempInF)
temp = (temp * 9 + 1600) / 5;/*Convert to F -> T*(9/5)+32*/
+ if (temp % 10 > 5)
+ temp += 10;//round up
OLED_DrawThreeNumber(temp / 10, x);
}
@@ -217,7 +245,7 @@ void drawTemp(uint16_t temp, uint8_t x) {
* Performs all the OLED drawing for the current operating mode
*/
void DrawUI() {
- uint16_t temp = readIronTemp(0, 0);
+ uint16_t temp = readIronTemp(0, 0, 0xFFFF);
switch (operatingMode) {
case STARTUP:
//We are chilling in the idle mode
@@ -336,7 +364,7 @@ void DrawUI() {
OLED_DrawString("LOW VOLT", 8);
break;
case THERMOMETER:
- temp = readIronTemp(0, 1); //Force a reading as heater is off
+ temp = readIronTemp(0, 1, 0xFFFF); //Force a reading as heater is off
OLED_DrawString("TEMP ", 5);//extra one to it clears the leftover 'L' from IDLE
drawTemp(temp, 5);
break;
@@ -354,6 +382,18 @@ void DrawUI() {
}
break;
+ case TEMPCAL: {
+
+ if (tempCalStatus == 0) {
+ OLED_DrawString("CAL TEMP", 8);
+ } else if (tempCalStatus == 1) {
+ OLED_DrawString("CAL OK ", 8);
+ } else if (tempCalStatus == 2) {
+ OLED_DrawString("CAL FAIL", 8);
+ }
+ }
+
+ break;
default:
break;
}
diff --git a/workspace/ts100/src/Oled.c b/workspace/ts100/src/Oled.c
index ba7c6023..306c4170 100644
--- a/workspace/ts100/src/Oled.c
+++ b/workspace/ts100/src/Oled.c
@@ -19,7 +19,7 @@ int8_t displayOffset = 32;
/*All commands are prefixed with 0x80*/
u8 OLED_Setup_Array[46] = { 0x80, 0xAE,/*Display off*/
0x80, 0xD5,/*Set display clock divide ratio / osc freq*/
-0x80, 0x52,/**/
+0x80, 0x52,/*Unknown*/
0x80, 0xA8,/*Set Multiplex Ratio*/
0x80, 0x0F, /*16 == max brightness,39==dimmest*/
0x80, 0xC0,/*Set COM Scan direction*/
@@ -28,7 +28,7 @@ u8 OLED_Setup_Array[46] = { 0x80, 0xAE,/*Display off*/
0x80, 0x40,/*Set Display start line to 0*/
0x80, 0xA0,/*Set Segment remap to normal*/
0x80, 0x8D,/*Unknown*/
-0x80, 0x14,/**/
+0x80, 0x14,/*Unknown*/
0x80, 0xDA,/*Set VCOM Pins hardware config*/
0x80, 0x02,/*Combination 2*/
0x80, 0x81,/*Contrast*/
@@ -36,7 +36,7 @@ u8 OLED_Setup_Array[46] = { 0x80, 0xAE,/*Display off*/
0x80, 0xD9,/*Set pre-charge period*/
0x80, 0xF1,/**/
0x80, 0xDB,/*Adjust VCOMH regulator ouput*/
-0x80, 0x30,/**/
+0x80, 0x30,/*Unknown*/
0x80, 0xA4,/*Enable the display GDDR*/
0x80, 0XA6,/*Normal display*/
0x80, 0xAF /*Dispaly on*/
diff --git a/workspace/ts100/src/PID.c b/workspace/ts100/src/PID.c
index b086f0ea..fb63a8b0 100644
--- a/workspace/ts100/src/PID.c
+++ b/workspace/ts100/src/PID.c
@@ -12,7 +12,7 @@
int32_t computePID(uint16_t setpoint) {
int32_t ITerm = 0;
static int16_t lastReading = 0;
- uint16_t currentReading = readIronTemp(0, 1); //get the current temp of the iron
+ uint16_t currentReading = readIronTemp(0, 1,setpoint); //get the current temp of the iron
int16_t error = (int16_t) setpoint - (int16_t) currentReading; //calculate the error term
ITerm += (pidSettings.ki * error);
if (ITerm > MAXPIDOUTPUT)
@@ -34,7 +34,7 @@ int32_t computePID(uint16_t setpoint) {
}
/*Sets up the pid values*/
void setupPID(void) {
- pidSettings.kp = 22;
+ pidSettings.kp = 25;
pidSettings.ki = 7;
pidSettings.kd = 2;