Compare commits

...

2 Commits

Author SHA1 Message Date
bee70b76b9 encoder "fast lane" 2026-05-15 16:25:14 +02:00
0609877f9e remove negative windup 2026-05-15 14:02:49 +02:00
2 changed files with 18 additions and 8 deletions

View File

@ -27,13 +27,17 @@
#define NTC_ADC_CHANNEL ANALOG_2 // PA2 #define NTC_ADC_CHANNEL ANALOG_2 // PA2
#define TEMP_ADC_CHANNEL ANALOG_3 // PA3 #define TEMP_ADC_CHANNEL ANALOG_3 // PA3
#define ENCODER_DEBOUNCE 6000 #define ENCODER_INV true
#define ENCODER_FAST 3
#define MAX_BOARD_TEMP 50 #define MAX_BOARD_TEMP 50
#define MAX_TIP_TEMP 500 #define MAX_TIP_TEMP 500
#define TURN_OFF_DELAY 3 #define TURN_OFF_DELAY 3
#define CYCLES_PER_MEASURE 2 #define CYCLES_PER_MEASURE 2
#define BOARD_MAX_VOLTAGE 28000 #define BOARD_MAX_VOLTAGE 28000
#define MIN_TIP_SET_TEMP 100
#define MAX_TIP_SET_TEMP 420
#endif // _FUNCONFIG_H #endif // _FUNCONFIG_H

View File

@ -107,8 +107,14 @@ void update_encoder(void)
// Find the movement direction based on transition // Find the movement direction based on transition
count += state_table[last_state][current_state]; count += state_table[last_state][current_state];
#if ENCODER_INV
if (count == 4) encoder--, count = 0;
if (count == -4) encoder++, count = 0;
#else
if (count == 4) encoder++, count = 0; if (count == 4) encoder++, count = 0;
if (count == -4) encoder--, count = 0; if (count == -4) encoder--, count = 0;
#endif
// Save current state for the next interrupt // Save current state for the next interrupt
last_state = current_state; last_state = current_state;
@ -391,7 +397,7 @@ uint16_t pid(int16_t delta, int16_t max_duty)
// TODO: use a back calculation anti windup strategy // TODO: use a back calculation anti windup strategy
// only integrate if the output is less then max // only integrate if the output is less then max
if (e < i2fp(100)) { if (e < i2fp(100) && e > 0) {
intgrt = fp_add(intgrt, err_i); intgrt = fp_add(intgrt, err_i);
} }
@ -489,6 +495,7 @@ __attribute__((noreturn)) int main(void)
MIN(pd_profile.set_power, pd_profile.power_avail)*pd_profile.tip_r)/1000) * 1000) / pd_profile.voltage MIN(pd_profile.set_power, pd_profile.power_avail)*pd_profile.tip_r)/1000) * 1000) / pd_profile.voltage
, 100); , 100);
#if 0
u8g2_ClearBuffer(u8g2); u8g2_ClearBuffer(u8g2);
u8g2_SetFont(u8g2, u8g2_font_5x8_tr); u8g2_SetFont(u8g2, u8g2_font_5x8_tr);
// Display tip temperature // Display tip temperature
@ -504,7 +511,8 @@ __attribute__((noreturn)) int main(void)
u8g2_DrawStr(u8g2, x_off+45, y_off+15, "D:"); u8g2_DrawStr(u8g2, x_off+45, y_off+15, "D:");
u8g2_DrawStr(u8g2, x_off+55, y_off+15, u8g2_u16toa(pd_profile.max_duty, 3)); u8g2_DrawStr(u8g2, x_off+55, y_off+15, u8g2_u16toa(pd_profile.max_duty, 3));
u8g2_SendBuffer(u8g2); u8g2_SendBuffer(u8g2);
// Delay_Ms(5000); Delay_Ms(5000);
#endif
} }
@ -559,12 +567,10 @@ __attribute__((noreturn)) int main(void)
u8g2_DrawStr(u8g2, x_off+25, y_off+7, u8g2_u16toa(pd_profile.set_temp, 4)); u8g2_DrawStr(u8g2, x_off+25, y_off+7, u8g2_u16toa(pd_profile.set_temp, 4));
if (encoder != 0) { if (encoder != 0) {
pd_profile.set_temp += encoder; pd_profile.set_temp += encoder >= ENCODER_FAST ? 20 : encoder;
encoder = 0; encoder = 0;
#define MIN_TEMP 100 if (pd_profile.set_temp < MIN_TIP_SET_TEMP) pd_profile.set_temp = MIN_TIP_SET_TEMP;
#define MAX_TEMP 360 if (pd_profile.set_temp > MAX_TIP_SET_TEMP) pd_profile.set_temp = MAX_TIP_SET_TEMP;
if (pd_profile.set_temp < MIN_TEMP) pd_profile.set_temp = MIN_TEMP;
if (pd_profile.set_temp > MAX_TEMP) pd_profile.set_temp = MAX_TEMP;
} }
if (btn == 0 && prev_btn == 1) { if (btn == 0 && prev_btn == 1) {