diff --git a/workspace/TS100/.settings/language.settings.xml b/workspace/TS100/.settings/language.settings.xml
index 9d93beb1..3174fb8a 100644
--- a/workspace/TS100/.settings/language.settings.xml
+++ b/workspace/TS100/.settings/language.settings.xml
@@ -6,7 +6,7 @@
-
+
@@ -18,7 +18,7 @@
-
+
diff --git a/workspace/TS100/src/LIS2DH12.cpp b/workspace/TS100/src/LIS2DH12.cpp
index a004200e..be793bd6 100644
--- a/workspace/TS100/src/LIS2DH12.cpp
+++ b/workspace/TS100/src/LIS2DH12.cpp
@@ -33,7 +33,9 @@ void LIS2DH12::initalize() {
uint8_t LIS2DH12::getOrientation() {
// 8=right handed,4=left,16=flat
//So we ignore if not 8/4
+ taskENTER_CRITICAL();
uint8_t pos = I2C_RegisterRead(LIS_INT2_SRC);
+ taskEXIT_CRITICAL();
if (pos == 8)
return 1;
else if (pos == 4)
@@ -59,7 +61,6 @@ void LIS2DH12::setSensitivity(uint8_t threshold, uint8_t filterTime) {
}
void LIS2DH12::I2C_RegisterWrite(uint8_t reg, uint8_t data) {
-
HAL_I2C_Mem_Write(i2c, LIS2DH_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, &data,
1, 500);
}
@@ -68,6 +69,5 @@ uint8_t LIS2DH12::I2C_RegisterRead(uint8_t reg) {
uint8_t tx_data[1];
HAL_I2C_Mem_Read(i2c, LIS2DH_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT,
tx_data, 1, 500);
-
return tx_data[0];
}
diff --git a/workspace/TS100/src/Setup.c b/workspace/TS100/src/Setup.c
index fb6ee650..7f5a450b 100644
--- a/workspace/TS100/src/Setup.c
+++ b/workspace/TS100/src/Setup.c
@@ -36,7 +36,7 @@ void Setup_HAL() {
MX_TIM2_Init();
MX_IWDG_Init();
- HAL_ADC_Start_DMA(&hadc1, (uint32_t*) ADCReadings, 64);
+ HAL_ADC_Start_DMA(&hadc1, (uint32_t*) ADCReadings, 64);//start DMA of normal readings
HAL_ADCEx_InjectedStart(&hadc1); //enable injected readings
}
@@ -252,7 +252,7 @@ static void MX_TIM2_Init(void) {
HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig);
sConfigOC.OCMode = TIM_OCMODE_PWM1;
- sConfigOC.Pulse = 117;
+ sConfigOC.Pulse = 118;
/*
* It takes 4 milliseconds for output to be stable after PWM turns off.
* Assume ADC samples in 0.5ms
diff --git a/workspace/TS100/src/gui.cpp b/workspace/TS100/src/gui.cpp
index e4acb844..de109c76 100644
--- a/workspace/TS100/src/gui.cpp
+++ b/workspace/TS100/src/gui.cpp
@@ -285,9 +285,16 @@ static void settings_displayInputVRange(void) {
}
static void settings_setSleepTemp(void) {
- systemSettings.SleepTemp += 10;
- if (systemSettings.SleepTemp > 300)
- systemSettings.SleepTemp = 50;
+ //If in C, 10 deg, if in F 20 deg
+ if (systemSettings.temperatureInF) {
+ systemSettings.SleepTemp += 20;
+ if (systemSettings.SleepTemp > 580)
+ systemSettings.SleepTemp = 120;
+ } else {
+ systemSettings.SleepTemp += 10;
+ if (systemSettings.SleepTemp > 300)
+ systemSettings.SleepTemp = 50;
+ }
}
static void settings_displaySleepTemp(void) {
@@ -339,6 +346,22 @@ static void settings_displayShutdownTime(void) {
static void settings_setTempF(void) {
systemSettings.temperatureInF = !systemSettings.temperatureInF;
+ if (systemSettings.temperatureInF) {
+ //Change sleep, boost and soldering temps to the F equiv
+ //C to F == F= ( (C*9) +160)/5
+ systemSettings.BoostTemp = ((systemSettings.BoostTemp * 9) + 160) / 5;
+ systemSettings.SolderingTemp =
+ ((systemSettings.SolderingTemp * 9) + 160) / 5;
+ systemSettings.SleepTemp = ((systemSettings.SleepTemp * 9) + 160) / 5;
+ } else {
+ //Change sleep, boost and soldering temps to the C equiv
+ // F->C == C = ((F-32)*5)/9
+ systemSettings.BoostTemp = ((systemSettings.BoostTemp - 32) * 5) / 9;
+ systemSettings.SolderingTemp = ((systemSettings.SolderingTemp - 32) * 5)
+ / 9;
+ systemSettings.SleepTemp = ((systemSettings.SleepTemp - 32) * 5) / 9;
+
+ }
}
static void settings_displayTempF(void) {
@@ -438,12 +461,14 @@ static void settings_displayBoostModeEnabled(void) {
}
static void settings_setBoostTemp(void) {
- systemSettings.BoostTemp += 10; // Go up 10 at a time
+
if (systemSettings.temperatureInF) {
+ systemSettings.BoostTemp += 20; // Go up 20F at a time
if (systemSettings.BoostTemp > 850) {
systemSettings.BoostTemp = 480; // loop back at 250
}
} else {
+ systemSettings.BoostTemp += 10; // Go up 10C at a time
if (systemSettings.BoostTemp > 450) {
systemSettings.BoostTemp = 250; // loop back at 250
}
diff --git a/workspace/TS100/src/hardware.c b/workspace/TS100/src/hardware.c
index 4f710190..c91a3b80 100644
--- a/workspace/TS100/src/hardware.c
+++ b/workspace/TS100/src/hardware.c
@@ -62,7 +62,7 @@ uint16_t getTipInstantTemperature() {
uint16_t getTipRawTemp(uint8_t instant) {
#define filterDepth1 1
/*Pre filter used before PID*/
-#define filterDepth2 32
+#define filterDepth2 64
/*Post filter used for UI display*/
static uint16_t filterLayer1[filterDepth1];
static uint16_t filterLayer2[filterDepth2];
diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp
index 22b2bc06..bad04580 100644
--- a/workspace/TS100/src/main.cpp
+++ b/workspace/TS100/src/main.cpp
@@ -60,8 +60,9 @@ int main(void) {
accel2.initalize(); //startup the accelerometer
} else {
PCBVersion = 3;
- systemSettings.SleepTime=0;
- systemSettings.ShutdownTime=0;//No accel -> disable sleep
+ systemSettings.SleepTime = 0;
+ systemSettings.ShutdownTime = 0; //No accel -> disable sleep
+ systemSettings.sensitivity=0;
}
HAL_IWDG_Refresh(&hiwdg);
restoreSettings(); // load the settings from flash
@@ -70,25 +71,25 @@ int main(void) {
/* Create the thread(s) */
/* definition and creation of GUITask */
- osThreadDef(GUITask, startGUITask, osPriorityBelowNormal, 0, 512);
+ osThreadDef(GUITask, startGUITask, osPriorityBelowNormal, 0, 768); //3k
GUITaskHandle = osThreadCreate(osThread(GUITask), NULL);
/* definition and creation of PIDTask */
- osThreadDef(PIDTask, startPIDTask, osPriorityRealtime, 0, 256);
+ osThreadDef(PIDTask, startPIDTask, osPriorityRealtime, 0, 512); //2k
PIDTaskHandle = osThreadCreate(osThread(PIDTask), NULL);
-
- /* definition and creation of ROTTask */
- osThreadDef(ROTTask, startRotationTask, osPriorityLow, 0, 256);
- ROTTaskHandle = osThreadCreate(osThread(ROTTask), NULL);
- /* definition and creation of MOVTask */
- osThreadDef(MOVTask, startMOVTask, osPriorityNormal, 0, 256);
- MOVTaskHandle = osThreadCreate(osThread(MOVTask), NULL);
-
+ if (PCBVersion != 3) {
+ /* definition and creation of ROTTask */
+ osThreadDef(ROTTask, startRotationTask, osPriorityLow, 0, 256); //1k
+ ROTTaskHandle = osThreadCreate(osThread(ROTTask), NULL);
+ /* definition and creation of MOVTask */
+ osThreadDef(MOVTask, startMOVTask, osPriorityNormal, 0, 512); //2k
+ MOVTaskHandle = osThreadCreate(osThread(MOVTask), NULL);
+ }
/* Create the objects*/
- rotationChangedSemaphore =
- xSemaphoreCreateBinary(); // Used to unlock rotation thread
- accelDataAvailableSemaphore =
- xSemaphoreCreateBinary(); // Used to unlock the movement thread
+ rotationChangedSemaphore = xSemaphoreCreateBinary();
+ // Used to unlock rotation thread
+ accelDataAvailableSemaphore = xSemaphoreCreateBinary();
+ // Used to unlock the movement thread
/* Start scheduler */
osKernelStart();
@@ -627,7 +628,7 @@ static void gui_solderingMode() {
}
lcd.refresh();
- if (systemSettings.sensitivity)
+ if (systemSettings.sensitivity && systemSettings.SleepTime)
if (xTaskGetTickCount() - lastMovementTime > sleepThres
&& xTaskGetTickCount() - lastButtonTime > sleepThres) {
if (gui_SolderingSleepingMode()) {
@@ -728,8 +729,8 @@ void startGUITask(void const *argument) {
lcd.clearScreen(); // Ensure the buffer starts clean
lcd.setCursor(0, 0); // Position the cursor at the 0,0 (top left)
lcd.setFont(1); // small font
- lcd.print((char *) "V2.03 PCB"); // Print version number
- lcd.printNumber(PCBVersion, 1);
+ lcd.print((char *) "V2.04 PCB"); // Print version number
+ lcd.printNumber(PCBVersion, 1); //Print PCB ID number
lcd.setCursor(0, 8); // second line
lcd.print(__DATE__); // print the compile date
lcd.refresh();
@@ -758,10 +759,15 @@ void startGUITask(void const *argument) {
default:
break;
}
+
currentlyActiveTemperatureTarget = 0; // ensure tip is off
- uint16_t tipTemp = tipMeasurementToC(getTipRawTemp(0));
+
+ uint16_t tipTemp = tipMeasurementToC(getTipRawTemp(1));//This forces a faster update rate on the filtering
+
if (tipTemp < 50) {
+
if (systemSettings.sensitivity) {
+
if ((xTaskGetTickCount() - lastMovementTime) > 6000
&& (xTaskGetTickCount() - lastButtonTime) > 6000) {
lcd.displayOnOff(false); // turn lcd off when no movement
@@ -846,11 +852,11 @@ void startPIDTask(void const *argument) {
int32_t kp, ki, kd;
kp = 40;
ki = 60;
- kd = 30;
+ kd = 20;
// REMEBER ^^^^ These constants are backwards
// They act as dividers, so to 'increase' a P term, you make the number
// smaller.
- const int32_t itermMax = 60;
+ const int32_t itermMax = 100;
for (;;) {
uint16_t rawTemp = getTipRawTemp(1); // get instantaneous reading
if (currentlyActiveTemperatureTarget) {
@@ -859,6 +865,11 @@ void startPIDTask(void const *argument) {
// 33 counts per C)
// P I & D are divisors, so inverse logic applies (beware)
+ // Cap the max setpoint to 450C
+ if (currentlyActiveTemperatureTarget > ctoTipMeasurement(450)) {
+ currentlyActiveTemperatureTarget = ctoTipMeasurement(450);
+ }
+
int32_t rawTempError = currentlyActiveTemperatureTarget - rawTemp;
int32_t ierror = (rawTempError / ki);
integralCount += ierror;
@@ -892,6 +903,7 @@ void startPIDTask(void const *argument) {
setTipPWM(0); // disable the output driver if the output is set to be off
integralCount = 0;
derivativeLastValue = 0;
+ osDelay(100); //sleep for a bit longer
}
HAL_IWDG_Refresh(&hiwdg);
@@ -901,7 +913,7 @@ void startPIDTask(void const *argument) {
#define MOVFilter 8
void startMOVTask(void const *argument) {
osDelay(4000); // wait for accel to stabilize
-
+ lastMovementTime = 0;
int16_t datax[MOVFilter];
int16_t datay[MOVFilter];
int16_t dataz[MOVFilter];
@@ -922,8 +934,8 @@ void startMOVTask(void const *argument) {
osDelay(5000);
}
for (;;) {
- int32_t threshold = 1200 + (9 * 200);
- threshold -= systemSettings.sensitivity * 200; // 200 is the step size
+ int32_t threshold = 1500 + (9 * 200);
+ threshold -= systemSettings.sensitivity * 200; // 200 is the step size
if (PCBVersion == 2)
accel2.getAxisReadings(&tx, &ty, &tz);
else if (PCBVersion == 1)
@@ -961,27 +973,24 @@ void startMOVTask(void const *argument) {
if (HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET)
max = 0;
#endif
- // Only run the actual processing if the sensitivity is set (aka we are
- // enabled)
- if (systemSettings.sensitivity) {
- // calculate averages
- avgx = avgy = avgz = 0;
- for (uint8_t i = 0; i < MOVFilter; i++) {
- avgx += datax[i];
- avgy += datay[i];
- avgz += dataz[i];
- }
- avgx /= MOVFilter;
- avgy /= MOVFilter;
- avgz /= MOVFilter;
- // So now we have averages, we want to look if these are different by more
- // than the threshold
- int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
- // If error has occured then we update the tick timer
- if (error > threshold) {
- lastMovementTime = xTaskGetTickCount();
- }
+ // calculate averages
+ avgx = avgy = avgz = 0;
+ for (uint8_t i = 0; i < MOVFilter; i++) {
+ avgx += datax[i];
+ avgy += datay[i];
+ avgz += dataz[i];
+ }
+ avgx /= MOVFilter;
+ avgy /= MOVFilter;
+ avgz /= MOVFilter;
+
+ // So now we have averages, we want to look if these are different by more
+ // than the threshold
+ int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
+ // If error has occurred then we update the tick timer
+ if (error > threshold) {
+ lastMovementTime = xTaskGetTickCount();
}
osDelay(100); // Slow down update rate