void PID_Autotuner::begin(TemperatureControl *temp, double target, StreamOutput *stream)
{
if (t)
- t->heater_pin->set(0);
+ t->heater_pin.set(0);
t = temp;
s->printf("%s: Starting PID Autotune\n", t->designator.c_str());
- bias = d = t->heater_pin->max_pwm() >> 1;
+ bias = d = t->heater_pin.max_pwm() >> 1;
output = true;
last_output = true;
// this code taken from http://github.com/ErikZalm/Marlin/blob/Marlin_v1/Marlin/temperature.cpp
bias += (d * (cycles[cycle].ticks_high - cycles[cycle].ticks_low) * (1000.0 / 20.0)) / ((cycles[cycle].ticks_high + cycles[cycle].ticks_low) * (1000.0 / 20.0));
- bias = confine(bias, 20, t->heater_pin->max_pwm() - 20);
- if (bias > (t->heater_pin->max_pwm() / 2))
- d = t->heater_pin->max_pwm() - 1 - bias;
+ bias = confine(bias, 20, t->heater_pin.max_pwm() - 20);
+ if (bias > (t->heater_pin.max_pwm() / 2))
+ d = t->heater_pin.max_pwm() - 1 - bias;
else
d = bias;
// end code from Marlin firmware
cycle++;
if (cycle == PID_AUTOTUNER_CYCLES)
{
- t->heater_pin->set(0);
+ t->heater_pin.set(0);
t->set_desired_temperature(0.0);
// TODO: finish
double tmax_avg = 0.0,
if (output)
{
ticks = ++cycles[cycle].ticks_high;
- t->heater_pin->pwm((t->o = ((bias + d) >> 1)));
+ t->heater_pin.pwm((t->o = ((bias + d) >> 1)));
}
else
{
ticks = ++cycles[cycle].ticks_low;
- t->heater_pin->set((t->o = 0));
+ t->heater_pin.set((t->o = 0));
}
if ((ticks % 16) == 0)
this->set_and_wait_m_code = this->kernel->config->value(temperature_control_checksum, this->name_checksum, set_and_wait_m_code_checksum)->by_default(109)->as_number();
this->get_m_code = this->kernel->config->value(temperature_control_checksum, this->name_checksum, get_m_code_checksum)->by_default(105)->as_number();
this->readings_per_second = this->kernel->config->value(temperature_control_checksum, this->name_checksum, readings_per_second_checksum)->by_default(20)->as_number();
-
+
this->max_pwm = this->kernel->config->value(temperature_control_checksum, this->name_checksum, max_pwm_checksum)->by_default(255)->as_number();
this->designator = this->kernel->config->value(temperature_control_checksum, this->name_checksum, designator_checksum)->by_default(string("T"))->as_string();
o = 0;
// Thermistor pin for ADC readings
- this->thermistor_pin = this->kernel->config->value(temperature_control_checksum, this->name_checksum, thermistor_pin_checksum )->required()->as_pin();
- this->kernel->adc->enable_pin(this->thermistor_pin);
+ this->thermistor_pin.from_string(this->kernel->config->value(temperature_control_checksum, this->name_checksum, thermistor_pin_checksum )->required()->as_string());
+ this->kernel->adc->enable_pin(&thermistor_pin);
// Heater pin
- this->heater_pin = this->kernel->config->value(temperature_control_checksum, this->name_checksum, heater_pin_checksum)->required()->as_pwm()->as_output();
- this->heater_pin->set(0);
+ this->heater_pin.from_string( this->kernel->config->value(temperature_control_checksum, this->name_checksum, heater_pin_checksum)->required()->as_string())->as_output();
+ this->heater_pin.set(0);
- set_low_on_debug(heater_pin->pin->port_number, heater_pin->pin->pin);
+ set_low_on_debug(heater_pin.pin->port_number, heater_pin.pin->pin);
// activate SD-DAC timer
- this->kernel->slow_ticker->attach(1000, this->heater_pin, &Pwm::on_tick);
+ this->kernel->slow_ticker->attach(1000, &heater_pin, &Pwm::on_tick);
// reading tick
this->kernel->slow_ticker->attach( this->readings_per_second, this, &TemperatureControl::thermistor_read_tick );
if (gcode->get_value('S') == 0)
{
this->target_temperature = UNDEFINED;
- this->heater_pin->set(0);
+ this->heater_pin.set(0);
}
else
{
if (gcode->get_value('S') == 0)
{
this->target_temperature = UNDEFINED;
- this->heater_pin->set(0);
+ this->heater_pin.set(0);
}
else
{
void TemperatureControl::set_desired_temperature(double desired_temperature){
target_temperature = desired_temperature;
if (desired_temperature == 0.0)
- heater_pin->set((o = 0));
+ heater_pin.set((o = 0));
}
double TemperatureControl::get_temperature(){
{
if ((r <= 1) || (r >= 4094))
{
- kernel->streams->printf("MINTEMP triggered on P%d.%d! check your thermistors!\n", this->thermistor_pin->port_number, this->thermistor_pin->pin);
+ kernel->streams->printf("MINTEMP triggered on P%d.%d! check your thermistors!\n", this->thermistor_pin.port_number, this->thermistor_pin.pin);
target_temperature = UNDEFINED;
- heater_pin->set(0);
+ heater_pin.set(0);
}
else
{
}
else
{
- heater_pin->set((o = 0));
+ heater_pin.set((o = 0));
}
last_reading = temperature;
return 0;
if (i < -this->i_max)
i = -this->i_max;
- this->o = (p + i + d) * heater_pin->max_pwm() / 256;
+ this->o = (p + i + d) * heater_pin.max_pwm() / 256;
- if (this->o >= heater_pin->max_pwm())
+ if (this->o >= heater_pin.max_pwm())
{
i = 0;
- this->o = heater_pin->max_pwm();
+ this->o = heater_pin.max_pwm();
}
if (this->o < 0)
{
- if (this->o < -(heater_pin->max_pwm()))
+ if (this->o < -(heater_pin.max_pwm()))
i = 0;
this->o = 0;
}
if( this->o > this->max_pwm ){ this->o = max_pwm; }
- this->heater_pin->pwm(o);
+ this->heater_pin.pwm(o);
}
int TemperatureControl::new_thermistor_reading()
{
- int last_raw = this->kernel->adc->read(this->thermistor_pin);
+ int last_raw = this->kernel->adc->read(&thermistor_pin);
if (queue.size() >= queue.capacity())
{
uint16_t l;