1
0
forked from me/IronOS

2.04 bugfixes

Should help with UI lockups
This commit is contained in:
Ben V. Brown
2018-05-07 21:24:29 +10:00
parent 771f0a1b9e
commit 4718efe79b
7 changed files with 109 additions and 44 deletions

View File

@@ -11,7 +11,7 @@
#define SETTINGS_H_
#include <stdint.h>
#include "stm32f1xx_hal.h"
#define SETTINGSVERSION 0x13 /*Change this if you change the struct below to prevent people getting out of sync*/
#define SETTINGSVERSION 0x14 /*Change this if you change the struct below to prevent people getting out of sync*/
/*
* This struct must be a multiple of 2 bytes as it is saved / restored from flash in uint16_t chunks
@@ -34,6 +34,9 @@ typedef struct {
uint16_t voltageDiv; //Voltage divisor factor
uint16_t BoostTemp; //Boost mode set point for the iron
int16_t CalibrationOffset; //This stores the temperature offset for this tip in the iron.
uint8_t PID_P; //PID P Term
uint8_t PID_I; //PID I Term
uint8_t PID_D; //PID D Term
uint8_t version; //Used to track if a reset is needed on firmware upgrade
uint32_t padding; //This is here for in case we are not an even divisor so that nothing gets cut off
} systemSettingsType;

View File

@@ -14,11 +14,13 @@ FRToSI2C::FRToSI2C(I2C_HandleTypeDef* i2chandle) {
void FRToSI2C::CpltCallback() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
i2c->State = HAL_I2C_STATE_READY;//Force state reset
if (I2CSemaphore) {
xSemaphoreGiveFromISR(I2CSemaphore, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
@@ -32,7 +34,7 @@ void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
//RToS is active, run threading
//Get the mutex so we can use the I2C port
//Wait up to 1 second for the mutex
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) portMAX_DELAY ) == pdTRUE) {
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 5000 ) == pdTRUE) {
if (HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData,
Size, 5000) != HAL_OK) {
NVIC_SystemReset();
@@ -57,7 +59,7 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
//RToS is active, run threading
//Get the mutex so we can use the I2C port
//Wait up to 1 second for the mutex
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) portMAX_DELAY ) == pdTRUE) {
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 5000 ) == pdTRUE) {
if (HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize,
pData, Size, 5000) != HAL_OK) {
NVIC_SystemReset();
@@ -86,7 +88,7 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) {
//RToS is active, run threading
//Get the mutex so we can use the I2C port
//Wait up to 1 second for the mutex
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) portMAX_DELAY ) == pdTRUE) {
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 5000 ) == pdTRUE) {
if (HAL_I2C_Master_Transmit_DMA(i2c, DevAddress, pData, Size)
!= HAL_OK) {
NVIC_SystemReset();

View File

@@ -90,6 +90,10 @@ void resetSettings() {
systemSettings.CalibrationOffset = 10; //This appears to be quite close for both of my tips, in both of my handles
systemSettings.temperatureInF = 0; //default to 0
systemSettings.descriptionScrollSpeed=0;//default to slow
systemSettings.PID_P =42;
systemSettings.PID_I =50;
systemSettings.PID_D =15;
saveSettings();
}

View File

@@ -154,14 +154,16 @@ static void MX_ADC1_Init(void) {
sConfigInjected.InjectedRank = 4;
HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected);
SET_BIT(hadc1.Instance->CR1, ( ADC_CR1_JEOCIE )); //Enable end of injected conv irq
while(HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK);
// Run ADC internal calibration
while (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK)
;
}
/* I2C1 init function */
static void MX_I2C1_Init(void) {
hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 300000; //300Khz
hi2c1.Init.ClockSpeed = 100000; // OLED doesnt handle >100k when its asleep (off).
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

View File

@@ -75,6 +75,15 @@ const char* SettingsDescriptions[17] = {
/* Calibrate input voltage */ "VIN Calibration. Buttons adjust, long press to exit",
/* Advanced soldering screen enabled */ "Display detailed information while soldering",
/* Description Scroll Speed */ "Speed this text scrolls past at",
#ifdef PIDSETTINGS
"PID P term. Inverse values! This acts as a divisor. So Larger numbers == typically smaller in other systems",
"PID I term. Inverse values! This acts as a divisor. So Larger numbers == typically smaller in other systems",
"PID D term. Inverse values! This acts as a divisor. So Larger numbers == typically smaller in other systems",
#endif
};
const char* SettingsCalibrationWarning = "Please ensure the tip is at room temperature before continuing!";
@@ -121,6 +130,13 @@ const char* SettingsShortNames[17][2] = {
/* (<= 16) Calibrate input voltage */ {"Calibrate", "input voltage?"},
/* (<= 13) Advanced soldering screen enabled */ {"Detailed", "solder screen"},
/* (<= 11) Display Help Text Scroll Speed */ {"Description","Scroll Speed"},
#ifdef PIDSETTINGS
{"PID","P"},
{"PID","I"},
{"PID","D"},
#endif
};
// SettingsMenuEntries lengths <= 13 per line (\n starts second line)

View File

@@ -31,7 +31,15 @@ static void settings_setAdvancedIDLEScreens(void);
static void settings_displayAdvancedIDLEScreens(void);
static void settings_setScrollSpeed(void);
static void settings_displayScrollSpeed(void);
#ifdef PIDSETTINGS
static void settings_setPIDP(void);
static void settings_displayPIDP(void);
static void settings_setPIDI(void);
static void settings_displayPIDI(void);
static void settings_setPIDD(void);
static void settings_displayPIDD(void);
#endif
static void settings_setDisplayRotation(void);
static void settings_displayDisplayRotation(void);
static void settings_setBoostModeEnabled(void);
@@ -181,6 +189,15 @@ const menuitem advancedMenu[] = {
settings_displayCalibrate } }, /*Calibrate tip*/
{ (const char*) SettingsDescriptions[14], { settings_setCalibrateVIN }, {
settings_displayCalibrateVIN } }, /*Voltage input cal*/
#ifdef PIDSETTINGS
{ (const char*) SettingsDescriptions[17], { settings_setPIDP }, {
settings_displayPIDP } }, /*Voltage input cal*/
{ (const char*) SettingsDescriptions[18], { settings_setPIDI }, {
settings_displayPIDI } }, /*Voltage input cal*/
{ (const char*) SettingsDescriptions[19], { settings_setPIDD }, {
settings_displayPIDD } }, /*Voltage input cal*/
#endif
{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE
};
@@ -363,12 +380,12 @@ static void settings_setTempF(void) {
}
// Rescale both to be multiples of 10
systemSettings.BoostTemp = systemSettings.BoostTemp/10;
systemSettings.BoostTemp *=10;
systemSettings.SolderingTemp = systemSettings.SolderingTemp/10;
systemSettings.SolderingTemp *=10;
systemSettings.SleepTemp = systemSettings.SleepTemp/10;
systemSettings.SleepTemp *=10;
systemSettings.BoostTemp = systemSettings.BoostTemp / 10;
systemSettings.BoostTemp *= 10;
systemSettings.SolderingTemp = systemSettings.SolderingTemp / 10;
systemSettings.SolderingTemp *= 10;
systemSettings.SleepTemp = systemSettings.SleepTemp / 10;
systemSettings.SleepTemp *= 10;
}
@@ -488,6 +505,33 @@ static void settings_displayBoostTemp(void) {
lcd.printNumber(systemSettings.BoostTemp, 3);
}
#ifdef PIDSETTINGS
static void settings_setPIDP(void) {
systemSettings.PID_P++;
systemSettings.PID_P %= 100;
}
static void settings_displayPIDP(void) {
printShortDescription(17, 6);
lcd.printNumber(systemSettings.PID_P, 2);
}
static void settings_setPIDI(void) {
systemSettings.PID_I++;
systemSettings.PID_I %= 100;
}
static void settings_displayPIDI(void) {
printShortDescription(18, 6);
lcd.printNumber(systemSettings.PID_I, 2);
}
static void settings_setPIDD(void) {
systemSettings.PID_D++;
systemSettings.PID_D %= 100;
}
static void settings_displayPIDD(void) {
printShortDescription(19, 6);
lcd.printNumber(systemSettings.PID_D, 2);
}
#endif
static void settings_setAutomaticStartMode(void) {
systemSettings.autoStartMode++;
systemSettings.autoStartMode %= 2;
@@ -495,7 +539,6 @@ static void settings_setAutomaticStartMode(void) {
static void settings_displayAutomaticStartMode(void) {
printShortDescription(10, 7);
lcd.drawCheckbox(systemSettings.autoStartMode);
}

View File

@@ -787,17 +787,11 @@ void startPIDTask(void const *argument) {
osDelay(500);
int32_t integralCount = 0;
int32_t derivativeLastValue = 0;
int32_t kp, ki, kd;
ki = 50;
kd = 15;
// REMEBER ^^^^ These constants are backwards
// They act as dividers, so to 'increase' a P term, you make the number
// smaller.
if (getInputVoltageX10(systemSettings.voltageDiv) < 150) {
//Boot P term if < 15 Volts
kp = 30;
} else
kp = 42;
const int32_t itermMax = 100;
pidTaskNotification = xTaskGetCurrentTaskHandle();
for (;;) {
@@ -818,7 +812,7 @@ void startPIDTask(void const *argument) {
int32_t rawTempError = currentlyActiveTemperatureTarget
- rawTemp;
int32_t ierror = (rawTempError / ki);
int32_t ierror = (rawTempError / ((int32_t)systemSettings.PID_I));
integralCount += ierror;
if (integralCount > (itermMax / 2))
integralCount = itermMax / 2; // prevent too much lead
@@ -828,11 +822,11 @@ void startPIDTask(void const *argument) {
int32_t dInput = (rawTemp - derivativeLastValue);
/*Compute PID Output*/
int32_t output = (rawTempError / kp);
if (ki)
int32_t output = (rawTempError / ((int32_t)systemSettings.PID_P));
if (((int32_t)systemSettings.PID_I))
output += integralCount;
if (kd)
output -= (dInput / kd);
if (((int32_t)systemSettings.PID_D))
output -= (dInput / ((int32_t)systemSettings.PID_D));
if (output > 100) {
output = 100; // saturate
@@ -968,6 +962,7 @@ void startMOVTask(void const *argument) {
bool showBootLogoIfavailable() {
// check if the header is there (0xAA,0x55,0xF0,0x0D)
// If so display logo
//TODO REDUCE STACK ON THIS ONE, USE DRAWING IN THE READ LOOP
uint16_t temp[98];
for (uint8_t i = 0; i < (98); i++) {