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
 // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino
457
 // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino
458
 //#define FAST_PWM_FAN
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
 // M240  Triggers a camera by emulating a Canon RC-1 Remote
471
 // M240  Triggers a camera by emulating a Canon RC-1 Remote
461
 // Data from: http://www.doc-diy.net/photo/rc-1_hacked/
472
 // Data from: http://www.doc-diy.net/photo/rc-1_hacked/
462
 // #define PHOTOGRAPH_PIN     23
473
 // #define PHOTOGRAPH_PIN     23

+ 4
- 0
Marlin/Marlin.h View File

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

+ 19
- 17
Marlin/planner.cpp View File

473
     disable_e2(); 
473
     disable_e2(); 
474
   }
474
   }
475
 #if defined(FAN_PIN) && FAN_PIN > -1
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
   #endif//!FAN_SOFT_PWM
494
   #endif//!FAN_SOFT_PWM
493
 #endif//FAN_PIN > -1
495
 #endif//FAN_PIN > -1
494
 #ifdef AUTOTEMP
496
 #ifdef AUTOTEMP
757
       block->acceleration_st = axis_steps_per_sqr_second[Z_AXIS];
759
       block->acceleration_st = axis_steps_per_sqr_second[Z_AXIS];
758
   }
760
   }
759
   block->acceleration = block->acceleration_st / steps_per_mm;
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
 #if 0  // Use old jerk for now
764
 #if 0  // Use old jerk for now
763
   // Compute path unit vector
765
   // Compute path unit vector

+ 12
- 5
Marlin/temperature.cpp View File

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

Loading…
Cancel
Save