Pārlūkot izejas kodu

Resolve corruption of Max7219 Debug LED Matrix

Roxy-3D 6 gadus atpakaļ
vecāks
revīzija
26cc12eaa4
1 mainītis faili ar 21 papildinājumiem un 9 dzēšanām
  1. 21
    9
      Marlin/src/feature/Max7219_Debug_LEDs.cpp

+ 21
- 9
Marlin/src/feature/Max7219_Debug_LEDs.cpp Parādīt failu

@@ -64,9 +64,9 @@
64 64
 static uint8_t LEDs[8] = { 0 };
65 65
 
66 66
 #ifdef CPU_32_BIT
67
-  #define MS_DELAY() delayMicroseconds(5)  // 32-bit processors need a delay to stabilize the signal
67
+  #define MS_DELAY() delayMicroseconds(7)  // 32-bit processors need a delay to stabilize the signal
68 68
 #else
69
-  #define MS_DELAY() NOOP
69
+  #define MS_DELAY() DELAY_3_NOP
70 70
 #endif
71 71
 
72 72
 void Max7219_PutByte(uint8_t data) {
@@ -214,6 +214,16 @@ void Max7219_Set_Column(const uint8_t col, const uint8_t val) {
214 214
   Max7219(8 - col, LEDs[col]);
215 215
 }
216 216
 
217
+void Max7219_register_setup() {
218
+  //initiation of the max 7219
219
+  Max7219(max7219_reg_scanLimit, 0x07);
220
+  Max7219(max7219_reg_decodeMode, 0x00);       // using an led matrix (not digits)
221
+  Max7219(max7219_reg_shutdown, 0x01);         // not in shutdown mode
222
+  Max7219(max7219_reg_displayTest, 0x00);      // no display test
223
+  Max7219(max7219_reg_intensity, 0x01 & 0x0F); // the first 0x0F is the value you can set
224
+                                               // range: 0x00 to 0x0F
225
+}
226
+
217 227
 void Max7219_init() {
218 228
   uint8_t i, x, y;
219 229
 
@@ -223,13 +233,8 @@ void Max7219_init() {
223 233
   OUT_WRITE(MAX7219_LOAD_PIN, HIGH);
224 234
   delay(1);
225 235
 
226
-  //initiation of the max 7219
227
-  Max7219(max7219_reg_scanLimit, 0x07);
228
-  Max7219(max7219_reg_decodeMode, 0x00);  // using an led matrix (not digits)
229
-  Max7219(max7219_reg_shutdown, 0x01);    // not in shutdown mode
230
-  Max7219(max7219_reg_displayTest, 0x00); // no display test
231
-  Max7219(max7219_reg_intensity, 0x01 & 0x0F); // the first 0x0F is the value you can set
232
-                                               // range: 0x00 to 0x0F
236
+  Max7219_register_setup();
237
+
233 238
   for (i = 0; i <= 7; i++) {      // empty registers, turn all LEDs off
234 239
     LEDs[i] = 0x00;
235 240
     Max7219(i + 1, 0);
@@ -282,6 +287,13 @@ void Max7219_idle_tasks() {
282 287
     #endif
283 288
     CRITICAL_SECTION_END
284 289
   #endif
290
+      
291
+  static uint16_t refresh_cnt = 0;  // The Max7219 circuit boards available for several dollars on eBay 
292
+  if (refresh_cnt++ > 50000) {      // are vulnerable to electrical noise, especially with long wires
293
+    Max7219_register_setup();       // next to high current wires. If the display becomes corrupted due
294
+    Max7219_LED_Toggle(7, 0);       // to electrical noise, this will fix it within a couple of seconds.
295
+    refresh_cnt = 0;
296
+  }
285 297
 
286 298
   #if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
287 299
     static millis_t next_blink = 0;

Notiek ielāde…
Atcelt
Saglabāt