Skip to content

Commit

Permalink
Try and re-tune TS100 and TS80
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralim committed Jul 14, 2019
1 parent c5409f4 commit 4347ed2
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 348 deletions.
2 changes: 1 addition & 1 deletion workspace/TS100/inc/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion workspace/TS100/inc/power.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t, oscillationPeriod> milliWattHistory;

int32_t tempToMilliWatts(int32_t rawTemp, uint8_t rawC);
Expand Down
41 changes: 20 additions & 21 deletions workspace/TS100/src/Setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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);
Expand Down
73 changes: 37 additions & 36 deletions workspace/TS100/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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<int32_t, PID_TIM_HZ / 4> tempError = { { 0 }, 0, 0 };
currentlyActiveTemperatureTarget = 0; // Force start with no output (off). If in sleep / soldering this will
// be over-ridden rapidly
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
24 changes: 4 additions & 20 deletions workspace/TS100/src/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,25 @@
#include <hardware.h>

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<uint32_t, oscillationPeriod> 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);
}
Expand Down
Loading

0 comments on commit 4347ed2

Please sign in to comment.