Wider Triac pulse; PID parameters are tuned
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1482216284" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="genericBoard" valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1344937624" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32G070RBTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Middlewares/Third_Party/FreeRTOS/Source/include | ../Drivers/CMSIS/Include | ../Core/Inc | ../Drivers/STM32G0xx_HAL_Driver/Inc | ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 | ../Drivers/CMSIS/Device/ST/STM32G0xx/Include | ../Drivers/STM32G0xx_HAL_Driver/Inc/Legacy | ../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM0 || || || USE_HAL_DRIVER | STM32G070xx | CMSIS_device_header=<stm32g0xx.h> || || Drivers | Core/Startup | Middlewares | Core || || || ${workspace_loc:/${ProjName}/STM32G070RBTX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.1224262438" name="Cpu clock frequence" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="64" valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat.989318517" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat" value="true" valueType="boolean"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat.989318517" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.1893601218" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
|
||||
<builder buildPath="${workspace_loc:/PCB-Heater}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1892196526" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.1860582162" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<provider-reference id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-412172835581539755" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-690114333473919073" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
@@ -17,7 +17,7 @@
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-412172835581539755" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-690114333473919073" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
|
@@ -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();
|
||||
|
@@ -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 */
|
||||
|
@@ -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]
|
||||
|
@@ -20,6 +20,7 @@
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
@@ -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;
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user