From c83174862a23b72eb5a472070f8701a423480b7b Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Fri, 9 Nov 2018 13:14:20 +1100 Subject: [PATCH] Tweak pwm timings, improve Voltage init for more stable startup --- workspace/TS100/src/Setup.c | 4 ++-- workspace/TS100/src/hardware.c | 12 +++--------- workspace/TS100/src/main.cpp | 11 +++-------- workspace/TS100A/.cproject | 12 +++++++++--- workspace/TS100A/.project | 15 +++++++++++++++ workspace/TS100A/.settings/language.settings.xml | 2 +- 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/workspace/TS100/src/Setup.c b/workspace/TS100/src/Setup.c index 78707d4b..f7d5667a 100644 --- a/workspace/TS100/src/Setup.c +++ b/workspace/TS100/src/Setup.c @@ -313,7 +313,7 @@ static void MX_TIM2_Init(void) { //Trade off is the slower the PWM output the slower we can respond and we gain temperature accuracy in settling time, //But it increases the time delay between the heat cycle and the measurement and calculate cycle htim2.Init.CounterMode = TIM_COUNTERMODE_UP; - htim2.Init.Period = 255+56; + htim2.Init.Period = 255+60; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before divide htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; HAL_TIM_Base_Init(&htim2); @@ -329,7 +329,7 @@ static void MX_TIM2_Init(void) { HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig); sConfigOC.OCMode = TIM_OCMODE_PWM1; - sConfigOC.Pulse = 255+47; //255 is the largest time period of the drive signal, and the 47 offsets this around 5ms afterwards + sConfigOC.Pulse = 255+50; //255 is the largest time period of the drive signal, and the 47 offsets this around 5ms afterwards /* * 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/hardware.c b/workspace/TS100/src/hardware.c index bfa41e9f..746cc4a5 100644 --- a/workspace/TS100/src/hardware.c +++ b/workspace/TS100/src/hardware.c @@ -133,13 +133,13 @@ uint16_t getInputVoltageX10(uint16_t divisor) { // Multiplying ADC max by 4 for additional calibration options, // ideal term is 467 #define BATTFILTERDEPTH 32 - static uint8_t preFillneeded = 1; + static uint8_t preFillneeded = 10; static uint32_t samples[BATTFILTERDEPTH]; static uint8_t index = 0; if (preFillneeded) { for (uint8_t i = 0; i < BATTFILTERDEPTH; i++) samples[i] = getADC(1); - preFillneeded = 0; + preFillneeded--; } samples[index] = getADC(1); index = (index + 1) % BATTFILTERDEPTH; @@ -409,10 +409,7 @@ uint8_t getTipPWM() { void setTipPWM(uint8_t pulse) { PWMSafetyTimer = 2; // This is decremented in the handler for PWM so that the tip pwm is // disabled if the PID task is not scheduled often enough. - if (pulse > 255) - pulse = 255; - if (pulse == 0) // Need to have some pulse to keep the PID controller moving forward as these end of cycle completions move the thread along - pulse = 1; + pendingPWM = pulse; } @@ -430,11 +427,9 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { // increased safety htim2.Instance->CCR4 = pendingPWM; if (htim2.Instance->CCR4 && PWMSafetyTimer) { - htim3.Instance->CCR1 = 50; HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); } else { HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1); - htim3.Instance->CCR1 = 0; } } else if (htim->Instance == TIM1) { // STM uses this for internal functions as a counter for timeouts @@ -447,7 +442,6 @@ void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) { // This was a when the PWM for the output has timed out if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4) { HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1); - htim3.Instance->CCR1 = 0; } } } diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp index b587dd4e..86af0f2d 100644 --- a/workspace/TS100/src/main.cpp +++ b/workspace/TS100/src/main.cpp @@ -914,13 +914,7 @@ void startGUITask(void const *argument __unused) { void startPIDTask(void const *argument __unused) { /* * We take the current tip temperature & evaluate the next step for the tip - * control PWM - * Tip temperature is measured by getTipTemperature(1) so we get instant - * result - * This comes in Cx10 format - * We then control the tip temperature to aim for the setpoint in the settings - * struct - * + * control PWM. */ setTipMilliWatts(0); // disable the output driver if the output is set to be off #ifdef MODEL_TS80 @@ -934,7 +928,8 @@ void startPIDTask(void const *argument __unused) { pidTaskNotification = xTaskGetCurrentTaskHandle(); for (;;) { - if (ulTaskNotifyTake(pdTRUE, 50)) { + + if (ulTaskNotifyTake(pdTRUE, 1000)) { // Wait a max of 50ms // This is a call to block this thread until the ADC does its samples uint16_t rawTemp = getTipRawTemp(1); // get instantaneous reading diff --git a/workspace/TS100A/.cproject b/workspace/TS100A/.cproject index 3f045f55..71603da9 100644 --- a/workspace/TS100A/.cproject +++ b/workspace/TS100A/.cproject @@ -19,7 +19,7 @@