Slow PWM fan @ 62.5Hz
This commit is contained in:
parent
f9522f5711
commit
cb334238cc
2 changed files with 13 additions and 9 deletions
|
@ -477,7 +477,8 @@ your extruder heater takes 2 minutes to hit the target on heating.
|
|||
// Use software PWM to drive the fan, as for the heaters. This uses a very low frequency
|
||||
// which is not ass annoying as with the hardware PWM. On the other hand, if this frequency
|
||||
// is too low, you should also increment SOFT_PWM_SCALE.
|
||||
//#define FAN_SOFT_PWM
|
||||
#define FAN_SOFT_PWM
|
||||
#define FAN_SOFT_PWM_BITS 4 //PWM bit resolution = 4bits, freq = 62.5Hz
|
||||
|
||||
// Incrementing this by 1 will double the software PWM frequency,
|
||||
// affecting heaters, and the fan if FAN_SOFT_PWM is enabled.
|
||||
|
|
|
@ -1024,7 +1024,7 @@ void tp_init()
|
|||
setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
|
||||
#endif
|
||||
#ifdef FAN_SOFT_PWM
|
||||
soft_pwm_fan = fanSpeedSoftPwm / 2;
|
||||
soft_pwm_fan = fanSpeedSoftPwm / (1 << (8 - FAN_SOFT_PWM_BITS));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -1599,12 +1599,15 @@ ISR(TIMER0_COMPB_vect)
|
|||
#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
|
||||
soft_pwm_b = soft_pwm_bed;
|
||||
if(soft_pwm_b > 0) WRITE(HEATER_BED_PIN,1); else WRITE(HEATER_BED_PIN,0);
|
||||
#endif
|
||||
#ifdef FAN_SOFT_PWM
|
||||
soft_pwm_fan = fanSpeedSoftPwm / 2;
|
||||
if(soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0);
|
||||
#endif
|
||||
}
|
||||
#ifdef FAN_SOFT_PWM
|
||||
if ((pwm_count & ((1 << FAN_SOFT_PWM_BITS) - 1)) == 0)
|
||||
{
|
||||
soft_pwm_fan = fanSpeedSoftPwm / (1 << (8 - FAN_SOFT_PWM_BITS));
|
||||
if(soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0);
|
||||
}
|
||||
#endif
|
||||
if(soft_pwm_0 < pwm_count)
|
||||
{
|
||||
WRITE(HEATER_0_PIN,0);
|
||||
|
@ -1623,7 +1626,7 @@ ISR(TIMER0_COMPB_vect)
|
|||
if(soft_pwm_b < pwm_count) WRITE(HEATER_BED_PIN,0);
|
||||
#endif
|
||||
#ifdef FAN_SOFT_PWM
|
||||
if(soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0);
|
||||
if (soft_pwm_fan < (pwm_count & ((1 << FAN_SOFT_PWM_BITS) - 1))) WRITE(FAN_PIN,0);
|
||||
#endif
|
||||
|
||||
pwm_count += (1 << SOFT_PWM_SCALE);
|
||||
|
@ -1810,8 +1813,8 @@ ISR(TIMER0_COMPB_vect)
|
|||
#endif
|
||||
|
||||
#ifdef FAN_SOFT_PWM
|
||||
if (pwm_count == 0){
|
||||
soft_pwm_fan = fanSpeedSoftPwm / 2;
|
||||
if ((pwm_count & ((1 << FAN_SOFT_PWM_BITS) - 1)) == 0)
|
||||
soft_pwm_fan = fanSpeedSoftPwm / (1 << (8 - FAN_SOFT_PWM_BITS));
|
||||
if (soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0);
|
||||
}
|
||||
if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0);
|
||||
|
|
Loading…
Add table
Reference in a new issue