Skip to content

Commit

Permalink
2.04 bugfixes
Browse files Browse the repository at this point in the history
Should help with UI lockups
  • Loading branch information
Ralim committed May 7, 2018
1 parent 771f0a1 commit 4718efe
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 45 deletions.
39 changes: 21 additions & 18 deletions workspace/TS100/inc/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,34 @@
#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
*/
typedef struct {
uint16_t SolderingTemp; //current set point for the iron
uint16_t SleepTemp; //temp to drop to in sleep
uint8_t SleepTime; //minutes timeout to sleep
uint8_t cutoutSetting; // The voltage we cut out at for under voltage
uint8_t OrientationMode:2; //If true we want to invert the display for lefties
uint8_t sensitivity :4; //Sensitivity of accelerometer (5 bits)
uint8_t autoStartMode :2; //Should the unit automatically jump straight into soldering mode when power is applied
uint8_t ShutdownTime; //Time until unit shuts down if left alone
uint8_t boostModeEnabled :1; //Boost mode swaps BUT_A in soldering mode to temporary soldering temp over-ride
uint8_t coolingTempBlink :1; //Should the temperature blink on the cool down screen until its <50C
uint16_t SolderingTemp; //current set point for the iron
uint16_t SleepTemp; //temp to drop to in sleep
uint8_t SleepTime; //minutes timeout to sleep
uint8_t cutoutSetting; // The voltage we cut out at for under voltage
uint8_t OrientationMode:2; //If true we want to invert the display for lefties
uint8_t sensitivity :4; //Sensitivity of accelerometer (5 bits)
uint8_t autoStartMode :2; //Should the unit automatically jump straight into soldering mode when power is applied
uint8_t ShutdownTime; //Time until unit shuts down if left alone
uint8_t boostModeEnabled :1; //Boost mode swaps BUT_A in soldering mode to temporary soldering temp over-ride
uint8_t coolingTempBlink :1; //Should the temperature blink on the cool down screen until its <50C
uint8_t detailedIDLE :1; //Detailed idle screen
uint8_t detailedSoldering :1; //Detailed soldering screens
uint8_t temperatureInF; //Should the temp be in F or C (true is F)
uint8_t descriptionScrollSpeed:1; // Description scroll speed
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 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
uint8_t temperatureInF; //Should the temp be in F or C (true is F)
uint8_t descriptionScrollSpeed:1; // Description scroll speed
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;

extern volatile systemSettingsType systemSettings;
Expand Down
8 changes: 5 additions & 3 deletions workspace/TS100/src/FRToSI2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions workspace/TS100/src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

6 changes: 4 additions & 2 deletions workspace/TS100/src/Setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions workspace/TS100/src/Translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down Expand Up @@ -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)
Expand Down
61 changes: 52 additions & 9 deletions workspace/TS100/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
};

Expand Down Expand Up @@ -363,13 +380,13 @@ 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;

}

static void settings_displayTempF(void) {
Expand Down Expand Up @@ -488,14 +505,40 @@ 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;
}

static void settings_displayAutomaticStartMode(void) {
printShortDescription(10, 7);

lcd.drawCheckbox(systemSettings.autoStartMode);
}

Expand Down
21 changes: 8 additions & 13 deletions workspace/TS100/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (;;) {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit 4718efe

Please sign in to comment.