mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Redeuce delay in readings and make it restore timer so we now have awesome performance
This commit is contained in:
@@ -14,5 +14,5 @@
|
|||||||
extern volatile uint16_t ADC1ConvertedValue[2];
|
extern volatile uint16_t ADC1ConvertedValue[2];
|
||||||
|
|
||||||
uint16_t Get_ADC1Value(uint8_t i);
|
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_ */
|
#endif /* ANALOG_H_ */
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ u32 Get_HeatingTime(void);
|
|||||||
void Set_HeatingTime(u32 heating_time);
|
void Set_HeatingTime(u32 heating_time);
|
||||||
u16 Get_AdcValue(u8 i);
|
u16 Get_AdcValue(u8 i);
|
||||||
void Init_Gtime(void);
|
void Init_Gtime(void);
|
||||||
void Delay_Ms(u32 ms);
|
|
||||||
void Delay_HalfMs(u32 ms);
|
|
||||||
void USB_Port(u8 state);
|
void USB_Port(u8 state);
|
||||||
void NVIC_Config(u16 tab_offset);
|
void NVIC_Config(u16 tab_offset);
|
||||||
void RCC_Config(void);
|
void RCC_Config(void);
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ int16_t readTipTemp() {
|
|||||||
uint32_t ad_sum = 0;
|
uint32_t ad_sum = 0;
|
||||||
uint32_t max = 0, min;
|
uint32_t max = 0, min;
|
||||||
uint32_t ad_value, avg_data;
|
uint32_t ad_value, avg_data;
|
||||||
|
uint32_t timer = getIronTimer();
|
||||||
setIronTimer(0); //set the remaining time to zero
|
setIronTimer(0); //set the remaining time to zero
|
||||||
HEAT_OFF(); //heater must be off
|
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
|
uint8_t gMeas_cnt = 9; //how many measurements to make
|
||||||
max = ad_sum = min = Get_ADC1Value(0);
|
max = ad_sum = min = Get_ADC1Value(0);
|
||||||
|
|
||||||
@@ -48,6 +48,7 @@ int16_t readTipTemp() {
|
|||||||
|
|
||||||
gMeas_cnt--;
|
gMeas_cnt--;
|
||||||
}
|
}
|
||||||
|
setIronTimer(timer);
|
||||||
ad_sum = ad_sum - max - min; //remove the two outliers
|
ad_sum = ad_sum - max - min; //remove the two outliers
|
||||||
avg_data = ad_sum / 8; //take the average
|
avg_data = ad_sum / 8; //take the average
|
||||||
rollingAverage[rIndex] = avg_data;
|
rollingAverage[rIndex] = avg_data;
|
||||||
@@ -101,16 +102,17 @@ uint16_t Get_ADC1Value(uint8_t i) {
|
|||||||
return ADC1ConvertedValue[i];
|
return ADC1ConvertedValue[i];
|
||||||
}
|
}
|
||||||
//This returns the calibrated temperature reading of the iron temp
|
//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 calTemp = 0;
|
||||||
static uint16_t lastVal = 0;
|
static uint16_t lastVal = 0;
|
||||||
static uint32_t lastUpdate = 0;
|
|
||||||
if (calibration_temp != 0)
|
if (calibration_temp != 0)
|
||||||
calTemp = calibration_temp;
|
calTemp = calibration_temp;
|
||||||
if (millis() - lastUpdate > 50) {
|
|
||||||
|
if (read) {
|
||||||
lastVal = (readTipTemp() * 1000 + 806 * readSensorTemp()
|
lastVal = (readTipTemp() * 1000 + 806 * readSensorTemp()
|
||||||
- calTemp * 1000) / 806;
|
- calTemp * 1000) / 806;
|
||||||
lastUpdate = millis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastVal;
|
return lastVal;
|
||||||
|
|||||||
@@ -35,10 +35,10 @@ int main(void) {
|
|||||||
|
|
||||||
Init_Oled(); //init the OLED display
|
Init_Oled(); //init the OLED display
|
||||||
Clear_Screen(); //clear the display buffer to black
|
Clear_Screen(); //clear the display buffer to black
|
||||||
systemSettings.SleepTemp = 1000;
|
systemSettings.SleepTemp = 900;
|
||||||
systemSettings.SleepTime = 1;
|
systemSettings.SleepTime = 1;
|
||||||
systemSettings.SolderingTemp = 1200;
|
systemSettings.SolderingTemp = 1500;
|
||||||
readIronTemp(239); //load the default calibration value
|
readIronTemp(239,0); //load the default calibration value
|
||||||
setupPID(); //init the PID values
|
setupPID(); //init the PID values
|
||||||
//OLED_DrawString("TEST012",7);
|
//OLED_DrawString("TEST012",7);
|
||||||
|
|
||||||
@@ -52,6 +52,7 @@ int main(void) {
|
|||||||
// Clear_Watchdog(); //reset the Watchdog
|
// Clear_Watchdog(); //reset the Watchdog
|
||||||
ProcessUI();
|
ProcessUI();
|
||||||
DrawUI();
|
DrawUI();
|
||||||
|
delayMs(50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/******************************** END OF FILE *********************************/
|
/******************************** END OF FILE *********************************/
|
||||||
|
|||||||
@@ -158,20 +158,23 @@ void DrawUI() {
|
|||||||
break;
|
break;
|
||||||
case SOLDERING:
|
case SOLDERING:
|
||||||
//The user is 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);
|
OLED_DrawChar('C', 14 * 4);
|
||||||
} else {
|
} else {
|
||||||
if (systemSettings.SolderingTemp - readIronTemp(0) < 20) {
|
if (systemSettings.SolderingTemp - temp < 20) {
|
||||||
OLED_DrawChar(' ', 14 * 4);
|
OLED_DrawChar(' ', 14 * 4);
|
||||||
} else { //we are heating
|
} else { //we are heating
|
||||||
OLED_DrawChar('H', 14 * 4);
|
OLED_DrawChar('H', 14 * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
OLED_DrawThreeNumber(readIronTemp(0) / 10, 0);
|
OLED_DrawThreeNumber(temp / 10, 0);
|
||||||
OLED_DrawChar('C', 14 * 3);
|
OLED_DrawChar('C', 14 * 3);
|
||||||
OLED_DrawChar(' ', 14 * 4);
|
OLED_DrawChar(' ', 14 * 4);
|
||||||
OLED_DrawChar(' ', 14 * 5);
|
OLED_DrawChar(' ', 14 * 5);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case TEMP_ADJ:
|
case TEMP_ADJ:
|
||||||
//We are prompting the user to change the temp so we draw the current setpoint temp
|
//We are prompting the user to change the temp so we draw the current setpoint temp
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ int32_t computePID(uint16_t setpoint) {
|
|||||||
static uint32_t lastSample = 0;
|
static uint32_t lastSample = 0;
|
||||||
int32_t ITerm = 0;
|
int32_t ITerm = 0;
|
||||||
static int16_t lastReading = 0;
|
static int16_t lastReading = 0;
|
||||||
if (millis() - lastSample > 50) {
|
if (millis() - lastSample > 25) {
|
||||||
//only sample every 50 milliseconds
|
//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
|
int16_t error = (int16_t)setpoint - (int16_t)currentReading; //calculate the error term
|
||||||
ITerm += (pidSettings.ki * error);
|
ITerm += (pidSettings.ki * error);
|
||||||
if (ITerm > MAXPIDOUTPUT)
|
if (ITerm > MAXPIDOUTPUT)
|
||||||
|
|||||||
Reference in New Issue
Block a user