MAX6675 Implementation (Marlin vs Repetier) September 26, 2015 10:05PM |
Registered: 8 years ago Posts: 14 |
Marlin #if ENABLED(HEATER_0_USES_MAX6675) static int read_max6675(); #endif ---- #if ENABLED(HEATER_0_USES_MAX6675) float ct = current_temperature[0]; if (ct > min(HEATER_0_MAXTEMP, 1023)) max_temp_error(0); if (ct < max(HEATER_0_MINTEMP, 0.01)) min_temp_error(0); #endif ---- #if ENABLED(HEATER_0_USES_MAX6675) if (e == 0) return 0.25 * raw; #endif ---- #if ENABLED(HEATER_0_USES_MAX6675) current_temperature_raw[0] = read_max6675(); #endif ---- #if ENABLED(HEATER_0_USES_MAX6675) #if DISABLED(SDSUPPORT) OUT_WRITE(SCK_PIN, LOW); OUT_WRITE(MOSI_PIN, HIGH); OUT_WRITE(MISO_PIN, HIGH); #else pinMode(SS_PIN, OUTPUT); digitalWrite(SS_PIN, HIGH); #endif OUT_WRITE(MAX6675_SS, HIGH); #endif //HEATER_0_USES_MAX6675 ---- #if ENABLED(HEATER_0_USES_MAX6675) #define MAX6675_HEAT_INTERVAL 250u static millis_t next_max6675_ms = 0; int max6675_temp = 2000; static int read_max6675() { millis_t ms = millis(); if (ms < next_max6675_ms) return max6675_temp; next_max6675_ms = ms + MAX6675_HEAT_INTERVAL; max6675_temp = 0; #ifdef PRR PRR &= ~BIT(PRSPI); #elif defined(PRR0) PRR0 &= ~BIT(PRSPI); #endif SPCR = BIT(MSTR) | BIT(SPE) | BIT(SPR0); // enable TT_MAX6675 WRITE(MAX6675_SS, 0); // ensure 100ns delay - a bit extra is fine asm("nop");//50ns on 20Mhz, 62.5ns on 16Mhz asm("nop");//50ns on 20Mhz, 62.5ns on 16Mhz // read MSB SPDR = 0; for (; (SPSR & BIT(SPIF)) == 0; max6675_temp = SPDR; max6675_temp <<= 8; // read LSB SPDR = 0; for (; (SPSR & BIT(SPIF)) == 0; max6675_temp |= SPDR; // disable TT_MAX6675 WRITE(MAX6675_SS, 1); if (max6675_temp & 4) { // thermocouple open max6675_temp = 4000; } else max6675_temp = max6675_temp >> 3; return max6675_temp; } #endif //HEATER_0_USES_MAX6675
Repetier #ifdef SUPPORT_MAX6675 extern int16_t read_max6675(uint8_t ss_pin); #endif ---- #if defined(SUPPORT_MAX6675) || defined(SUPPORT_MAX31855) if(act->tempControl.sensorType == 101 || act->tempControl.sensorType == 102) { WRITE(SCK_PIN, 0); SET_OUTPUT(SCK_PIN); WRITE(MOSI_PIN, 1); SET_OUTPUT(MOSI_PIN); WRITE(MISO_PIN, 1); SET_INPUT(MISO_PIN); SET_OUTPUT(SS); WRITE(SS, HIGH); HAL::digitalWrite(act->tempControl.sensorPin, 1); HAL::pinMode(act->tempControl.sensorPin, OUTPUT); } #endif ---- #ifdef SUPPORT_MAX6675 case 101: // MAX6675 currentTemperature = read_max6675(sensorPin); break; #endif ---- #ifdef SUPPORT_MAX6675 case 101: // MAX6675 currentTemperatureC = (float)currentTemperature / 4.0; break; #endif ---- #ifdef SUPPORT_MAX6675 case 101: // defined HEATER_USES_MAX6675 targetTemperature = temp * 4; break; #endif ---- #ifdef SUPPORT_MAX6675 int16_t read_max6675(uint8_t ss_pin) { int16_t max6675_temp = 0; HAL::spiInit(2); HAL::digitalWrite(ss_pin, 0); // enable TT_MAX6675 HAL::delayMicroseconds(250); // ensure 100ns delay - a bit extra is fine max6675_temp = HAL::spiReceive(0); max6675_temp <<= 8; max6675_temp |= HAL::spiReceive(0); HAL::digitalWrite(ss_pin, 1); // disable TT_MAX6675 return max6675_temp & 4 ? 2000 : max6675_temp >> 3; // thermocouple open? } #endif