Change K1 to required option PID_K1

This commit is contained in:
Richard Wackerbarth
2017-12-01 09:08:30 -06:00
committed by Scott Lahteine
parent 9e3fbcf35c
commit c1184552ac
47 changed files with 150 additions and 151 deletions

View File

@@ -49,10 +49,6 @@
#include "../feature/filwidth.h"
#endif
#ifdef K1 // Defined in Configuration.h in the PID settings
#define K2 (1.0-K1)
#endif
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
@@ -603,7 +599,7 @@ float Temperature::get_pid_output(const int8_t e) {
#if ENABLED(PIDTEMP)
#if DISABLED(PID_OPENLOOP)
pid_error[HOTEND_INDEX] = target_temperature[HOTEND_INDEX] - current_temperature[HOTEND_INDEX];
dTerm[HOTEND_INDEX] = K2 * PID_PARAM(Kd, HOTEND_INDEX) * (current_temperature[HOTEND_INDEX] - temp_dState[HOTEND_INDEX]) + K1 * dTerm[HOTEND_INDEX];
dTerm[HOTEND_INDEX] = PID_K2 * PID_PARAM(Kd, HOTEND_INDEX) * (current_temperature[HOTEND_INDEX] - temp_dState[HOTEND_INDEX]) + PID_K1 * dTerm[HOTEND_INDEX];
temp_dState[HOTEND_INDEX] = current_temperature[HOTEND_INDEX];
#if HEATER_IDLE_HANDLER
if (heater_idle_timeout_exceeded[HOTEND_INDEX]) {
@@ -700,7 +696,7 @@ float Temperature::get_pid_output(const int8_t e) {
temp_iState_bed += pid_error_bed;
iTerm_bed = bedKi * temp_iState_bed;
dTerm_bed = K2 * bedKd * (current_temperature_bed - temp_dState_bed) + K1 * dTerm_bed;
dTerm_bed = PID_K2 * bedKd * (current_temperature_bed - temp_dState_bed) + PID_K1 * dTerm_bed;
temp_dState_bed = current_temperature_bed;
pid_output = pTerm_bed + iTerm_bed - dTerm_bed;

View File

@@ -88,6 +88,17 @@ enum ADCSensorState {
#define ACTUAL_ADC_SAMPLES max(int(MIN_ADC_ISR_LOOPS), int(SensorsReady))
#if HAS_PID_HEATING
#define PID_K2 (1.0-PID_K1)
#define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / (F_CPU / 64.0 / 256.0))
// Apply the scale factors to the PID values
#define scalePID_i(i) ( (i) * PID_dT )
#define unscalePID_i(i) ( (i) / PID_dT )
#define scalePID_d(d) ( (d) / PID_dT )
#define unscalePID_d(d) ( (d) * PID_dT )
#endif
#if !HAS_HEATER_BED
constexpr int16_t target_temperature_bed = 0;
#endif
@@ -116,10 +127,6 @@ class Temperature {
soft_pwm_count_fan[FAN_COUNT];
#endif
#if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED)
#define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / TEMP_TIMER_FREQUENCY)
#endif
#if ENABLED(PIDTEMP)
#if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
@@ -140,12 +147,6 @@ class Temperature {
#endif // PID_PARAMS_PER_HOTEND
// Apply the scale factors to the PID values
#define scalePID_i(i) ( (i) * PID_dT )
#define unscalePID_i(i) ( (i) / PID_dT )
#define scalePID_d(d) ( (d) / PID_dT )
#define unscalePID_d(d) ( (d) * PID_dT )
#endif
#if ENABLED(PIDTEMPBED)
@@ -431,10 +432,10 @@ class Temperature {
#if HAS_PID_HEATING
static void PID_autotune(const float temp, const int8_t hotend, const int8_t ncycles, const bool set_result=false);
/**
* Update the temp manager when PID values change
*/
#if ENABLED(PIDTEMP)
/**
* Update the temp manager when PID values change
*/
FORCE_INLINE static void updatePID() {
#if ENABLED(PID_EXTRUSION_SCALING)
last_e_position = 0;