|
@ -283,6 +283,12 @@ int temp2analog(int celsius, uint8_t e) { |
|
|
SERIAL_ERRORLNPGM(" - Invalid extruder number!"); |
|
|
SERIAL_ERRORLNPGM(" - Invalid extruder number!"); |
|
|
kill(); |
|
|
kill(); |
|
|
} |
|
|
} |
|
|
|
|
|
#ifdef HEATER_0_USES_MAX6675 |
|
|
|
|
|
if (e == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
return celsius * 4; |
|
|
|
|
|
} |
|
|
|
|
|
#endif |
|
|
if(heater_ttbl_map[e] != 0) |
|
|
if(heater_ttbl_map[e] != 0) |
|
|
{ |
|
|
{ |
|
|
int raw = 0; |
|
|
int raw = 0; |
|
@ -353,6 +359,13 @@ float analog2temp(int raw, uint8_t e) { |
|
|
SERIAL_ERRORLNPGM(" - Invalid extruder number !"); |
|
|
SERIAL_ERRORLNPGM(" - Invalid extruder number !"); |
|
|
kill(); |
|
|
kill(); |
|
|
} |
|
|
} |
|
|
|
|
|
#ifdef HEATER_0_USES_MAX6675 |
|
|
|
|
|
if (e == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
return 0.25 * raw; |
|
|
|
|
|
} |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
if(heater_ttbl_map[e] != 0) |
|
|
if(heater_ttbl_map[e] != 0) |
|
|
{ |
|
|
{ |
|
|
float celsius = 0; |
|
|
float celsius = 0; |
|
@ -446,6 +459,22 @@ void tp_init() |
|
|
SET_OUTPUT(FAN_PIN); |
|
|
SET_OUTPUT(FAN_PIN); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifdef HEATER_0_USES_MAX6675 |
|
|
|
|
|
#ifndef SDSUPPORT |
|
|
|
|
|
SET_OUTPUT(MAX_SCK_PIN); |
|
|
|
|
|
WRITE(MAX_SCK_PIN,0); |
|
|
|
|
|
|
|
|
|
|
|
SET_OUTPUT(MAX_MOSI_PIN); |
|
|
|
|
|
WRITE(MAX_MOSI_PIN,1); |
|
|
|
|
|
|
|
|
|
|
|
SET_INPUT(MAX_MISO_PIN); |
|
|
|
|
|
WRITE(MAX_MISO_PIN,1); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
SET_OUTPUT(MAX6675_SS); |
|
|
|
|
|
WRITE(MAX6675_SS,1); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
// 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; |
|
@ -595,6 +624,62 @@ void bed_max_temp_error(void) { |
|
|
SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!"); |
|
|
SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define HEAT_INTERVAL 250 |
|
|
|
|
|
#ifdef HEATER_0_USES_MAX6675 |
|
|
|
|
|
long max6675_previous_millis = -HEAT_INTERVAL; |
|
|
|
|
|
int max6675_temp = 2000; |
|
|
|
|
|
|
|
|
|
|
|
int read_max6675() |
|
|
|
|
|
{ |
|
|
|
|
|
if (millis() - max6675_previous_millis < HEAT_INTERVAL) |
|
|
|
|
|
return max6675_temp; |
|
|
|
|
|
|
|
|
|
|
|
max6675_previous_millis = millis(); |
|
|
|
|
|
max6675_temp = 0; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef PRR |
|
|
|
|
|
PRR &= ~(1<<PRSPI); |
|
|
|
|
|
#elif defined PRR0 |
|
|
|
|
|
PRR0 &= ~(1<<PRSPI); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
SPCR = (1<<MSTR) | (1<<SPE) | (1<<SPR0); |
|
|
|
|
|
|
|
|
|
|
|
// enable TT_MAX6675
|
|
|
|
|
|
WRITE(MAX6675_SS, 0); |
|
|
|
|
|
|
|
|
|
|
|
// ensure 100ns delay - a bit extra is fine
|
|
|
|
|
|
delay(1); |
|
|
|
|
|
|
|
|
|
|
|
// read MSB
|
|
|
|
|
|
SPDR = 0; |
|
|
|
|
|
for (;(SPSR & (1<<SPIF)) == 0;); |
|
|
|
|
|
max6675_temp = SPDR; |
|
|
|
|
|
max6675_temp <<= 8; |
|
|
|
|
|
|
|
|
|
|
|
// read LSB
|
|
|
|
|
|
SPDR = 0; |
|
|
|
|
|
for (;(SPSR & (1<<SPIF)) == 0;); |
|
|
|
|
|
max6675_temp |= SPDR; |
|
|
|
|
|
|
|
|
|
|
|
// disable TT_MAX6675
|
|
|
|
|
|
WRITE(MAX6675_SS, 1); |
|
|
|
|
|
|
|
|
|
|
|
if (max6675_temp & 4) |
|
|
|
|
|
{ |
|
|
|
|
|
// thermocouple open
|
|
|
|
|
|
max6675_temp = 2000; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
max6675_temp = max6675_temp >> 3; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return max6675_temp; |
|
|
|
|
|
} |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Timer 0 is shared with millies
|
|
|
// Timer 0 is shared with millies
|
|
|
ISR(TIMER0_COMPB_vect) |
|
|
ISR(TIMER0_COMPB_vect) |
|
|
{ |
|
|
{ |
|
@ -653,6 +738,9 @@ ISR(TIMER0_COMPB_vect) |
|
|
#if (TEMP_0_PIN > -1) |
|
|
#if (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
|
|
@ -732,7 +820,7 @@ ISR(TIMER0_COMPB_vect) |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#if EXTRUDERS > 1 |
|
|
#if EXTRUDERS > 1 |
|
|
#ifdef HEATER_1_USES_AD595 |
|
|
#ifdef HEATER_1_USES_AD595 || defined HEATER_0_USES_MAX6675 |
|
|
current_raw[1] = raw_temp_1_value; |
|
|
current_raw[1] = raw_temp_1_value; |
|
|
#else |
|
|
#else |
|
|
current_raw[1] = 16383 - raw_temp_1_value; |
|
|
current_raw[1] = 16383 - raw_temp_1_value; |
|
|