MarlinFirmware / Marlin

Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
https://marlinfw.org
GNU General Public License v3.0
16.33k stars 19.25k forks source link

When compiling Marlin RC7 or the newest RCBugFix with MAX31855, Marlin goes into some kind of loop and doesn't respond any more #4938

Closed derletztename closed 8 years ago

derletztename commented 8 years ago

When I try to use Marlin on my RAMPS 1.4 EFB with the MAX31855 thermocouple board and the thermocouple after compiling and uploading, Marlin goes into some kind of loop and I can't connect with pronterface. Also I can't upload anything again unless I upload just in the tiny moment after plugging the Arduino into my PC. This happens with Marlin RC7 and RCBugFix on every Arduino I tested with and without RAMPS. And it only happens when I compile Marlin with the "-3" for MAX31855 support. Maybe someone could figure out, what is wrong? I'm printing metal, I need to measure high temperatures :(

//// Temperature sensor settings:
// -3 is thermocouple with MAX31855 (only for sensor 0)
thinkyhead commented 8 years ago

The most likely thing getting stuck related to that thermocouple is the reading of the MAX31855 itself. The loop which reads the bits will stick if it never gets all 4 bytes. So perhaps it's an issue of timing. The read speed for the MAX31855 is 4x the rate of the MAX6675, so possibly the initial delay is too large. Try editing the method Temperature::read_max6675 in temperature.cpp and removing one of these two "nop" lines…

    // 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
derletztename commented 8 years ago

I am not a coder and I have no idea what it really means that you just told me, but I will try this out and post my experiences. Thank you :)

thinkyhead commented 8 years ago

I hear ya – I've never been to Moscow. Let me know if the suggestion helps.

derletztename commented 8 years ago

It did not change anything at all, as it seem :(

Actually both ICs look very similar: https://cdn-shop.adafruit.com/datasheets/MAX31855.pdf https://cdn-shop.adafruit.com/datasheets/MAX6675.pdf

The only easy to see difference is: MAX6675 The data is output in a 12-bit resolution, SPI™-compatible, read-only format. MAX31855 The data is output in a signed 14-bit, SPI-compatible, read-only format.

Also the MAX6675 can only work with type-K thermocouples and the MAX31855 works with several thermocouple types, which is why I am trying to use it...

Is this a problem for Marlin somehow, that it treats both ICs the same? 12-bit resolution and signed 14-bit?

derletztename commented 8 years ago

Here are two Arduino Librarys for the MAX6675 and the MAX31855. Maybe the difference in the code helps fixing the Marlin Issues? https://learn.adafruit.com/thermocouple/using-a-thermocouple

derletztename commented 8 years ago

The MAX31855 code is twice the lines than the MAX6675. Also it looks different. Nevertheless it's still russian to me :(

Grogyan commented 8 years ago

In temperature,cpp line 1293

define MAX6675_SPEED_BITS (_BV(SPR1)) // clock ÷ 64

You can try changing SPR1 to SPR0. This increases the clock rate for the MAX31855, but you may end up with erranous values at times.

Can you please post your configuration.h file.

Also if you are in a particuarly noisy location, you may have spikes on the data/clock lines or even the thermocouple itself. Also note that that you need to plug in the 5V from RAMPS to the 5V pin on the MAX31855 board, not the 3V3 rail, as that is an output .

derletztename commented 8 years ago

config_h.txt

derletztename commented 8 years ago

I am not using the IC directly, I am using the Adafruit breakout board https://www.adafruit.com/index.php?main_page=product_info&products_id=269&zenid=516505f41182f3a344fea2f8955968e0

Grogyan commented 8 years ago

This line should be uncommented

//#define THERMAL_PROTECTION_HOTENDS // Enable thermal protection for all extruders

This line should be a lower value

#define HEATER_0_MAXTEMP 1650

K type typically has a 500 degree upper limit, what thermocouple are you actually using?

derletztename commented 8 years ago

I'm printing Steel, it's very experimental ;) For the first experiments I only used a small amount of power and therefore it's heating up very slow. That's a problem for the thermal runaway...

derletztename commented 8 years ago

The System can melt steel easily, but I wasn't able to measure higher temperatures above 1350°C, as I can't get that stupid MAX31855 to work :(

Grogyan commented 8 years ago

@derletztename what thermocouple are you using?

This from the adafruit site Works with any K type thermocouple Will not work with any other kind of thermocouple other than K type

derletztename commented 8 years ago

started with a thermocouple type k, and now i am trying to use a thermocouple type s, which only works with the MAX31855. I have the breakout board with a thermocouple type k for testing, but also changed the IC on another board and try to use it with a chinese thermocouple type S...

derletztename commented 8 years ago

Here is a picture of the system melting steel wire: wp_20160610_22_34_49_rich

Grogyan commented 8 years ago

https://datasheets.maximintegrated.com/en/ds/MAX31855.pdf

package for S type thermocouple should be MAX31855SASA+T

derletztename commented 8 years ago

I asked the adafruit technicans. They say if you change the chip (solder, unsolder) it's suppose to work. Nevertheless it's not even working with the type k thermocouple without changing anything. I bought 2 breakout boards to tests this

derletztename commented 8 years ago

I postet the same pdf^^

Grogyan commented 8 years ago

The max6675 also has an alternate type of package

on the SO8 it should read MAX31855S whereas the original chip marking reads MAX31855K The K and S are the cold junction offsets within the device

Grogyan commented 8 years ago

Can you also please post a photo of your thermocouple boards?

derletztename commented 8 years ago

https://cdn-shop.adafruit.com/datasheets/MAX6675.pdf says it's only reading type K thermocouples. Or how do you mean alternate type of package?

derletztename commented 8 years ago

I use the adafruit board. https://www.adafruit.com/index.php?main_page=product_info&products_id=269&zenid=516505f41182f3a344fea2f8955968e0 and plugged it in as said on their site

Grogyan commented 8 years ago

My mistake, I thought there was another variant of the 6675 for different thermocouples

derletztename commented 8 years ago

Man, you brought up hopes :( Is there hope to get the MAX31855 running?

Grogyan commented 8 years ago

Indeed, I suggest first using an unmodified MAX31855 board and use a fresh copy of the Marlin firmware

derletztename commented 8 years ago

I did. I bought 2 breakout boards and only modified one. I am trying to get it working with the unmodified board and I hardly changed anything in the Marlin RC and RCBugFix edition. The error also happens without the RAMPS plugged in the Arduino. But the error do not happen without the -3 for the MAX31855 board set. So it must be an error in the Marlin code I guess

derletztename commented 8 years ago

Just try this, download a new copy of Marlin and compile it with the -3 for the MAX31855 and see if you can connect to your Arduino afterwards. For me it don't work with pronterface nor with the Arduino software itself anymore. The only workaround is to upload another code just after plugging the Arduino in

Grogyan commented 8 years ago

I can't try that out till late tonight when I get home from work

Blue-Marlin commented 8 years ago

Might not bee very interesting for your problem. To make negative temperature readings correct with a MAX31855, these chanes are needed. Shifting right a negative unsigned will not shift in the needed 1s but always 0s (what makes them high positives).

@@ -1295,16 +1295,16 @@ void Temperature::disable_all_heaters() {
 #if ENABLED(HEATER_0_USES_MAX6675)

   #define MAX6675_HEAT_INTERVAL 250u

   #if ENABLED(MAX6675_IS_MAX31855)
-    uint32_t max6675_temp = 2000;
+    int32_t max6675_temp = 2000;
     #define MAX6675_ERROR_MASK 7
     #define MAX6675_DISCARD_BITS 18
     #define MAX6675_SPEED_BITS (_BV(SPR1)) // clock ÷ 64
   #else
-    uint16_t max6675_temp = 2000;
+    int16_t max6675_temp = 2000;
     #define MAX6675_ERROR_MASK 4
     #define MAX6675_DISCARD_BITS 3
     #define MAX6675_SPEED_BITS (_BV(SPR0)) // clock ÷ 16
   #endif

@@ -1347,11 +1347,11 @@ void Temperature::disable_all_heaters() {
     if (max6675_temp & MAX6675_ERROR_MASK)
       max6675_temp = 4000; // thermocouple open
     else
       max6675_temp >>= MAX6675_DISCARD_BITS;

-    return (int)max6675_temp;
+    return max6675_temp;
   }

 #endif //HEATER_0_USES_MAX6675
Blue-Marlin commented 8 years ago

For analysing the problem

@@ -1343,11 +1343,31 @@ void Temperature::disable_all_heaters() {
     }

     WRITE(MAX6675_SS, 1); // disable TT_MAX6675

     if (max6675_temp & MAX6675_ERROR_MASK)
-      max6675_temp = 4000; // thermocouple open
+     #if ENABLED(MAX6675_IS_MAX31855)
+     if (max6675_temp & 1) {
+       SERIAL_ERROR_START;
+        SERIAL_ERRORLNPGM("Temp measurement error! MAX31855 Open Circuit");
+     }
+     if (max6675_temp & 2) {
+       SERIAL_ERROR_START;
+        SERIAL_ERRORLNPGM("Temp measurement error! MAX31855 Short to GND");
+     }
+     if (max6675_temp & 4) {
+       SERIAL_ERROR_START;
+        SERIAL_ERRORLNPGM("Temp measurement error! MAX31855 Short to VCC");
+     }
+     #else
+     if (max6675_temp & 4) {
+       SERIAL_ERROR_START;
+        SERIAL_ERRORLNPGM("Temp measurement error! MAX6675");
+     }
+     #endif
+      //max6675_temp = 4000; // thermocouple open
+      max6675_temp = 25; // JUST TO AVOID THE KILL!!! Don't use in production.
     else
       max6675_temp >>= MAX6675_DISCARD_BITS;

     return (int)max6675_temp;
   }

might help.

Wo bist den Du in Deutschland?

derletztename commented 8 years ago

Nähe Köln/Bonn. Über Support vor Ort würde ich mich seeehr freuen ;)

derletztename commented 8 years ago

endif

+      //max6675_temp = 4000; // thermocouple open
+      max6675_temp = 25; // JUST TO AVOID THE KILL!!! Don't use in production.
     else
       max6675_temp >>= MAX6675_DISCARD_BITS;

--> leads to an error because the "#endif" ends the "if loop" and than there is an else without an if. Is the position, how much the line is indented (eingerückt) important for Arduino Code? Or should this be solved by the "#"? I hate to have no idea about coding :(

thinkyhead commented 8 years ago

leads to an error because the "#endif" ends the "if loop"

Try this:

    if (max6675_temp & MAX6675_ERROR_MASK) {
      SERIAL_ERROR_START;
      SERIAL_ERRORPGM("Temp measurement error! ");
      #if MAX6675_ERROR_MASK == 7
        SERIAL_ERRORPGM("MAX31855 ");
        if (max6675_temp & 1)
          SERIAL_ERRORLNPGM("Open Circuit");
        else if (max6675_temp & 2)
          SERIAL_ERRORLNPGM("Short to GND");
        else if (max6675_temp & 4)
          SERIAL_ERRORLNPGM("Short to VCC");
      #else
        SERIAL_ERRORLNPGM("MAX6675");
      #endif
      //max6675_temp = 4000; // thermocouple open
      max6675_temp = 25; // JUST TO AVOID THE KILL!!! Don't use in production.
    }
    else
      max6675_temp >>= MAX6675_DISCARD_BITS;
derletztename commented 8 years ago

At least this is compiling, going to test this on the machine soon :)

ghost commented 8 years ago

I've completely same trouble as @derletztename. Arduino MEGA2560 + RAMPS 1.4 EFB + Adafruit MAX31855. I doubted that my hardware is broken at 2 month ago, but now I setup new MEGA2560 + new RAMPS, same trouble still alive.

It continuously reboots (freeze) when using MAX31855 without SDSUPPORT. When freezing, red LED on RAMPS is flashing. It can be reproduced without real thing of MAX31855.

When I enable SDSUPPORT, MINTENP Err is occurs on every startup.

Try this:

Unfortunately any message of those was shown.

ghost commented 8 years ago
    // 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
+    //asm("nop");//50ns on 20Mhz, 62.5ns on 16Mhz
+    //asm("nop");//50ns on 20Mhz, 62.5ns on 16Mhz
-    uint32_t max6675_temp = 2000;
+    int32_t max6675_temp = 2000;
-    uint16_t max6675_temp = 2000;
+    int16_t max6675_temp = 2000;
-    return (int)max6675_temp;
+    return max6675_temp;

These weren't also solved problem unfortunately.

ghost commented 8 years ago

And, I'm seeing interesting result. With this setting, MINTENP Err is occurs on startup. But with this setting, MAXTEMP Err and MAX31855 Open Circuit Err are occurs on startup.

It seems that something of other setting is affecting to result.

Edit: My mistake of test. Results are same. Above Open Circuit Err occurred when MAX31855 was not connected.

ghost commented 8 years ago

Still searching, but this setting and dirty hack works fine for some reason.

  #if ENABLED(HEATER_0_USES_MAX6675)

-    #if DISABLED(SDSUPPORT)
+    //#if DISABLED(SDSUPPORT)
      OUT_WRITE(SCK_PIN, LOW);
      OUT_WRITE(MOSI_PIN, HIGH);
      SET_INPUT(MISO_PIN);
-     WRITE(MISO_PIN,1);
-    #else
+    WRITE(MISO_PIN, HIGH);
+    //#else
      OUT_WRITE(SS_PIN, HIGH);
-    #endif
+    //#endif

    OUT_WRITE(MAX6675_SS, HIGH);

  #endif //HEATER_0_USES_MAX6675
Grogyan commented 8 years ago

I tried compiling RC7 a few days ago, not RCBugFix, with Max31855 thermocouple and I just get a compiling error. DIODIO_MISO had not defined in this scope. It was referring to pin 53 not being defined, possibly due to a conflict with SDCard, it read like it was a typo. DIODIO_MISO should be DIO_MISO

I hadn't tried yet with RCBugFix, I've not had a good week.

ghost commented 8 years ago

@Grogyan

DIODIO_MISO

That was a bug in RC7, and fixed in current RCBugFix.

ghost commented 8 years ago

So, this hack (same as above) works fine with SDSUPPORT too, but there is a conditional. When SDCard or microSD - SDCard adaptor is already inserted in card slot at bootup of Marlin, it causes freeze and LED flashing. But SDCard or microSD - SDCard adaptor is inserted to card slot after bootup of Marlin, both SDCard and MAX31855 works fine.

  #if ENABLED(HEATER_0_USES_MAX6675)

-    #if DISABLED(SDSUPPORT)
+    //#if DISABLED(SDSUPPORT)
      OUT_WRITE(SCK_PIN, LOW);
      OUT_WRITE(MOSI_PIN, HIGH);
      SET_INPUT(MISO_PIN);
-     WRITE(MISO_PIN,1);
-    #else
+    WRITE(MISO_PIN, HIGH);
+    //#else
      OUT_WRITE(SS_PIN, HIGH);
-    #endif
+    //#endif

    OUT_WRITE(MAX6675_SS, HIGH);

  #endif //HEATER_0_USES_MAX6675

Then, I guess that initialize process of Marlin has some kind of problem...

Blue-Marlin commented 8 years ago

Recently we shifted the initialisation of the thermal manager in front of the initialisation of the display/SDcard, because of uncontrolled heaters during the boot screens.

@esenapaj Your 'hack' makes perfect sense to me. The SPI interface has to be initialized here.

ghost commented 8 years ago

My final result at this time: https://github.com/esenapaj/Marlin/commit/a76393d6a0c3fc844359c424b562765cdafca4e8 In Marlin_main.cpp

  lcd_init();
  #if ENABLED(SHOW_BOOTSCREEN)
    #if ENABLED(DOGLCD)
      safe_delay(BOOTSCREEN_TIMEOUT);
    #elif ENABLED(ULTRA_LCD)
      bootscreen();
-      lcd_init();
+      #if DISABLED(SDSUPPORT)
+        lcd_init();
+      #endif
    #endif
  #endif

This second lcd_init() causes freeze when SDSUPPORT (and MAX31855) is enabled for some reason. But when SDSUPPORT is disabled, this doesn't causes freeze, moreover if this second lcd_init() is removed, displaying of LCD is broken.

In tmperature.cpp

  #if ENABLED(HEATER_0_USES_MAX6675)

-    #if DISABLED(SDSUPPORT)
-      OUT_WRITE(SCK_PIN, LOW);
-      OUT_WRITE(MOSI_PIN, HIGH);
-      SET_INPUT(MISO_PIN);
-      WRITE(MISO_PIN,1);
-    #else
-      OUT_WRITE(SS_PIN, HIGH);
-    #endif
+    OUT_WRITE(SCK_PIN, LOW);
+    OUT_WRITE(MOSI_PIN, HIGH);
+    SET_INPUT(MISO_PIN);
+    WRITE(MISO_PIN, HIGH);
+    OUT_WRITE(SS_PIN, HIGH);

    OUT_WRITE(MAX6675_SS, HIGH);

  #endif //HEATER_0_USES_MAX6675

By test, these all the writing process are needed whether SDSUPPORT is enabled or not. If one of those lack, MINTEMP Err or freeze occures. I wonder that why OUT_WRITE(SS_PIN, HIGH) is also needed when SDSUPPORT is disabled.

This result is still bit unstable (broken displaying or slow bootup or MAXTEMP Err occures once in a while when bootup), but in that case, remove a SDCard then reset or completely power off / on the machine, it restore stability.

ghost commented 8 years ago

@derletztename I prepared a test branch that it's based on newest RCBugFix. Please try it if you'd like. https://github.com/esenapaj/Marlin/tree/succeed

derletztename commented 8 years ago

So great, i absolutely will test this. Thanks

derletztename commented 8 years ago

Your code is working on my arduino, it doesn't freeze anymore, but I got an Mintemp error and Marlin stops working immediately. I checked the wiring again and everything is fine. Any Ideas about that?

ghost commented 8 years ago

I guess that maybe your wiring of K thermocouple is inverted. K thermocouple has polarity. When start heating with inversely wired K thermocouple, measured temperature isn't increased but decreased, finally it go below the mintemp.

And this is information: my wiring img_20161015_203011_

derletztename commented 8 years ago

Actually it was at first, but after changing it, the error stayed the same. Also it's popping up just after booting Marlin via Pronterface. So I have no chance to see where the temperature would go to (up or down). It's just killing the Process with an error. Maybe I could upload a screenshot...

derletztename commented 8 years ago

wp_20161015_14_21_33_rich

ghost commented 8 years ago

This is mine. default

I'd like to see your Configuration.h, Configuration_adv.h, and pins_RAMPS.h. If you rename those files to Configuration.txt, Configuration_adv.txt, and pins_RAMPS.txt, and drag & drop to Comment window in this thread, those files are uploaded. I can test your setting on my machine, because we has same hardware (RAMPS and MAX31855 by Adafruit).