aboutsummaryrefslogtreecommitdiffhomepage
path: root/workspace/TS100
diff options
context:
space:
mode:
Diffstat (limited to 'workspace/TS100')
-rw-r--r--workspace/TS100/inc/Settings.h39
-rw-r--r--workspace/TS100/src/FRToSI2C.cpp8
-rw-r--r--workspace/TS100/src/Settings.cpp4
-rw-r--r--workspace/TS100/src/Setup.c6
-rw-r--r--workspace/TS100/src/Translation.cpp16
-rw-r--r--workspace/TS100/src/gui.cpp61
-rw-r--r--workspace/TS100/src/main.cpp21
7 files changed, 110 insertions, 45 deletions
diff --git a/workspace/TS100/inc/Settings.h b/workspace/TS100/inc/Settings.h
index 384a46ae..0c733c43 100644
--- a/workspace/TS100/inc/Settings.h
+++ b/workspace/TS100/inc/Settings.h
@@ -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;
diff --git a/workspace/TS100/src/FRToSI2C.cpp b/workspace/TS100/src/FRToSI2C.cpp
index 49058ce1..9a81f9ad 100644
--- a/workspace/TS100/src/FRToSI2C.cpp
+++ b/workspace/TS100/src/FRToSI2C.cpp
@@ -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();
diff --git a/workspace/TS100/src/Settings.cpp b/workspace/TS100/src/Settings.cpp
index 22389404..840aebb4 100644
--- a/workspace/TS100/src/Settings.cpp
+++ b/workspace/TS100/src/Settings.cpp
@@ -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();
}
diff --git a/workspace/TS100/src/Setup.c b/workspace/TS100/src/Setup.c
index 98128007..8cbf54a1 100644
--- a/workspace/TS100/src/Setup.c
+++ b/workspace/TS100/src/Setup.c
@@ -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;
diff --git a/workspace/TS100/src/Translation.cpp b/workspace/TS100/src/Translation.cpp
index b452efb1..a4e44150 100644
--- a/workspace/TS100/src/Translation.cpp
+++ b/workspace/TS100/src/Translation.cpp
@@ -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)
diff --git a/workspace/TS100/src/gui.cpp b/workspace/TS100/src/gui.cpp
index 5884ab8f..bb57ab87 100644
--- a/workspace/TS100/src/gui.cpp
+++ b/workspace/TS100/src/gui.cpp
@@ -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,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) {
@@ -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);
}
diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp
index dd986967..44249442 100644
--- a/workspace/TS100/src/main.cpp
+++ b/workspace/TS100/src/main.cpp
@@ -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++) {