Welcome! Log In Create A New Profile

Advanced

MAX6675 Implementation (Marlin vs Repetier)

Posted by lynspyre 
MAX6675 Implementation (Marlin vs Repetier)
September 26, 2015 10:05PM
Hi,

I've managed to setup my MAX6675 module into ramps with Marlin, but i like more the way repetier controls the hardware, but i couldn't get the module working on it.

I've tried to "debug" why this happens, and figured that they use similar codes but writen in different ways. Is there any possibility that Repetier people when re-encoding Amplifiers support had done a mess-up in their code?.

Here are all entries i could found that drive the MAX6675 module on both firmwares.

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)) == 0winking smiley;
  max6675_temp = SPDR;
  max6675_temp <<= 8;
  // read LSB
  SPDR = 0;
  for (; (SPSR & BIT(SPIF)) == 0winking smiley;
  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

P.S.: I have no aknowledgment on Arduino programming, but have some C++ logic, and something tells me that in Repetier code are missing some code.
Sorry, only registered users may post in this forum.

Click here to login