1
0
forked from me/IronOS

Tweak pwm timings, improve Voltage init for more stable startup

This commit is contained in:
Ben V. Brown
2018-11-09 13:14:20 +11:00
parent 18a8461b99
commit c83174862a
6 changed files with 33 additions and 23 deletions

View File

@@ -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

View File

@@ -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;
}
}
}

View File

@@ -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