diff --git a/firmware/PCB-Heater/.cproject b/firmware/PCB-Heater/.cproject
index 3921886..44025fb 100644
--- a/firmware/PCB-Heater/.cproject
+++ b/firmware/PCB-Heater/.cproject
@@ -23,7 +23,7 @@
-
+
diff --git a/firmware/PCB-Heater/.settings/language.settings.xml b/firmware/PCB-Heater/.settings/language.settings.xml
index 8bb4761..702716d 100644
--- a/firmware/PCB-Heater/.settings/language.settings.xml
+++ b/firmware/PCB-Heater/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
@@ -17,7 +17,7 @@
-
+
diff --git a/firmware/PCB-Heater/Core/Src/app_freertos.c b/firmware/PCB-Heater/Core/Src/app_freertos.c
index 3cf5c83..2a37698 100644
--- a/firmware/PCB-Heater/Core/Src/app_freertos.c
+++ b/firmware/PCB-Heater/Core/Src/app_freertos.c
@@ -103,6 +103,10 @@ typedef struct {
#define SCR_DIALOG 3
#define SCR_BOOT 99
+//Pulses
+#define P_WIDTH 40 // Triac gate Pulse width
+#define P_DELAY 5 // Minimum delay before gate pulse
+
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
@@ -160,6 +164,7 @@ static uint8_t Stage = 0; //current stage of a profile
static float spp; //Seconds per pixel (horizontal)
static float dpp; //Degrees per pixel (vertical)
uint16_t Timer = 0; //Time counter
+uint16_t Timer10 = 0; //Time x10 counter
static uint8_t fanActive = 0; //Fans are active flag
static uint8_t Running = 0; //Running program flag
settings_t settings = { //settings structure
@@ -186,12 +191,12 @@ const presets_t presets[4] = {
PIDController pid = {
.Kp = 40.0f,
- .Ki = 20.0f,
- .Kd = 5.0f,
- .T = 0.5f, //2 times per second
+ .Ki = 1.0f,
+ .Kd = 3.0f,
+ .T = 0.25f, //2 times per second
.tau = 0.2f, //Low-pass filter (0 - no filter)
.limMin = -100.0f,
- .limMax = 969.0f
+ .limMax = 1000.0f - P_WIDTH - P_DELAY - 1 // 949.0
};
/* USER CODE END Variables */
@@ -474,7 +479,7 @@ void svc_sensor(void *argument)
if (!Running && Temperature > 50.0f) setFansSpeed(100);
if (!Running && Temperature <= 44.0f && fanActive) setFansSpeed(0);
- osDelay(500);
+ osDelay(250);
}
/* USER CODE END svc_sensor */
}
@@ -527,13 +532,45 @@ void clockTick(void *argument)
return;
}
- if (Timer == 0) {
+
+ //PID
+ PID_Update(&pid, aimTemperature, Temperature);
+ if (pid.out >= 0.0f) {
+ pulse = (uint16_t)(pid.limMax - pid.out)+P_DELAY;
+ if (fanActive) setFansSpeed(0);
+ }
+ else {
+ pulse = 1020;
+ setFansSpeed((uint8_t)(pid.out * -1));
+ }
+ TIM1->ARR = pulse+P_WIDTH;
+ TIM1->CCR2 = pulse;
+
+ //Draw PID value
+ if (Screen == SCR_RUNNING) {
+ snprintf(str, 7, "%3.2f", pid.out);
+ //snprintf(str, 7, "%3d.%02d", (int)pid.out, (int)((pid.out-(int)pid.out)*100));
+ osMutexAcquire(mutScreenHandle, osWaitForever);
+ ST7793_SetFontSize(1);
+ ST7793_FillRect(Darkergray, 11, 180, 27, 192);
+ ST7793_DrawString(Black, Darkergray, str, 11, 180);
+
+ snprintf(str, 7, "P:%4d", pulse);
+ ST7793_FillRect(Lightgray, 100, 50, 116, 62);
+ ST7793_DrawString(Black, Lightgray, str, 100, 50);
+ osMutexRelease(mutScreenHandle);
+ }
+
+ if (Timer == 0 && Timer10 == 0) {
stime = 0;
stemp = 20;
dps = (presets[Preset].temperature[Stage] - stemp) / (float)(presets[Preset].time[Stage]);
Running = 1;
}
+ Timer10++;
+ if (Timer10%4 != 0) return;
+
Timer++;
osMutexAcquire(mutScreenHandle, osWaitForever);
@@ -577,33 +614,7 @@ void clockTick(void *argument)
osMutexRelease(mutScreenHandle);
- //PID
- PID_Update(&pid, aimTemperature, Temperature);
- if (pid.out >= 0.0f) {
- pulse = (uint16_t)(pid.limMax - pid.out)+20;
- if (fanActive) setFansSpeed(0);
- }
- else {
- pulse = 1020;
- setFansSpeed((uint8_t)(pid.out * -1));
- }
- TIM1->ARR = pulse+10;
- TIM1->CCR2 = pulse;
- //Draw PID value
- if (Screen == SCR_RUNNING) {
- snprintf(str, 7, "%3.2f", pid.out);
- //snprintf(str, 7, "%3d.%02d", (int)pid.out, (int)((pid.out-(int)pid.out)*100));
- osMutexAcquire(mutScreenHandle, osWaitForever);
- ST7793_SetFontSize(1);
- ST7793_FillRect(Darkergray, 11, 180, 27, 192);
- ST7793_DrawString(Black, Darkergray, str, 11, 180);
-
- snprintf(str, 7, "P:%4d", pulse);
- ST7793_FillRect(Lightgray, 100, 50, 116, 62);
- ST7793_DrawString(Black, Lightgray, str, 100, 50);
- osMutexRelease(mutScreenHandle);
- }
/* USER CODE END clockTick */
}
@@ -629,9 +640,10 @@ void btnPressed(uint8_t id) {
break;
case BTN_START: // START
Timer = 0;
+ Timer10 = 0;
Stage = 0;
drawRunningScreen();
- osTimerStart(secTimerHandle, 1000);
+ osTimerStart(secTimerHandle, 250);
break;
case BTN_COG: // COG (Settings)
drawSettingsScreen();
diff --git a/firmware/PCB-Heater/Core/Src/main.c b/firmware/PCB-Heater/Core/Src/main.c
index 35475c6..27adcd2 100644
--- a/firmware/PCB-Heater/Core/Src/main.c
+++ b/firmware/PCB-Heater/Core/Src/main.c
@@ -133,6 +133,7 @@ int main(void)
/* Start scheduler */
osKernelStart();
+
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
diff --git a/firmware/PCB-Heater/Core/Src/pid.c b/firmware/PCB-Heater/Core/Src/pid.c
index 5da1b51..3a9de57 100644
--- a/firmware/PCB-Heater/Core/Src/pid.c
+++ b/firmware/PCB-Heater/Core/Src/pid.c
@@ -22,7 +22,7 @@ void PID_Init(PIDController *pid) {
float PID_Update(PIDController *pid, float setpoint, float measurement) {
// PID = Kp + Ki * 1/s + Kd * s/(s*tau+1)
- // e = error tothe setpoint
+ // e = error to the setpoint
// p[n] = Kp * e[n]
// i[n] = Ki*T/2 * (e[n]+e[n-1]) + i[n-1]
// d[n] = 2*Kd/(2*tau+T) * (e[n]-e[n-1]) + (2*tau-T)/(2*tau+T) * d[n-1]
diff --git a/firmware/PCB-Heater/Core/Src/stm32g0xx_hal_msp.c b/firmware/PCB-Heater/Core/Src/stm32g0xx_hal_msp.c
index dfadb15..4abb1a1 100644
--- a/firmware/PCB-Heater/Core/Src/stm32g0xx_hal_msp.c
+++ b/firmware/PCB-Heater/Core/Src/stm32g0xx_hal_msp.c
@@ -20,6 +20,7 @@
/* Includes ------------------------------------------------------------------*/
#include "main.h"
+
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
diff --git a/firmware/PCB-Heater/Core/Src/tim.c b/firmware/PCB-Heater/Core/Src/tim.c
index 65f240b..c8f0f47 100644
--- a/firmware/PCB-Heater/Core/Src/tim.c
+++ b/firmware/PCB-Heater/Core/Src/tim.c
@@ -51,7 +51,7 @@ void MX_TIM1_Init(void)
htim1.Instance = TIM1;
htim1.Init.Prescaler = 640-1;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
- htim1.Init.Period = 999;
+ htim1.Init.Period = 1000-1;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
diff --git a/firmware/PCB-Heater/PCB-Heater.ioc b/firmware/PCB-Heater/PCB-Heater.ioc
index 19a84f9..c83a4df 100644
--- a/firmware/PCB-Heater/PCB-Heater.ioc
+++ b/firmware/PCB-Heater/PCB-Heater.ioc
@@ -87,8 +87,8 @@ Mcu.PinsNb=42
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32G070RBTx
-MxCube.Version=6.8.1
-MxDb.Version=DB.6.0.81
+MxCube.Version=6.9.1
+MxDb.Version=DB.6.0.91
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
@@ -259,6 +259,8 @@ ProjectManager.RegisterCallBack=
ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
+ProjectManager.UAScriptAfterPath=
+ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_TIM1_Init-TIM1-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_SPI2_Init-SPI2-false-HAL-true,6-MX_TIM17_Init-TIM17-false-HAL-true,7-MX_TIM15_Init-TIM15-false-HAL-true,8-MX_TIM14_Init-TIM14-false-HAL-true,9-MX_USART1_UART_Init-USART1-false-HAL-true,10-MX_TIM16_Init-TIM16-false-HAL-true
RCC.ADCFreq_Value=64000000
@@ -316,7 +318,7 @@ TIM1.IPParameters=AutoReloadPreload,Prescaler,Period,BreakState,AutomaticOutput,
TIM1.OC2Preload_PWM=DISABLE
TIM1.OCMode_PWM-PWM\ Generation2\ CH2=TIM_OCMODE_PWM2
TIM1.OCPolarity_2=TIM_OCPOLARITY_HIGH
-TIM1.Period=999
+TIM1.Period=1000-1
TIM1.Prescaler=640-1
TIM1.Pulse-PWM\ Generation2\ CH2=1020
TIM14.Channel=TIM_CHANNEL_1