Borrow from Ultimaker to fix MAX6675 SPI conflict

Changes to temperature.cpp from Ultimaker fork, intended to address
#1226 and #1227
master
Scott Lahteine 10 years ago
parent 9040446780
commit e770489f27

@ -904,7 +904,7 @@
#define SCK_PIN 52 #define SCK_PIN 52
#define MISO_PIN 50 #define MISO_PIN 50
#define MOSI_PIN 51 #define MOSI_PIN 51
#define MAX6675_SS 66// Do not use pin 53 if there is even the remote possibility of using Dsplay/SD card #define MAX6675_SS 66// Do not use pin 53 if there is even the remote possibility of using Display/SD card
#else #else
#define MAX6675_SS 66// Do not use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present #define MAX6675_SS 66// Do not use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present
#endif #endif

@ -177,6 +177,11 @@ unsigned long watchmillis[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0);
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
static int meas_shift_index; //used to point to a delayed sample in buffer for filament width sensor static int meas_shift_index; //used to point to a delayed sample in buffer for filament width sensor
#endif #endif
#ifdef HEATER_0_USES_MAX6675
static int read_max6675();
#endif
//=========================================================================== //===========================================================================
//============================= functions ============================ //============================= functions ============================
//=========================================================================== //===========================================================================
@ -448,6 +453,15 @@ void manage_heater()
updateTemperaturesFromRawValues(); updateTemperaturesFromRawValues();
#ifdef HEATER_0_USES_MAX6675
if (current_temperature[0] > 1023 || current_temperature[0] > HEATER_0_MAXTEMP) {
max_temp_error(0);
}
if (current_temperature[0] == 0 || current_temperature[0] < HEATER_0_MINTEMP) {
min_temp_error(0);
}
#endif //HEATER_0_USES_MAX6675
for(int e = 0; e < EXTRUDERS; e++) for(int e = 0; e < EXTRUDERS; e++)
{ {
@ -757,6 +771,9 @@ static float analog2tempBed(int raw) {
and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */ and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
static void updateTemperaturesFromRawValues() static void updateTemperaturesFromRawValues()
{ {
#ifdef HEATER_0_USES_MAX6675
current_temperature_raw[0] = read_max6675();
#endif
for(uint8_t e=0;e<EXTRUDERS;e++) for(uint8_t e=0;e<EXTRUDERS;e++)
{ {
current_temperature[e] = analog2temp(current_temperature_raw[e], e); current_temperature[e] = analog2temp(current_temperature_raw[e], e);
@ -851,6 +868,7 @@ void tp_init()
#endif #endif
#ifdef HEATER_0_USES_MAX6675 #ifdef HEATER_0_USES_MAX6675
#ifndef SDSUPPORT #ifndef SDSUPPORT
SET_OUTPUT(SCK_PIN); SET_OUTPUT(SCK_PIN);
WRITE(SCK_PIN,0); WRITE(SCK_PIN,0);
@ -860,16 +878,16 @@ void tp_init()
SET_INPUT(MISO_PIN); SET_INPUT(MISO_PIN);
WRITE(MISO_PIN,1); WRITE(MISO_PIN,1);
#endif #else
/* Using pinMode and digitalWrite, as that was the only way I could get it to compile */
//Have to toggle SD card CS pin to low first, to enable firmware to talk with SD card
pinMode(SS_PIN, OUTPUT); pinMode(SS_PIN, OUTPUT);
digitalWrite(SS_PIN,0); digitalWrite(SS_PIN, HIGH);
pinMode(MAX6675_SS, OUTPUT);
digitalWrite(MAX6675_SS,1);
#endif #endif
SET_OUTPUT(MAX6675_SS);
WRITE(MAX6675_SS,1);
#endif //HEATER_0_USES_MAX6675
// Set analog inputs // Set analog inputs
ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07; ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
DIDR0 = 0; DIDR0 = 0;
@ -1167,7 +1185,7 @@ void bed_max_temp_error(void) {
long max6675_previous_millis = MAX6675_HEAT_INTERVAL; long max6675_previous_millis = MAX6675_HEAT_INTERVAL;
int max6675_temp = 2000; int max6675_temp = 2000;
int read_max6675() static int read_max6675()
{ {
if (millis() - max6675_previous_millis < MAX6675_HEAT_INTERVAL) if (millis() - max6675_previous_millis < MAX6675_HEAT_INTERVAL)
return max6675_temp; return max6675_temp;
@ -1177,7 +1195,7 @@ int read_max6675()
#ifdef PRR #ifdef PRR
PRR &= ~(1<<PRSPI); PRR &= ~(1<<PRSPI);
#elif defined PRR0 #elif defined(PRR0)
PRR0 &= ~(1<<PRSPI); PRR0 &= ~(1<<PRSPI);
#endif #endif
@ -1207,7 +1225,7 @@ int read_max6675()
if (max6675_temp & 4) if (max6675_temp & 4)
{ {
// thermocouple open // thermocouple open
max6675_temp = 2000; max6675_temp = 4000;
} }
else else
{ {
@ -1216,7 +1234,8 @@ int read_max6675()
return max6675_temp; return max6675_temp;
} }
#endif
#endif //HEATER_0_USES_MAX6675
// Timer 0 is shared with millies // Timer 0 is shared with millies
@ -1554,9 +1573,6 @@ ISR(TIMER0_COMPB_vect)
#if defined(TEMP_0_PIN) && (TEMP_0_PIN > -1) #if defined(TEMP_0_PIN) && (TEMP_0_PIN > -1)
raw_temp_0_value += ADC; raw_temp_0_value += ADC;
#endif #endif
#ifdef HEATER_0_USES_MAX6675 // TODO remove the blocking
raw_temp_0_value = read_max6675();
#endif
temp_state = 2; temp_state = 2;
break; break;
case 2: // Prepare TEMP_BED case 2: // Prepare TEMP_BED
@ -1659,7 +1675,9 @@ ISR(TIMER0_COMPB_vect)
{ {
if (!temp_meas_ready) //Only update the raw values if they have been read. Else we could be updating them during reading. if (!temp_meas_ready) //Only update the raw values if they have been read. Else we could be updating them during reading.
{ {
#ifndef HEATER_0_USES_MAX6675
current_temperature_raw[0] = raw_temp_0_value; current_temperature_raw[0] = raw_temp_0_value;
#endif
#if EXTRUDERS > 1 #if EXTRUDERS > 1
current_temperature_raw[1] = raw_temp_1_value; current_temperature_raw[1] = raw_temp_1_value;
#endif #endif
@ -1690,14 +1708,18 @@ ISR(TIMER0_COMPB_vect)
#else #else
if(current_temperature_raw[0] >= maxttemp_raw[0]) { if(current_temperature_raw[0] >= maxttemp_raw[0]) {
#endif #endif
#ifndef HEATER_0_USES_MAX6675
max_temp_error(0); max_temp_error(0);
#endif
} }
#if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
if(current_temperature_raw[0] >= minttemp_raw[0]) { if(current_temperature_raw[0] >= minttemp_raw[0]) {
#else #else
if(current_temperature_raw[0] <= minttemp_raw[0]) { if(current_temperature_raw[0] <= minttemp_raw[0]) {
#endif #endif
#ifndef HEATER_0_USES_MAX6675
min_temp_error(0); min_temp_error(0);
#endif
} }
#if EXTRUDERS > 1 #if EXTRUDERS > 1
#if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP #if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP

Loading…
Cancel
Save