Ver código fonte

I have added some code in the "temperature.cpp" for have the possibility of control the time of the states with the heater drived by relays, with this feature now it is possible use PID function in conjunction with relay to control the temperature. I have made some tests and the temperature stay always in the range of +-1°C from the setted temp.

There is the possibility of turn on this features adding "#define SLOW_PWM_HEATERS" in Configuration.h
Dino Del Favero 10 anos atrás
pai
commit
038fccd7a1
1 arquivos alterados com 277 adições e 34 exclusões
  1. 277
    34
      Marlin/temperature.cpp

+ 277
- 34
Marlin/temperature.cpp Ver arquivo

@@ -497,7 +497,7 @@ void manage_heater()
497 497
     SERIAL_ECHO(" iTerm ");
498 498
     SERIAL_ECHO(iTerm[e]);
499 499
     SERIAL_ECHO(" dTerm ");
500
-    SERIAL_ECHOLN(dTerm[e]);  
500
+    SERIAL_ECHOLN(dTerm[e]);
501 501
     #endif //PID_DEBUG
502 502
   #else /* PID off */
503 503
     pid_output = 0;
@@ -1221,68 +1221,311 @@ ISR(TIMER0_COMPB_vect)
1221 1221
   static unsigned char temp_state = 10;
1222 1222
   static unsigned char pwm_count = (1 << SOFT_PWM_SCALE);
1223 1223
   static unsigned char soft_pwm_0;
1224
-  #if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL)
1224
+#ifdef SLOW_PWM_HEATERS
1225
+  static unsigned char slow_pwm_count = 0;
1226
+  static unsigned char state_heater_0 = 0;
1227
+  static unsigned char state_timer_heater_0 = 0;
1228
+#endif 
1229
+#if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL)
1225 1230
   static unsigned char soft_pwm_1;
1226
-  #endif
1227
-  #if EXTRUDERS > 2
1231
+#ifdef SLOW_PWM_HEATERS
1232
+  static unsigned char state_heater_1 = 0;
1233
+  static unsigned char state_timer_heater_1 = 0;
1234
+#endif 
1235
+#endif
1236
+#if EXTRUDERS > 2
1228 1237
   static unsigned char soft_pwm_2;
1229
-  #endif
1230
-  #if HEATER_BED_PIN > -1
1238
+#ifdef SLOW_PWM_HEATERS
1239
+  static unsigned char state_heater_2 = 0;
1240
+  static unsigned char state_timer_heater_2 = 0;
1241
+#endif 
1242
+#endif
1243
+#if HEATER_BED_PIN > -1
1231 1244
   static unsigned char soft_pwm_b;
1232
-  #endif
1245
+#ifdef SLOW_PWM_HEATERS
1246
+  static unsigned char state_heater_b = 0;
1247
+  static unsigned char state_timer_heater_b = 0;
1248
+#endif 
1249
+#endif
1233 1250
   
1234
-  #if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1)
1235
-   static unsigned long raw_filwidth_value = 0;  //added for filament width sensor
1236
-  #endif
1251
+#if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1)
1252
+  static unsigned long raw_filwidth_value = 0;  //added for filament width sensor
1253
+#endif
1237 1254
   
1255
+#ifndef SLOW_PWM_HEATERS
1256
+  /*
1257
+   * standard PWM modulation
1258
+   */
1238 1259
   if(pwm_count == 0){
1239 1260
     soft_pwm_0 = soft_pwm[0];
1240 1261
     if(soft_pwm_0 > 0) { 
1241 1262
       WRITE(HEATER_0_PIN,1);
1242
-      #ifdef HEATERS_PARALLEL
1263
+#ifdef HEATERS_PARALLEL
1243 1264
       WRITE(HEATER_1_PIN,1);
1244
-      #endif
1265
+#endif
1245 1266
     } else WRITE(HEATER_0_PIN,0);
1246
-	
1247
-    #if EXTRUDERS > 1
1267
+    
1268
+#if EXTRUDERS > 1
1248 1269
     soft_pwm_1 = soft_pwm[1];
1249 1270
     if(soft_pwm_1 > 0) WRITE(HEATER_1_PIN,1); else WRITE(HEATER_1_PIN,0);
1250
-    #endif
1251
-    #if EXTRUDERS > 2
1271
+#endif
1272
+#if EXTRUDERS > 2
1252 1273
     soft_pwm_2 = soft_pwm[2];
1253 1274
     if(soft_pwm_2 > 0) WRITE(HEATER_2_PIN,1); else WRITE(HEATER_2_PIN,0);
1254
-    #endif
1255
-    #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1275
+#endif
1276
+#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1256 1277
     soft_pwm_b = soft_pwm_bed;
1257 1278
     if(soft_pwm_b > 0) WRITE(HEATER_BED_PIN,1); else WRITE(HEATER_BED_PIN,0);
1258
-    #endif
1259
-    #ifdef FAN_SOFT_PWM
1279
+#endif
1280
+#ifdef FAN_SOFT_PWM
1260 1281
     soft_pwm_fan = fanSpeedSoftPwm / 2;
1261 1282
     if(soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0);
1262
-    #endif
1283
+#endif
1263 1284
   }
1264 1285
   if(soft_pwm_0 < pwm_count) { 
1265
-      WRITE(HEATER_0_PIN,0);
1266
-      #ifdef HEATERS_PARALLEL
1267
-      WRITE(HEATER_1_PIN,0);
1268
-      #endif
1269
-    }
1270
-  #if EXTRUDERS > 1
1286
+    WRITE(HEATER_0_PIN,0);
1287
+#ifdef HEATERS_PARALLEL
1288
+    WRITE(HEATER_1_PIN,0);
1289
+#endif
1290
+  }
1291
+#if EXTRUDERS > 1
1271 1292
   if(soft_pwm_1 < pwm_count) WRITE(HEATER_1_PIN,0);
1272
-  #endif
1273
-  #if EXTRUDERS > 2
1293
+#endif
1294
+#if EXTRUDERS > 2
1274 1295
   if(soft_pwm_2 < pwm_count) WRITE(HEATER_2_PIN,0);
1275
-  #endif
1276
-  #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1296
+#endif
1297
+#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1277 1298
   if(soft_pwm_b < pwm_count) WRITE(HEATER_BED_PIN,0);
1278
-  #endif
1279
-  #ifdef FAN_SOFT_PWM
1299
+#endif
1300
+#ifdef FAN_SOFT_PWM
1280 1301
   if(soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0);
1281
-  #endif
1302
+#endif
1303
+  
1304
+  pwm_count += (1 << SOFT_PWM_SCALE);
1305
+  pwm_count &= 0x7f;
1306
+  
1307
+#else //ifndef SLOW_PWM_HEATERS
1308
+  /*
1309
+   * SLOW PWM HEATERS
1310
+   *
1311
+   * for heaters drived by relay
1312
+   */
1313
+#ifndef MIN_STATE_TIME
1314
+#define MIN_STATE_TIME 16 // MIN_STATE_TIME * 65.5 = time in milliseconds
1315
+#endif
1316
+  if (slow_pwm_count == 0) {
1317
+    // EXTRUDER 0 
1318
+    soft_pwm_0 = soft_pwm[0];
1319
+    if (soft_pwm_0 > 0) {
1320
+      // turn ON heather only if the minimum time is up 
1321
+      if (state_timer_heater_0 == 0) { 
1322
+	// if change state set timer 
1323
+	if (state_heater_0 == 0) {
1324
+	  state_timer_heater_0 = MIN_STATE_TIME;
1325
+	}
1326
+	state_heater_0 = 1;
1327
+	WRITE(HEATER_0_PIN, 1);
1328
+#ifdef HEATERS_PARALLEL
1329
+	WRITE(HEATER_1_PIN, 1);
1330
+#endif
1331
+      }
1332
+    } else {
1333
+      // turn OFF heather only if the minimum time is up 
1334
+      if (state_timer_heater_0 == 0) {
1335
+	// if change state set timer 
1336
+	if (state_heater_0 == 1) {
1337
+	  state_timer_heater_0 = MIN_STATE_TIME;
1338
+	}
1339
+	state_heater_0 = 0;
1340
+	WRITE(HEATER_0_PIN, 0);
1341
+#ifdef HEATERS_PARALLEL
1342
+	WRITE(HEATER_1_PIN, 0);
1343
+#endif
1344
+      }
1345
+    }
1346
+    
1347
+#if EXTRUDERS > 1
1348
+    // EXTRUDER 1
1349
+    soft_pwm_1 = soft_pwm[1];
1350
+    if (soft_pwm_1 > 0) {
1351
+      // turn ON heather only if the minimum time is up 
1352
+      if (state_timer_heater_1 == 0) { 
1353
+	// if change state set timer 
1354
+	if (state_heater_1 == 0) {
1355
+	  state_timer_heater_1 = MIN_STATE_TIME;
1356
+	}
1357
+	state_heater_1 = 1;
1358
+	WRITE(HEATER_1_PIN, 1);
1359
+      }
1360
+    } else {
1361
+      // turn OFF heather only if the minimum time is up 
1362
+      if (state_timer_heater_1 == 0) {
1363
+	// if change state set timer 
1364
+	if (state_heater_1 == 1) {
1365
+	  state_timer_heater_1 = MIN_STATE_TIME;
1366
+	}
1367
+	state_heater_1 = 0;
1368
+	WRITE(HEATER_1_PIN, 0);
1369
+      }
1370
+    }
1371
+#endif
1372
+    
1373
+#if EXTRUDERS > 2
1374
+    // EXTRUDER 2
1375
+    soft_pwm_2 = soft_pwm[2];
1376
+    if (soft_pwm_2 > 0) {
1377
+      // turn ON heather only if the minimum time is up 
1378
+      if (state_timer_heater_2 == 0) { 
1379
+	// if change state set timer 
1380
+	if (state_heater_2 == 0) {
1381
+	  state_timer_heater_2 = MIN_STATE_TIME;
1382
+	}
1383
+	state_heater_2 = 1;
1384
+	WRITE(HEATER_2_PIN, 1);
1385
+      }
1386
+    } else {
1387
+      // turn OFF heather only if the minimum time is up 
1388
+      if (state_timer_heater_2 == 0) {
1389
+	// if change state set timer 
1390
+	if (state_heater_2 == 1) {
1391
+	  state_timer_heater_2 = MIN_STATE_TIME;
1392
+	}
1393
+	state_heater_2 = 0;
1394
+	WRITE(HEATER_2_PIN, 0);
1395
+      }
1396
+    }
1397
+#endif
1398
+    
1399
+#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1400
+    // BED
1401
+    soft_pwm_b = soft_pwm_bed;
1402
+    if (soft_pwm_b > 0) {
1403
+      // turn ON heather only if the minimum time is up 
1404
+      if (state_timer_heater_b == 0) { 
1405
+	// if change state set timer 
1406
+	if (state_heater_b == 0) {
1407
+	  state_timer_heater_b = MIN_STATE_TIME;
1408
+	}
1409
+	state_heater_b = 1;
1410
+	WRITE(HEATER_BED_PIN, 1);
1411
+      }
1412
+    } else {
1413
+      // turn OFF heather only if the minimum time is up 
1414
+      if (state_timer_heater_b == 0) {
1415
+	// if change state set timer 
1416
+	if (state_heater_b == 1) {
1417
+	  state_timer_heater_b = MIN_STATE_TIME;
1418
+	}
1419
+	state_heater_b = 0;
1420
+	WRITE(HEATER_BED_PIN, 0);
1421
+      }
1422
+    }
1423
+#endif
1424
+  } // if (slow_pwm_count == 0)
1425
+  
1426
+  // EXTRUDER 0 
1427
+  if (soft_pwm_0 < slow_pwm_count) {
1428
+    // turn OFF heather only if the minimum time is up 
1429
+    if (state_timer_heater_0 == 0) { 
1430
+      // if change state set timer 
1431
+      if (state_heater_0 == 1) {
1432
+	state_timer_heater_0 = MIN_STATE_TIME;
1433
+      }
1434
+      state_heater_0 = 0;
1435
+      WRITE(HEATER_0_PIN, 0);
1436
+#ifdef HEATERS_PARALLEL
1437
+      WRITE(HEATER_1_PIN, 0);
1438
+#endif
1439
+    }
1440
+  }
1441
+    
1442
+#if EXTRUDERS > 1
1443
+  // EXTRUDER 1 
1444
+  if (soft_pwm_1 < slow_pwm_count) {
1445
+    // turn OFF heather only if the minimum time is up 
1446
+    if (state_timer_heater_1 == 0) { 
1447
+      // if change state set timer 
1448
+      if (state_heater_1 == 1) {
1449
+	state_timer_heater_1 = MIN_STATE_TIME;
1450
+      }
1451
+      state_heater_1 = 0;
1452
+      WRITE(HEATER_1_PIN, 0);
1453
+    }
1454
+  }
1455
+#endif
1456
+  
1457
+#if EXTRUDERS > 2
1458
+  // EXTRUDER 2
1459
+  if (soft_pwm_2 < slow_pwm_count) {
1460
+    // turn OFF heather only if the minimum time is up 
1461
+    if (state_timer_heater_2 == 0) { 
1462
+      // if change state set timer 
1463
+      if (state_heater_2 == 1) {
1464
+	state_timer_heater_2 = MIN_STATE_TIME;
1465
+      }
1466
+      state_heater_2 = 0;
1467
+      WRITE(HEATER_2_PIN, 0);
1468
+    }
1469
+  }
1470
+#endif
1471
+  
1472
+#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1473
+  // BED
1474
+  if (soft_pwm_b < slow_pwm_count) {
1475
+    // turn OFF heather only if the minimum time is up 
1476
+    if (state_timer_heater_b == 0) { 
1477
+      // if change state set timer 
1478
+      if (state_heater_b == 1) {
1479
+	state_timer_heater_b = MIN_STATE_TIME;
1480
+      }
1481
+      state_heater_b = 0;
1482
+      WRITE(HEATER_BED_PIN, 0);
1483
+    }
1484
+  }
1485
+#endif
1486
+  
1487
+#ifdef FAN_SOFT_PWM
1488
+  if (pwm_count == 0){
1489
+    soft_pwm_fan = fanSpeedSoftPwm / 2;
1490
+    if (soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0);
1491
+  }
1492
+  if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0);
1493
+#endif
1282 1494
   
1283 1495
   pwm_count += (1 << SOFT_PWM_SCALE);
1284 1496
   pwm_count &= 0x7f;
1285 1497
   
1498
+  // increment slow_pwm_count only every 64 pwm_count circa 65.5ms
1499
+  if ((pwm_count % 64) == 0) {
1500
+    slow_pwm_count++;
1501
+    slow_pwm_count &= 0x7f;
1502
+    
1503
+    // Extruder 0
1504
+    if (state_timer_heater_0 > 0) {
1505
+      state_timer_heater_0--;
1506
+    } 
1507
+  
1508
+#if EXTRUDERS > 1
1509
+    // Extruder 1
1510
+    if (state_timer_heater_1 > 0) 
1511
+      state_timer_heater_1--;
1512
+#endif
1513
+    
1514
+#if EXTRUDERS > 2
1515
+    // Extruder 2
1516
+    if (state_timer_heater_2 > 0) 
1517
+      state_timer_heater_2--;
1518
+#endif
1519
+    
1520
+#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
1521
+    // Bed   
1522
+    if (state_timer_heater_b > 0) 
1523
+      state_timer_heater_b--;
1524
+#endif
1525
+  } //if ((pwm_count % 64) == 0) {
1526
+  
1527
+#endif //ifndef SLOW_PWM_HEATERS
1528
+  
1286 1529
   switch(temp_state) {
1287 1530
     case 0: // Prepare TEMP_0
1288 1531
       #if defined(TEMP_0_PIN) && (TEMP_0_PIN > -1)

Carregando…
Cancelar
Salvar