ConfigValue* Config::value(uint16_t check_sum){
ConfigValue* result = new ConfigValue;
result->check_sum = check_sum;
+ if( this->has_config_file() == false ){
+ return result;
+ }
// Open the config file ( find it if we haven't already found it )
FILE *lp = fopen(this->get_config_file().c_str(), "r");
string buffer;
return result;
}
-// Get the filename for the config file
-string Config::get_config_file(){
- if( this->config_file_found ){ return this->config_file; }
+bool Config::has_config_file(){
+ if( this->config_file_found ){ return true; }
this->try_config_file("/local/config");
this->try_config_file("/sd/config");
if( this->config_file_found ){
+ return true;
+ }else{
+ return false;
+ }
+
+}
+
+// Get the filename for the config file
+string Config::get_config_file(){
+ if( this->config_file_found ){ return this->config_file; }
+ if( this->has_config_file() ){
return this->config_file;
}else{
printf("ERROR: no config file found\r\n");
ConfigValue* value(uint16_t check_sum);
bool has_characters(uint16_t check_sum, string str );
string get_config_file();
+ bool has_config_file();
void try_config_file(string candidate);
string config_file; // Path to the config file
SlowTicker::SlowTicker(){
global_slow_ticker = this;
- LPC_SC->PCONP |= (1 << 22);
- LPC_TIM2->MR0 = 1000000;
- LPC_TIM2->MCR = 3;
- LPC_TIM2->TCR = 1;
- NVIC_EnableIRQ(TIMER2_IRQn);
+ LPC_SC->PCONP |= (1 << 22); // Power Ticker ON
+ LPC_TIM2->MR0 = 1000000; // Initial dummy value for Match Register
+ LPC_TIM2->MCR = 3; // Match on MR0, reset on MR0
+ LPC_TIM2->TCR = 1; // Enable interrupt
+ NVIC_EnableIRQ(TIMER2_IRQn); // Enable interrupt handler
}
void SlowTicker::set_frequency( int frequency ){
- LPC_TIM2->MR0 = int(floor((SystemCoreClock/4)/frequency));
- LPC_TIM2->TCR = 3;
- LPC_TIM2->TCR = 1;
+ LPC_TIM2->MR0 = int(floor((SystemCoreClock/4)/frequency)); // SystemCoreClock/4 = Timer increments in a second
+ LPC_TIM2->TCR = 3; // Reset
+ LPC_TIM2->TCR = 1; // Reset
}
void SlowTicker::tick(){
}
extern "C" void TIMER2_IRQHandler (void){
- if((LPC_TIM2->IR >> 0) & 1){
- LPC_TIM2->IR |= 1 << 0;
+ if((LPC_TIM2->IR >> 0) & 1){ // If interrupt register set for MR0
+ LPC_TIM2->IR |= 1 << 0; // Reset it
global_slow_ticker->tick();
}
}
}
void Planner::on_config_reload(void* argument){
- this->acceleration = this->kernel->config->value(acceleration_checksum )->required()->as_number();
- this->max_jerk = this->kernel->config->value(max_jerk_checksum )->required( )->as_number();
+ this->acceleration = this->kernel->config->value(acceleration_checksum )->by_default(100 )->as_number();
+ this->max_jerk = this->kernel->config->value(max_jerk_checksum )->by_default(100 )->as_number();
this->junction_deviation = this->kernel->config->value(junction_deviation_checksum )->by_default(0.05)->as_number();
}
this->base_stepping_frequency = this->kernel->config->value(base_stepping_frequency_checksum )->by_default(100000)->as_number();
this->step_gpio_port = gpios[(int)this->kernel->config->value(step_gpio_port_checksum )->by_default(0 )->as_number()];
this->dir_gpio_port = gpios[(int)this->kernel->config->value(dir_gpio_port_checksum )->by_default(0 )->as_number()];
- this->alpha_step_pin = this->kernel->config->value(alpha_step_pin_checksum )->required( )->as_number();
- this->beta_step_pin = this->kernel->config->value(beta_step_pin_checksum )->required( )->as_number();
- this->gamma_step_pin = this->kernel->config->value(gamma_step_pin_checksum )->required( )->as_number();
- this->alpha_dir_pin = this->kernel->config->value(alpha_dir_pin_checksum )->required( )->as_number();
- this->beta_dir_pin = this->kernel->config->value(beta_dir_pin_checksum )->required( )->as_number();
- this->gamma_dir_pin = this->kernel->config->value(gamma_dir_pin_checksum )->required( )->as_number();
+ this->alpha_step_pin = this->kernel->config->value(alpha_step_pin_checksum )->by_default(1 )->as_number();
+ this->beta_step_pin = this->kernel->config->value(beta_step_pin_checksum )->by_default(2 )->as_number();
+ this->gamma_step_pin = this->kernel->config->value(gamma_step_pin_checksum )->by_default(3 )->as_number();
+ this->alpha_dir_pin = this->kernel->config->value(alpha_dir_pin_checksum )->by_default(4 )->as_number();
+ this->beta_dir_pin = this->kernel->config->value(beta_dir_pin_checksum )->by_default(5 )->as_number();
+ this->gamma_dir_pin = this->kernel->config->value(gamma_dir_pin_checksum )->by_default(6 )->as_number();
this->step_mask = ( 1 << this->alpha_step_pin ) + ( 1 << this->beta_step_pin ) + ( 1 << this->gamma_step_pin );
this->dir_mask = ( 1 << this->alpha_dir_pin ) + ( 1 << this->beta_dir_pin ) + ( 1 << this->gamma_dir_pin );
this->step_bits[ALPHA_STEPPER ] = this->alpha_step_pin;
// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse of Smoothie. It is executed at the rate set with
// config_step_timer. It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
inline void Stepper::main_interrupt(){
-
+
+ // TODO: Explain this magic
// Step dir pins first, then step pinse, stepper drivers like to know the direction before the step signal comes in
// Clear dir pins
this->dir_gpio_port->FIOSET = this->dir_invert_mask & this->dir_mask;
this->desired_adc_value = UNDEFINED;
// Settings
- this->readings_per_second = 5;
-
- this->r0 = 100000; // Stated resistance eg. 100K
- this->t0 = 25 + 273.15; // Temperature at stated resistance, eg. 25C
- this->beta = 4066; // Thermistor beta rating. See http://reprap.org/bin/view/Main/MeasuringThermistorBeta
- this->vadc = 3.3; // ADC Reference
- this->vcc = 3.3; // Supply voltage to potential divider
- this->k = this->r0 * exp( -this->beta / this->t0 );
- double r1 = 0;
- double r2 = 4700;
-
- if( r1 > 0 ){
- this->vs = r1 * this->vcc / ( r1 + r2 );
- this->rs = r1 * r2 / ( r1 + r2 );
- }else{
- this->vs = this->vcc;
- this->rs = r2;
- }
+ this->on_config_reload(this);
this->acceleration_factor = 10;
}
+
+// Get configuration from the config file
+void TemperatureControl::on_config_reload(void* argument){
+
+ this->readings_per_second = this->kernel->config->value(readings_per_second_ckeckusm )->by_default(5 )->as_number();
+
+ // Values are here : http://reprap.org/wiki/Thermistor
+ // TODO: WARNING : THIS WILL CHANGE and backward compatibility will be broken for config files that use this
+ this->r0 = this->kernel->config->value(temperature_control_r0_ckeckusm )->by_default(100000)->as_number(); // Stated resistance eg. 100K
+ this->t0 = this->kernel->config->value(temperature_control_t0_ckeckusm )->by_default(25 )->as_number() + 273.15; // Temperature at stated resistance, eg. 25C
+ this->beta = this->kernel->config->value(temperature_control_beta_ckeckusm)->by_default(4066 )->as_number(); // Thermistor beta rating. See http://reprap.org/bin/view/Main/MeasuringThermistorBeta
+ this->vadc = this->kernel->config->value(temperature_control_vadc_ckeckusm)->by_default(3.3 )->as_number(); // ADC Reference
+ this->vcc = this->kernel->config->value(temperature_control_vcc_ckeckusm )->by_default(3.3 )->as_number(); // Supply voltage to potential divider
+ this->r1 = this->kernel->config->value(temperature_control_r1_ckeckusm )->by_default(0 )->as_number();
+ this->r2 = this->kernel->config->value(temperature_control_r2_ckeckusm )->by_default(4700 )->as_number();
+
+ this->k = this->r0 * exp( -this->beta / this->t0 );
+
+ if( r1 > 0 ){
+ this->vs = r1 * this->vcc / ( r1 + r2 );
+ this->rs = r1 * r2 / ( r1 + r2 );
+ }else{
+ this->vs = this->vcc;
+ this->rs = r2;
+ }
+
+}
+
void TemperatureControl::on_gcode_execute(void* argument){
Gcode* gcode = static_cast<Gcode*>(argument);
#define UNDEFINED -1
+
+#define temperature_control_r0_ckeckusm 8728
+#define readings_per_second_ckeckusm 18645
+#define temperature_control_t0_ckeckusm 9754
+#define temperature_control_beta_ckeckusm 64275
+#define temperature_control_vadc_ckeckusm 8725
+#define temperature_control_vcc_ckeckusm 4274
+#define temperature_control_r1_ckeckusm 8985
+#define temperature_control_r2_ckeckusm 9242
+
+
+
+
class TemperatureControl : public Module {
public:
TemperatureControl();
void on_module_loaded();
void on_gcode_execute(void* argument);
+ void on_config_reload(void* argument);
void set_desired_temperature(double desired_temperature);
double get_temperature();
double adc_value_to_temperature(double adc_value);
// Thermistor computation settings
double r0;
double t0;
+ double r1;
+ double r2;
double beta;
double vadc;
double vcc;