time to save, more very minor tweaks during testing runs

This commit is contained in:
Michael Moon 2010-02-08 16:30:14 +11:00
parent f8eee368c4
commit d5c2e0534d
2 changed files with 63 additions and 56 deletions

View File

@ -448,8 +448,13 @@ void process_gcode_command(GCODE_COMMAND *gcmd) {
// M104- set temperature // M104- set temperature
case 104: case 104:
temp_set(gcmd->S); temp_set(gcmd->S);
enable_heater(); if (gcmd->S) {
enable_steppers(); enable_heater();
enable_steppers();
}
else {
disable_heater();
}
break; break;
// M105- get temperature // M105- get temperature

View File

@ -131,69 +131,71 @@ void temp_print() {
} }
void temp_tick() { void temp_tick() {
uint16_t last_temp = current_temp; if (target_temp) {
temp_read(); uint16_t last_temp = current_temp;
temp_read();
// if (DEBUG) // if (DEBUG)
// serial_writestr_P(PSTR("T{")); // serial_writestr_P(PSTR("T{"));
int16_t t_error = target_temp - current_temp; int16_t t_error = target_temp - current_temp;
// if (DEBUG) { // if (DEBUG) {
// serial_writestr_P(PSTR("E:")); // serial_writestr_P(PSTR("E:"));
// serwrite_int16(t_error); // serwrite_int16(t_error);
// } // }
// PID stuff // PID stuff
// proportional // proportional
heater_p = t_error; heater_p = t_error;
// integral // integral
heater_i += t_error; heater_i += t_error;
// prevent integrator wind-up // prevent integrator wind-up
if (heater_i > I_LIMIT) if (heater_i > I_LIMIT)
heater_i = I_LIMIT; heater_i = I_LIMIT;
else if (heater_i < -I_LIMIT) else if (heater_i < -I_LIMIT)
heater_i = -I_LIMIT; heater_i = -I_LIMIT;
// derivative // derivative
// note: D follows temp rather than error so there's no large derivative when the target changes // note: D follows temp rather than error so there's no large derivative when the target changes
heater_d = (current_temp - last_temp); heater_d = (current_temp - last_temp);
// combine factors // combine factors
int32_t pid_output_intermed = ( int32_t pid_output_intermed = (
( (
(((int32_t) heater_p) * p_factor) + (((int32_t) heater_p) * p_factor) +
(((int32_t) heater_i) * i_factor) + (((int32_t) heater_i) * i_factor) +
(((int32_t) heater_d) * d_factor) (((int32_t) heater_d) * d_factor)
) / PID_SCALE ) / PID_SCALE
); );
// rebase and limit factors // rebase and limit factors
uint8_t pid_output; uint8_t pid_output;
if (pid_output_intermed > 127) if (pid_output_intermed > 127)
pid_output = 255; pid_output = 255;
else if (pid_output_intermed < -128) else if (pid_output_intermed < -128)
pid_output = 0; pid_output = 0;
else else
pid_output = (pid_output_intermed + 128); pid_output = (pid_output_intermed + 128);
// if (DEBUG) { // if (DEBUG) {
// serial_writestr_P(PSTR(",O:")); // serial_writestr_P(PSTR(",O:"));
// serwrite_uint8(pid_output); // serwrite_uint8(pid_output);
// } // }
#ifdef HEATER_PWM #ifdef HEATER_PWM
HEATER_PWM = pid_output; HEATER_PWM = pid_output;
#else #else
if (pid_output >= 128) { if (pid_output >= 128) {
enable_heater(); enable_heater();
}
else {
disable_heater();
}
#endif
// if (DEBUG)
// serial_writechar('}');
} }
else {
disable_heater();
}
#endif
// if (DEBUG)
// serial_writechar('}');
} }