From: <adr...@us...> - 2010-07-25 22:10:46
|
Revision: 3662 http://reprap.svn.sourceforge.net/reprap/?rev=3662&view=rev Author: adrian-bowyer Date: 2010-07-25 22:10:40 +0000 (Sun, 25 Jul 2010) Log Message: ----------- Added heated bed code to Mega firmware. Modified Paths: -------------- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.h trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.pde trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/pins.h trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde Added Paths: ----------- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.h trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.pde Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde 2010-07-24 17:47:20 UTC (rev 3661) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/FiveD_GCode_Interpreter.pde 2010-07-25 22:10:40 UTC (rev 3662) @@ -8,6 +8,7 @@ #include "pins.h" #include "Temperature.h" #include "pid.h" +#include "bed.h" #include "extruder.h" #include "cartesian_dda.h" @@ -92,6 +93,8 @@ #endif +static bed heatedBed(BED_HEATER_PIN, BED_TEMPERATURE_PIN); + // Each entry in the buffer is an instance of cartesian_dda. cartesian_dda* cdda[BUFFER_SIZE]; @@ -217,12 +220,22 @@ for(;;); } + +// Keep all extruders, bed, up to temperature etc. + +void manage() +{ + for(byte i = 0; i < EXTRUDER_COUNT; i++) + ex[i]->manage(); + heatedBed.manage(); +} + //long count = 0; //int ct1 = 0; void loop() { - manageAllExtruders(); + manage(); get_and_do_command(); #if MOTHERBOARD == 2 talker.tick(); Added: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.h =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.h (rev 0) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.h 2010-07-25 22:10:40 UTC (rev 3662) @@ -0,0 +1,35 @@ +#ifndef BED_H +#define BED_H + +class bed +{ + +public: + bed(byte heat, byte temp); + void waitForTemperature(); + + void setTemperature(int temp); + int getTemperature(); + void slowManage(); + void manage(); + void shutdown(); + +private: + + int targetTemperature; + int count; + int oldT, newT; + long manageCount; + + PIDcontrol* bedPID; // Temperature control - extruder... + + int sampleTemperature(); + void controlTemperature(); + void temperatureError(); + +// The pins we control + byte heater_pin, temp_pin; + +}; + +#endif Added: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.pde =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.pde (rev 0) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/bed.pde 2010-07-25 22:10:40 UTC (rev 3662) @@ -0,0 +1,120 @@ +static PIDcontrol bPID(BED_HEATER_PIN, BED_TEMPERATURE_PIN, false); + + +bed::bed(byte heat, byte temp) +{ + heater_pin = heat; + temp_pin = temp; + + manageCount = 0; + bedPID = &bPID; + + //setup our pins + + pinMode(heater_pin, OUTPUT); + pinMode(temp_pin, INPUT); + + analogWrite(heater_pin, 0); + + //these our the default values for the extruder. + + targetTemperature = 0; + + setTemperature(targetTemperature); +} + +void bed::controlTemperature() +{ + bedPID->pidCalculation(targetTemperature); +} + + + +void bed::slowManage() +{ + manageCount = 0; + + controlTemperature(); +} + +void bed::manage() +{ + manageCount++; + if(manageCount > SLOW_CLOCK) + slowManage(); +} + +// Stop everything + +void bed::shutdown() +{ + setTemperature(0); + bedPID->shutdown(); +} + +void bed::setTemperature(int tp) +{ + bedPID->reset(); + targetTemperature = tp; +} + +int bed::getTemperature() +{ + return bedPID->temperature(); +} + + +void bed::waitForTemperature() +{ + byte seconds = 0; + bool warming = true; + count = 0; + newT = 0; + oldT = newT; + + while (true) + { + newT += getTemperature(); + count++; + if(count > 5) + { + newT = newT/5; + if(newT >= targetTemperature - HALF_DEAD_ZONE) + { + warming = false; + if(seconds > WAIT_AT_TEMPERATURE) + return; + else + seconds++; + } + + if(warming) + { + if(newT > oldT) + oldT = newT; + else + { + // Temp isn't increasing - extruder hardware error + temperatureError(); + return; + } + } + + newT = 0; + count = 0; + } + for(int i = 0; i < 1000; i++) + { + manage(); + delay(1); + } + } +} + +// TODO: Should use debugstring[] + +void bed::temperatureError() +{ + Serial.print("E: "); + Serial.println(getTemperature()); +} Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.h =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.h 2010-07-24 17:47:20 UTC (rev 3661) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.h 2010-07-25 22:10:40 UTC (rev 3662) @@ -393,8 +393,6 @@ PIDcontrol* extruderPID; // Temperature control - extruder... - byte wait_till_hot(); - //byte wait_till_cool(); int sampleTemperature(); void temperatureError(); Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.pde =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.pde 2010-07-24 17:47:20 UTC (rev 3661) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/extruder.pde 2010-07-25 22:10:40 UTC (rev 3662) @@ -5,15 +5,8 @@ #include "intercom.h" #include "extruder.h" -// Keep all extruders up to temperature etc. -void manageAllExtruders() -{ - for(byte i = 0; i < EXTRUDER_COUNT; i++) - ex[i]->manage(); -} - // Select a new extruder void newExtruder(byte e) @@ -75,7 +68,7 @@ } for(int i = 0; i < 1000; i++) { - manageAllExtruders(); + manage(); delay(1); } } @@ -168,32 +161,6 @@ } -/* -byte extruder::wait_till_cool() - { - count = 0; - oldT = get_temperature(); - while (get_temperature() > target_celsius + HALF_DEAD_ZONE) - { - manage_all_extruders(); - count++; - if(count > 20) - { - newT = get_temperature(); - if(newT < oldT) - oldT = newT; - else - return 1; - count = 0; - } - delay(1000); - } - return 0; - } - */ - - - void extruder::valveSet(bool open, int dTime) { waitForTemperature(); Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/pins.h =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/pins.h 2010-07-24 17:47:20 UTC (rev 3661) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/pins.h 2010-07-25 22:10:40 UTC (rev 3662) @@ -172,8 +172,8 @@ // Heated bed -#define BED_HEATER_PIN (byte)1 -#define BED_TEMPERATURE_PIN (byte)2 +#define BED_HEATER_PIN (byte)3 +#define BED_TEMPERATURE_PIN (byte)1 //extruder pins @@ -188,7 +188,7 @@ #define EXTRUDER_1_DIR_PIN (byte)5 #define EXTRUDER_1_ENABLE_PIN (byte)6 #define EXTRUDER_1_HEATER_PIN (byte)13 -#define EXTRUDER_1_TEMPERATURE_PIN (byte)1 +#define EXTRUDER_1_TEMPERATURE_PIN (byte)2 #else Modified: trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde =================================================================== --- trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde 2010-07-24 17:47:20 UTC (rev 3661) +++ trunk/mendel/firmware/FiveD_GCode/FiveD_GCode_Interpreter/process_g_code.pde 2010-07-25 22:10:40 UTC (rev 3662) @@ -553,7 +553,7 @@ Serial.println(ex[0]->getBedTemperature()); #else Serial.print(" B:"); - Serial.println("0"); // TODO: bed temp needed + Serial.println(heatedBed.getTemperature()); // TODO: bed temp needed #endif break; @@ -644,7 +644,7 @@ ex[0]->setBedTemperature((int)gc.S); #endif #if MOTHERBOARD == 3 - // TODO: setBedTemperature((int)gc.S); + heatedBed.setTemperature((int)gc.S); #endif } break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |