From c98e4126b25d49a8fad3e7337137914f66eaeab8 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Thu, 29 Sep 2016 00:31:36 +1000 Subject: [PATCH] Redeuce delay in readings and make it restore timer so we now have awesome performance --- workspace/ts100/inc/Analog.h | 2 +- workspace/ts100/inc/Bios.h | 2 -- workspace/ts100/src/Analog.c | 14 ++++++++------ workspace/ts100/src/Main.c | 7 ++++--- workspace/ts100/src/Modes.c | 9 ++++++--- workspace/ts100/src/PID.c | 4 ++-- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/workspace/ts100/inc/Analog.h b/workspace/ts100/inc/Analog.h index 5fcff41e..92187269 100644 --- a/workspace/ts100/inc/Analog.h +++ b/workspace/ts100/inc/Analog.h @@ -14,5 +14,5 @@ extern volatile uint16_t ADC1ConvertedValue[2]; uint16_t Get_ADC1Value(uint8_t i); -uint16_t readIronTemp(uint16_t calibration); +uint16_t readIronTemp(uint16_t calibration,uint8_t read); #endif /* ANALOG_H_ */ diff --git a/workspace/ts100/inc/Bios.h b/workspace/ts100/inc/Bios.h index cf6607d1..a2d0df67 100644 --- a/workspace/ts100/inc/Bios.h +++ b/workspace/ts100/inc/Bios.h @@ -38,8 +38,6 @@ u32 Get_HeatingTime(void); void Set_HeatingTime(u32 heating_time); u16 Get_AdcValue(u8 i); void Init_Gtime(void); -void Delay_Ms(u32 ms); -void Delay_HalfMs(u32 ms); void USB_Port(u8 state); void NVIC_Config(u16 tab_offset); void RCC_Config(void); diff --git a/workspace/ts100/src/Analog.c b/workspace/ts100/src/Analog.c index 38abae35..79d13d4c 100644 --- a/workspace/ts100/src/Analog.c +++ b/workspace/ts100/src/Analog.c @@ -31,10 +31,10 @@ int16_t readTipTemp() { uint32_t ad_sum = 0; uint32_t max = 0, min; uint32_t ad_value, avg_data; - + uint32_t timer = getIronTimer(); setIronTimer(0); //set the remaining time to zero HEAT_OFF(); //heater must be off - delayMs(50); //wait for the heater to time out + delayMs(5); //wait for the heater to time out uint8_t gMeas_cnt = 9; //how many measurements to make max = ad_sum = min = Get_ADC1Value(0); @@ -48,6 +48,7 @@ int16_t readTipTemp() { gMeas_cnt--; } + setIronTimer(timer); ad_sum = ad_sum - max - min; //remove the two outliers avg_data = ad_sum / 8; //take the average rollingAverage[rIndex] = avg_data; @@ -101,16 +102,17 @@ uint16_t Get_ADC1Value(uint8_t i) { return ADC1ConvertedValue[i]; } //This returns the calibrated temperature reading of the iron temp -uint16_t readIronTemp(uint16_t calibration_temp) { +uint16_t readIronTemp(uint16_t calibration_temp, uint8_t read) { static uint16_t calTemp = 0; static uint16_t lastVal = 0; - static uint32_t lastUpdate = 0; + if (calibration_temp != 0) calTemp = calibration_temp; - if (millis() - lastUpdate > 50) { + + if (read) { lastVal = (readTipTemp() * 1000 + 806 * readSensorTemp() - calTemp * 1000) / 806; - lastUpdate = millis(); + } return lastVal; diff --git a/workspace/ts100/src/Main.c b/workspace/ts100/src/Main.c index 7114ef7e..8b1ac5ab 100644 --- a/workspace/ts100/src/Main.c +++ b/workspace/ts100/src/Main.c @@ -35,10 +35,10 @@ int main(void) { Init_Oled(); //init the OLED display Clear_Screen(); //clear the display buffer to black - systemSettings.SleepTemp = 1000; + systemSettings.SleepTemp = 900; systemSettings.SleepTime = 1; - systemSettings.SolderingTemp = 1200; - readIronTemp(239); //load the default calibration value + systemSettings.SolderingTemp = 1500; + readIronTemp(239,0); //load the default calibration value setupPID(); //init the PID values //OLED_DrawString("TEST012",7); @@ -52,6 +52,7 @@ int main(void) { // Clear_Watchdog(); //reset the Watchdog ProcessUI(); DrawUI(); + delayMs(50); } } /******************************** END OF FILE *********************************/ diff --git a/workspace/ts100/src/Modes.c b/workspace/ts100/src/Modes.c index 5931bd7c..bd268eb4 100644 --- a/workspace/ts100/src/Modes.c +++ b/workspace/ts100/src/Modes.c @@ -158,20 +158,23 @@ void DrawUI() { break; case SOLDERING: //The user is soldering - if (systemSettings.SolderingTemp < readIronTemp(0)) { + { + uint16_t temp = readIronTemp(0, 0); + if (systemSettings.SolderingTemp < temp) { OLED_DrawChar('C', 14 * 4); } else { - if (systemSettings.SolderingTemp - readIronTemp(0) < 20) { + if (systemSettings.SolderingTemp - temp < 20) { OLED_DrawChar(' ', 14 * 4); } else { //we are heating OLED_DrawChar('H', 14 * 4); } } - OLED_DrawThreeNumber(readIronTemp(0) / 10, 0); + OLED_DrawThreeNumber(temp / 10, 0); OLED_DrawChar('C', 14 * 3); OLED_DrawChar(' ', 14 * 4); OLED_DrawChar(' ', 14 * 5); + } break; case TEMP_ADJ: //We are prompting the user to change the temp so we draw the current setpoint temp diff --git a/workspace/ts100/src/PID.c b/workspace/ts100/src/PID.c index b23ece6e..e31dbb24 100644 --- a/workspace/ts100/src/PID.c +++ b/workspace/ts100/src/PID.c @@ -13,9 +13,9 @@ int32_t computePID(uint16_t setpoint) { static uint32_t lastSample = 0; int32_t ITerm = 0; static int16_t lastReading = 0; - if (millis() - lastSample > 50) { + if (millis() - lastSample > 25) { //only sample every 50 milliseconds - uint16_t currentReading = readIronTemp(0); //get the current temp of the iron + uint16_t currentReading = readIronTemp(0,1); //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)