Browse Source

Allow increasing the software PWM frequency.

Erik van der Zalm 11 years ago
parent
commit
c8dcc7c208
4 changed files with 46 additions and 22 deletions
  1. 11
    0
      Marlin/Configuration.h
  2. 4
    0
      Marlin/Marlin.h
  3. 19
    17
      Marlin/planner.cpp
  4. 12
    5
      Marlin/temperature.cpp

+ 11
- 0
Marlin/Configuration.h View File

@@ -457,6 +457,17 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
457 457
 // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino
458 458
 //#define FAST_PWM_FAN
459 459
 
460
+// Use software PWM to drive the fan, as for the heaters. This uses a very low frequency
461
+// which is not ass annoying as with the hardware PWM. On the other hand, if this frequency
462
+// is too low, you should also increment SOFT_PWM_SCALE.
463
+//#define FAN_SOFT_PWM
464
+
465
+// Incrementing this by 1 will double the software PWM frequency,
466
+// affecting heaters, and the fan if FAN_SOFT_PWM is enabled.
467
+// However, control resolution will be halved for each increment;
468
+// at zero value, there are 128 effective control positions.
469
+#define SOFT_PWM_SCALE 0
470
+
460 471
 // M240  Triggers a camera by emulating a Canon RC-1 Remote
461 472
 // Data from: http://www.doc-diy.net/photo/rc-1_hacked/
462 473
 // #define PHOTOGRAPH_PIN     23

+ 4
- 0
Marlin/Marlin.h View File

@@ -191,6 +191,10 @@ extern int ValvePressure;
191 191
 extern int EtoPPressure;
192 192
 #endif
193 193
 
194
+#ifdef FAN_SOFT_PWM
195
+extern unsigned char fanSpeedSoftPwm;
196
+#endif
197
+
194 198
 #ifdef FWRETRACT
195 199
 extern bool autoretract_enabled;
196 200
 extern bool retracted;

+ 19
- 17
Marlin/planner.cpp View File

@@ -473,22 +473,24 @@ void check_axes_activity()
473 473
     disable_e2(); 
474 474
   }
475 475
 #if defined(FAN_PIN) && FAN_PIN > -1
476
-  #ifndef FAN_SOFT_PWM
477
-    #ifdef FAN_KICKSTART_TIME
478
-      static unsigned long fan_kick_end;
479
-      if (tail_fan_speed) {
480
-        if (fan_kick_end == 0) {
481
-          // Just starting up fan - run at full power.
482
-          fan_kick_end = millis() + FAN_KICKSTART_TIME;
483
-          tail_fan_speed = 255;
484
-        } else if (fan_kick_end > millis())
485
-          // Fan still spinning up.
486
-          tail_fan_speed = 255;
487
-      } else {
488
-        fan_kick_end = 0;
489
-      }
490
-    #endif//FAN_KICKSTART_TIME
491
-    analogWrite(FAN_PIN,tail_fan_speed);
476
+  #ifdef FAN_KICKSTART_TIME
477
+    static unsigned long fan_kick_end;
478
+    if (tail_fan_speed) {
479
+      if (fan_kick_end == 0) {
480
+        // Just starting up fan - run at full power.
481
+        fan_kick_end = millis() + FAN_KICKSTART_TIME;
482
+        tail_fan_speed = 255;
483
+      } else if (fan_kick_end > millis())
484
+        // Fan still spinning up.
485
+        tail_fan_speed = 255;
486
+    } else {
487
+      fan_kick_end = 0;
488
+    }
489
+  #endif//FAN_KICKSTART_TIME
490
+  #ifdef FAN_SOFT_PWM
491
+  fanSpeedSoftPwm = tail_fan_speed;
492
+  #else
493
+  analogWrite(FAN_PIN,tail_fan_speed);
492 494
   #endif//!FAN_SOFT_PWM
493 495
 #endif//FAN_PIN > -1
494 496
 #ifdef AUTOTEMP
@@ -757,7 +759,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
757 759
       block->acceleration_st = axis_steps_per_sqr_second[Z_AXIS];
758 760
   }
759 761
   block->acceleration = block->acceleration_st / steps_per_mm;
760
-  block->acceleration_rate = (long)((float)block->acceleration_st * 8.388608);
762
+  block->acceleration_rate = (long)((float)block->acceleration_st * (16777216.0 / (F_CPU / 8.0)));
761 763
 
762 764
 #if 0  // Use old jerk for now
763 765
   // Compute path unit vector

+ 12
- 5
Marlin/temperature.cpp View File

@@ -62,6 +62,9 @@ float current_temperature_bed = 0.0;
62 62
   float bedKd=(DEFAULT_bedKd/PID_dT);
63 63
 #endif //PIDTEMPBED
64 64
   
65
+#ifdef FAN_SOFT_PWM
66
+  unsigned char fanSpeedSoftPwm;
67
+#endif
65 68
   
66 69
 //===========================================================================
67 70
 //=============================private variables============================
@@ -145,6 +148,10 @@ int watch_start_temp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0);
145 148
 unsigned long watchmillis[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0);
146 149
 #endif //WATCH_TEMP_PERIOD
147 150
 
151
+#ifndef SOFT_PWM_SCALE
152
+#define SOFT_PWM_SCALE 0
153
+#endif
154
+
148 155
 //===========================================================================
149 156
 //=============================   functions      ============================
150 157
 //===========================================================================
@@ -720,8 +727,8 @@ void tp_init()
720 727
     setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
721 728
     #endif
722 729
     #ifdef FAN_SOFT_PWM
723
-	soft_pwm_fan=(unsigned char)fanSpeed;
724
-	#endif
730
+    soft_pwm_fan = fanSpeedSoftPwm / 2;
731
+    #endif
725 732
   #endif  
726 733
 
727 734
   #ifdef HEATER_0_USES_MAX6675
@@ -1028,7 +1035,7 @@ ISR(TIMER0_COMPB_vect)
1028 1035
   static unsigned long raw_temp_2_value = 0;
1029 1036
   static unsigned long raw_temp_bed_value = 0;
1030 1037
   static unsigned char temp_state = 0;
1031
-  static unsigned char pwm_count = 1;
1038
+  static unsigned char pwm_count = (1 << SOFT_PWM_SCALE);
1032 1039
   static unsigned char soft_pwm_0;
1033 1040
   #if EXTRUDERS > 1
1034 1041
   static unsigned char soft_pwm_1;
@@ -1056,7 +1063,7 @@ ISR(TIMER0_COMPB_vect)
1056 1063
     if(soft_pwm_b > 0) WRITE(HEATER_BED_PIN,1);
1057 1064
     #endif
1058 1065
     #ifdef FAN_SOFT_PWM
1059
-    soft_pwm_fan =(unsigned char) fanSpeed;
1066
+    soft_pwm_fan = fanSpeedSoftPwm / 2;
1060 1067
     if(soft_pwm_fan > 0) WRITE(FAN_PIN,1);
1061 1068
     #endif
1062 1069
   }
@@ -1074,7 +1081,7 @@ ISR(TIMER0_COMPB_vect)
1074 1081
   if(soft_pwm_fan <= pwm_count) WRITE(FAN_PIN,0);
1075 1082
   #endif
1076 1083
   
1077
-  pwm_count++;
1084
+  pwm_count += (1 << SOFT_PWM_SCALE);
1078 1085
   pwm_count &= 0x7f;
1079 1086
   
1080 1087
   switch(temp_state) {

Loading…
Cancel
Save