diff --git a/workspace/TS100/inc/hardware.h b/workspace/TS100/inc/hardware.h index 561f1229..0717fde3 100644 --- a/workspace/TS100/inc/hardware.h +++ b/workspace/TS100/inc/hardware.h @@ -16,7 +16,7 @@ extern "C" { enum Orientation { ORIENTATION_LEFT_HAND = 0, ORIENTATION_RIGHT_HAND = 1, ORIENTATION_FLAT = 3 }; -#define PID_TIM_HZ (16) +#define PID_TIM_HZ (8) #if defined(MODEL_TS100) + defined(MODEL_TS80) > 1 #error "Multiple models defined!" #elif defined(MODEL_TS100) + defined(MODEL_TS80) == 0 diff --git a/workspace/TS100/inc/power.hpp b/workspace/TS100/inc/power.hpp index 87df47f2..1850cd14 100644 --- a/workspace/TS100/inc/power.hpp +++ b/workspace/TS100/inc/power.hpp @@ -11,7 +11,23 @@ #ifndef POWER_HPP_ #define POWER_HPP_ -const uint8_t oscillationPeriod = 4 * PID_TIM_HZ; // I term look back value +// thermal mass = 1690 milliJ/*C for my tip. +// -> Wattsx10*Seconds to raise Temp from room temp to +100*C, divided by 100*C. +// we divide mass by 20 to let the I term dominate near the set point. +// This is necessary because of the temp noise and thermal lag in the system. +// Once we have feed-forward temp estimation we should be able to better tune this. + +#ifdef MODEL_TS100 +const uint16_t tipMass = 450; // divide here so division is compile-time. +const uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80 + +#endif +#ifdef MODEL_TS80 +const uint16_t tipMass = 450; +const uint8_t tipResistance = 45; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80 + +#endif +const uint8_t oscillationPeriod = 6 * PID_TIM_HZ; // I term look back value extern history milliWattHistory; int32_t tempToMilliWatts(int32_t rawTemp, uint8_t rawC); diff --git a/workspace/TS100/src/Setup.c b/workspace/TS100/src/Setup.c index 50f742a3..12858395 100644 --- a/workspace/TS100/src/Setup.c +++ b/workspace/TS100/src/Setup.c @@ -32,13 +32,13 @@ static void MX_ADC2_Init(void); void Setup_HAL() { SystemClock_Config(); - #ifndef LOCAL_BUILD -__HAL_AFIO_REMAP_SWJ_DISABLE(); - #else -__HAL_AFIO_REMAP_SWJ_NOJTAG(); - #endif - - +#ifndef LOCAL_BUILD + __HAL_AFIO_REMAP_SWJ_DISABLE() + ; +#else + __HAL_AFIO_REMAP_SWJ_NOJTAG(); +#endif + MX_GPIO_Init(); MX_DMA_Init(); MX_I2C1_Init(); @@ -262,9 +262,9 @@ static void MX_TIM3_Init(void) { htim3.Instance = TIM3; htim3.Init.Prescaler = 8; htim3.Init.CounterMode = TIM_COUNTERMODE_UP; - htim3.Init.Period = 400; // 5 Khz PWM freq + htim3.Init.Period = 100; // 5 Khz PWM freq htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before div - htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;//Preload the ARR register (though we dont use this) + htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; //Preload the ARR register (though we dont use this) HAL_TIM_Base_Init(&htim3); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; @@ -279,7 +279,7 @@ static void MX_TIM3_Init(void) { HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig); sConfigOC.OCMode = TIM_OCMODE_PWM1; - sConfigOC.Pulse = 80;//80% duty cycle, that is AC coupled through the cap + sConfigOC.Pulse = 80; //80% duty cycle, that is AC coupled through the cap sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_ENABLE; HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, PWM_Out_CHANNEL); @@ -291,11 +291,12 @@ static void MX_TIM3_Init(void) { */ GPIO_InitStruct.Pin = PWM_Out_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;//We would like sharp rising edges + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; //We would like sharp rising edges HAL_GPIO_Init(PWM_Out_GPIO_Port, &GPIO_InitStruct); #ifdef MODEL_TS100 // Remap TIM3_CH1 to be on PB4 - __HAL_AFIO_REMAP_TIM3_PARTIAL(); + __HAL_AFIO_REMAP_TIM3_PARTIAL() + ; #else // No re-map required #endif @@ -314,17 +315,15 @@ static void MX_TIM2_Init(void) { // Timer 2 is fairly slow as its being used to run the PWM and trigger the ADC // in the PWM off time. htim2.Instance = TIM2; - htim2.Init.Prescaler = 2000; //1mhz tick rate/800 = 1.25 KHz tick rate + htim2.Init.Prescaler = 4000; //1mhz tick rate/800 = 1.25 KHz tick rate // pwm out is 10k from tim3, we want to run our PWM at around 10hz or slower on the output stage - // The input is 1mhz after the div/4, so divide this by 785 to give around 4Hz output change rate - //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 + // These values give a rate of around 8Hz htim2.Init.CounterMode = TIM_COUNTERMODE_UP; - htim2.Init.Period = 255 + 20; + htim2.Init.Period = 255 + 17; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before divide - htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; - htim2.Init.RepetitionCounter=0; + htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + htim2.Init.RepetitionCounter = 0; HAL_TIM_Base_Init(&htim2); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; @@ -338,7 +337,7 @@ static void MX_TIM2_Init(void) { HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig); sConfigOC.OCMode = TIM_OCMODE_PWM1; - sConfigOC.Pulse = 255 + 10; + sConfigOC.Pulse = 255 + 13;//13 -> Delay of 5ms //255 is the largest time period of the drive signal, and then offset ADC sample to be a bit delayed after this /* * It takes 4 milliseconds for output to be stable after PWM turns off. @@ -348,7 +347,7 @@ static void MX_TIM2_Init(void) { sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_ENABLE; HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1); - sConfigOC.Pulse = 0;//default to entirely off + sConfigOC.Pulse = 0; //default to entirely off HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4); HAL_TIM_Base_Start_IT(&htim2); diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp index cc970019..54c030aa 100644 --- a/workspace/TS100/src/main.cpp +++ b/workspace/TS100/src/main.cpp @@ -271,36 +271,36 @@ static void gui_drawBatteryIcon() { // we need to calculate which of the 10 levels they are on uint8_t cellCount = systemSettings.cutoutSetting + 2; uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0) - / cellCount; + / cellCount; // Should give us approx cell voltage X10 // Range is 42 -> 33 = 9 steps therefore we will use battery 1-10 if (cellV < 33) - cellV = 33; - cellV -= 33; // Should leave us a number of 0-9 + cellV = 33; + cellV -= 33;// Should leave us a number of 0-9 if (cellV > 9) - cellV = 9; + cellV = 9; OLED::drawBattery(cellV + 1); } else - OLED::drawSymbol(15); // Draw the DC Logo + OLED::drawSymbol(15); // Draw the DC Logo #else - // On TS80 we replace this symbol with the voltage we are operating on - // If <9V then show single digit, if not show duals - uint8_t V = getInputVoltageX10(systemSettings.voltageDiv, 0); - if (V % 10 >= 5) - V = V / 10 + 1;// round up - else - V = V / 10; - if (V >= 10) { - int16_t xPos = OLED::getCursorX(); - OLED::setFont(1); - OLED::printNumber(1, 1); - OLED::setCursor(xPos, 8); - OLED::printNumber(V % 10, 1); - OLED::setFont(0); - OLED::setCursor(xPos + 12, 0); // need to reset this as if we drew a wide char - } else { - OLED::printNumber(V, 1); - } + // On TS80 we replace this symbol with the voltage we are operating on + // If <9V then show single digit, if not show duals + uint8_t V = getInputVoltageX10(systemSettings.voltageDiv, 0); + if (V % 10 >= 5) + V = V / 10 + 1; // round up + else + V = V / 10; + if (V >= 10) { + int16_t xPos = OLED::getCursorX(); + OLED::setFont(1); + OLED::printNumber(1, 1); + OLED::setCursor(xPos, 8); + OLED::printNumber(V % 10, 1); + OLED::setFont(0); + OLED::setCursor(xPos + 12, 0); // need to reset this as if we drew a wide char + } else { + OLED::printNumber(V, 1); + } #endif } static void gui_solderingTempAdjust() { @@ -372,7 +372,7 @@ static void gui_solderingTempAdjust() { #ifdef MODEL_TS80 if (!OLED::getRotation()) #else - if (OLED::getRotation()) + if (OLED::getRotation()) #endif OLED::print(SymbolMinus); else @@ -388,7 +388,7 @@ static void gui_solderingTempAdjust() { #ifdef MODEL_TS80 if (!OLED::getRotation()) #else - if (OLED::getRotation()) + if (OLED::getRotation()) #endif OLED::print(SymbolPlus); else @@ -415,7 +415,7 @@ static int gui_SolderingSleepingMode() { || (xTaskGetTickCount() - lastButtonTime < 100)) return 0; // user moved or pressed a button, go back to soldering #ifdef MODEL_TS100 - if (checkVoltageForExit()) + if (checkVoltageForExit()) return 1; // return non-zero on error #endif if (systemSettings.temperatureInF) { @@ -682,9 +682,9 @@ void showVersion(void) { OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) OLED::setFont(1); // small font #ifdef MODEL_TS100 - OLED::print(SymbolVersionNumber); // Print version number -#else OLED::print(SymbolVersionNumber); // Print version number +#else + OLED::print(SymbolVersionNumber); // Print version number #endif OLED::setCursor(0, 8); // second line OLED::print(DebugMenu[screen]); @@ -871,7 +871,7 @@ void startGUITask(void const *argument __unused) { #ifdef MODEL_TS80 if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif OLED::drawArea(12, 0, 84, 16, idleScreenBG); OLED::setCursor(0, 0); @@ -892,7 +892,7 @@ void startGUITask(void const *argument __unused) { #ifdef MODEL_TS80 if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif // in right handed mode we want to draw over the first part OLED::fillArea(55, 0, 41, 16, 0); // clear the area for the temp @@ -921,15 +921,16 @@ void startPIDTask(void const *argument __unused) { */ setTipMilliWatts(0); // disable the output driver if the output is set to be off #ifdef MODEL_TS80 - idealQCVoltage = calculateMaxVoltage(systemSettings.cutoutSetting); + idealQCVoltage = calculateMaxVoltage(systemSettings.cutoutSetting); #endif uint8_t rawC = ctoTipMeasurement(101) - ctoTipMeasurement(100); // 1*C change in raw. #ifdef MODEL_TS80 - //Set power management code to the tip resistance in ohms * 10 - TickType_t lastPowerPulse = 0; + //Set power management code to the tip resistance in ohms * 10 + TickType_t lastPowerPulse = 0; #endif // Tip temp reading filter + // Tip temp is read at a rate of PID_TIM_Hz history tempError = { { 0 }, 0, 0 }; currentlyActiveTemperatureTarget = 0; // Force start with no output (off). If in sleep / soldering this will // be over-ridden rapidly @@ -991,7 +992,7 @@ void startPIDTask(void const *argument __unused) { // This is purely guesswork :'( as everyone implements stuff differently if (xTaskGetTickCount() - lastPowerPulse < 10) { // for the first 100mS turn on for a bit - setTipMilliWatts(2000);// typically its around 5W to hold the current temp, so this wont raise temp much + setTipMilliWatts(2000); // typically its around 5W to hold the current temp, so this wont raise temp much } else { setTipMilliWatts(0); } @@ -1021,9 +1022,9 @@ void startMOVTask(void const *argument __unused) { #ifdef MODEL_TS80 startQC(systemSettings.voltageDiv); while (pidTaskNotification == 0) - osDelay(30); // To ensure we return after idealQCVoltage/tip resistance + osDelay(30); // To ensure we return after idealQCVoltage/tip resistance - seekQC(idealQCVoltage, systemSettings.voltageDiv);// this will move the QC output to the preferred voltage to start with + seekQC(idealQCVoltage, systemSettings.voltageDiv); // this will move the QC output to the preferred voltage to start with #else osDelay(250); // wait for accelerometer to stabilize diff --git a/workspace/TS100/src/power.cpp b/workspace/TS100/src/power.cpp index 1182bf45..967a72e9 100644 --- a/workspace/TS100/src/power.cpp +++ b/workspace/TS100/src/power.cpp @@ -10,41 +10,25 @@ #include const uint16_t powerPWM = 255; -const uint16_t totalPWM = 255 + 30; //htim2.Init.Period, the full PWM cycle +const uint16_t totalPWM = 255 + 17; //htim2.Init.Period, the full PWM cycle -// thermal mass = 1690 milliJ/*C for my tip. -// -> Wattsx10*Seconds to raise Temp from room temp to +100*C, divided by 100*C. -// we divide mass by 20 to let the I term dominate near the set point. -// This is necessary because of the temp noise and thermal lag in the system. -// Once we have feed-forward temp estimation we should be able to better tune this. - -#ifdef MODEL_TS100 -const uint16_t tipMass = 2020 ; // divide here so division is compile-time. -const uint8_t tipResistance = 85;//x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80 - -#endif -#ifdef MODEL_TS80 -const uint16_t tipMass = 1000/4; -const uint8_t tipResistance = 46; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80 - -#endif history milliWattHistory = { { 0 }, 0, 0 }; int32_t tempToMilliWatts(int32_t rawTemp, uint8_t rawC) { // mass is in milliJ/*C, rawC is raw per degree C // returns milliWatts needed to raise/lower a mass by rawTemp // degrees in one cycle. - int32_t milliJoules = tipMass * (rawTemp / rawC); + int32_t milliJoules = tipMass*10 * (rawTemp / rawC); return milliJoules; } void setTipMilliWatts(int32_t mw) { //Enforce Max Watts Limiter # TODO - int32_t output = milliWattsToPWM(mw, systemSettings.voltageDiv / 10, 1); + int32_t output = milliWattsToPWM(mw, systemSettings.voltageDiv , 1); setTipPWM(output); uint32_t actualMilliWatts = PWMToMilliWatts(output, - systemSettings.voltageDiv / 10, 0); + systemSettings.voltageDiv , 0); milliWattHistory.update(actualMilliWatts); } diff --git a/workspace/TS100A/.cproject b/workspace/TS100A/.cproject index 75bd2169..2fd646fc 100644 --- a/workspace/TS100A/.cproject +++ b/workspace/TS100A/.cproject @@ -2,7 +2,7 @@ - + @@ -12,7 +12,7 @@ - + - - + + @@ -171,21 +171,21 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/workspace/TS100A/.gitignore b/workspace/TS100A/.gitignore index c4a1dda3..5221ec2e 100644 --- a/workspace/TS100A/.gitignore +++ b/workspace/TS100A/.gitignore @@ -1,3 +1,5 @@ /Release/ /TS100/ /TS100_LOCAL/ +/ReleaseTS80/ +/ReleaseTS100/ diff --git a/workspace/TS100A/.settings/language.settings.xml b/workspace/TS100A/.settings/language.settings.xml index 0a28b70f..d6ecf5e6 100644 --- a/workspace/TS100A/.settings/language.settings.xml +++ b/workspace/TS100A/.settings/language.settings.xml @@ -1,6 +1,6 @@ - + @@ -10,17 +10,7 @@ - - - - - - - - - - - + diff --git a/workspace/TS100A/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/workspace/TS100A/.settings/org.eclipse.cdt.managedbuilder.core.prefs index 331f04f5..50e6de99 100644 --- a/workspace/TS100A/.settings/org.eclipse.cdt.managedbuilder.core.prefs +++ b/workspace/TS100A/.settings/org.eclipse.cdt.managedbuilder.core.prefs @@ -11,6 +11,12 @@ environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419.2005314669/C_INCLUDE_PATH/operation=remove environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419.2005314669/append=true environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419.2005314669/appendContributed=true +environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419.567701681/CPATH/delimiter=\: +environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419.567701681/CPATH/operation=remove +environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419.567701681/C_INCLUDE_PATH/delimiter=\: +environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419.567701681/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419.567701681/append=true +environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419.567701681/appendContributed=true environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419/CPATH/delimiter=; environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419/CPATH/operation=remove environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.200032419/C_INCLUDE_PATH/delimiter=; @@ -25,6 +31,10 @@ environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.200032419.2005314669/LIBRARY_PATH/operation=remove environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.200032419.2005314669/append=true environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.200032419.2005314669/appendContributed=true +environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.200032419.567701681/LIBRARY_PATH/delimiter=\: +environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.200032419.567701681/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.200032419.567701681/append=true +environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.200032419.567701681/appendContributed=true environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.200032419/LIBRARY_PATH/delimiter=; environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.200032419/LIBRARY_PATH/operation=remove environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.200032419/append=true