Variable bed PWM resolution/frequency (adjusted to 5bits/32Hz)

This commit is contained in:
Robert Pelnar 2019-05-06 18:07:42 +02:00
parent fa1bdd6ab1
commit 58683da2fb
2 changed files with 9 additions and 3 deletions

View File

@ -480,6 +480,9 @@ your extruder heater takes 2 minutes to hit the target on heating.
#define FAN_SOFT_PWM
#define FAN_SOFT_PWM_BITS 4 //PWM bit resolution = 4bits, freq = 62.5Hz
// Bed soft pwm
#define HEATER_BED_SOFT_PWM_BITS 5 //PWM bit resolution = 5bits, freq = 32Hz
// Incrementing this by 1 will double the software PWM frequency,
// affecting heaters, and the fan if FAN_SOFT_PWM is enabled.
// However, control resolution will be halved for each increment;

View File

@ -1693,13 +1693,16 @@ ISR(TIMER0_COMPB_vect)
soft_pwm_2 = soft_pwm[2];
if(soft_pwm_2 > 0) WRITE(HEATER_2_PIN,1); else WRITE(HEATER_2_PIN,0);
#endif
}
#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
soft_pwm_b = soft_pwm_bed;
if ((pwm_count & ((1 << HEATER_BED_SOFT_PWM_BITS) - 1)) == 0)
{
soft_pwm_b = soft_pwm_bed / (1 << (8 - HEATER_BED_SOFT_PWM_BITS));
#ifndef SYSTEM_TIMER_2
if(soft_pwm_b > 0) WRITE(HEATER_BED_PIN,1); else WRITE(HEATER_BED_PIN,0);
#endif //SYSTEM_TIMER_2
#endif
}
#endif
#ifdef FAN_SOFT_PWM
if ((pwm_count & ((1 << FAN_SOFT_PWM_BITS) - 1)) == 0)
{
@ -1722,7 +1725,7 @@ ISR(TIMER0_COMPB_vect)
if(soft_pwm_2 < pwm_count) WRITE(HEATER_2_PIN,0);
#endif
#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
if(soft_pwm_b < pwm_count) WRITE(HEATER_BED_PIN,0);
if (soft_pwm_b < (pwm_count & ((1 << HEATER_BED_SOFT_PWM_BITS) - 1))) WRITE(HEATER_BED_PIN,0);
#endif
#ifdef FAN_SOFT_PWM
if (soft_pwm_fan < (pwm_count & ((1 << FAN_SOFT_PWM_BITS) - 1))) WRITE(FAN_PIN,0);