Merge pull request #4621 from thinkyhead/rc_fan_set_output

Init PWM-able AUTO_FAN pins with SET_OUTPUT
master
Scott Lahteine 8 years ago committed by GitHub
commit dcd26b0403

@ -440,10 +440,16 @@
#define HAS_AUTO_FAN_1 (PIN_EXISTS(EXTRUDER_1_AUTO_FAN)) #define HAS_AUTO_FAN_1 (PIN_EXISTS(EXTRUDER_1_AUTO_FAN))
#define HAS_AUTO_FAN_2 (PIN_EXISTS(EXTRUDER_2_AUTO_FAN)) #define HAS_AUTO_FAN_2 (PIN_EXISTS(EXTRUDER_2_AUTO_FAN))
#define HAS_AUTO_FAN_3 (PIN_EXISTS(EXTRUDER_3_AUTO_FAN)) #define HAS_AUTO_FAN_3 (PIN_EXISTS(EXTRUDER_3_AUTO_FAN))
#define AUTO_1_IS_0 (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
#define AUTO_2_IS_0 (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
#define AUTO_2_IS_1 (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN)
#define AUTO_3_IS_0 (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
#define AUTO_3_IS_1 (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN)
#define AUTO_3_IS_2 (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN)
#define HAS_AUTO_FAN (HAS_AUTO_FAN_0 || HAS_AUTO_FAN_1 || HAS_AUTO_FAN_2 || HAS_AUTO_FAN_3) #define HAS_AUTO_FAN (HAS_AUTO_FAN_0 || HAS_AUTO_FAN_1 || HAS_AUTO_FAN_2 || HAS_AUTO_FAN_3)
#define HAS_FAN0 (PIN_EXISTS(FAN)) #define HAS_FAN0 (PIN_EXISTS(FAN))
#define HAS_FAN1 (PIN_EXISTS(FAN1) && CONTROLLERFAN_PIN != FAN1_PIN && EXTRUDER_0_AUTO_FAN_PIN != FAN1_PIN && EXTRUDER_1_AUTO_FAN_PIN != FAN1_PIN && EXTRUDER_2_AUTO_FAN_PIN != FAN1_PIN) #define HAS_FAN1 (PIN_EXISTS(FAN1) && CONTROLLERFAN_PIN != FAN1_PIN && EXTRUDER_0_AUTO_FAN_PIN != FAN1_PIN && EXTRUDER_1_AUTO_FAN_PIN != FAN1_PIN && EXTRUDER_2_AUTO_FAN_PIN != FAN1_PIN && EXTRUDER_3_AUTO_FAN_PIN != FAN1_PIN)
#define HAS_FAN2 (PIN_EXISTS(FAN2) && CONTROLLERFAN_PIN != FAN2_PIN && EXTRUDER_0_AUTO_FAN_PIN != FAN2_PIN && EXTRUDER_1_AUTO_FAN_PIN != FAN2_PIN && EXTRUDER_2_AUTO_FAN_PIN != FAN2_PIN) #define HAS_FAN2 (PIN_EXISTS(FAN2) && CONTROLLERFAN_PIN != FAN2_PIN && EXTRUDER_0_AUTO_FAN_PIN != FAN2_PIN && EXTRUDER_1_AUTO_FAN_PIN != FAN2_PIN && EXTRUDER_2_AUTO_FAN_PIN != FAN2_PIN && EXTRUDER_3_AUTO_FAN_PIN != FAN2_PIN)
#define HAS_CONTROLLERFAN (PIN_EXISTS(CONTROLLERFAN)) #define HAS_CONTROLLERFAN (PIN_EXISTS(CONTROLLERFAN))
#define HAS_SERVOS (defined(NUM_SERVOS) && NUM_SERVOS > 0) #define HAS_SERVOS (defined(NUM_SERVOS) && NUM_SERVOS > 0)
#define HAS_SERVO_0 (PIN_EXISTS(SERVO0)) #define HAS_SERVO_0 (PIN_EXISTS(SERVO0))

@ -185,7 +185,7 @@ int Temperature::minttemp_raw[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_RAW_LO_TEMP ,
#endif #endif
#if HAS_AUTO_FAN #if HAS_AUTO_FAN
millis_t Temperature::next_auto_fan_check_ms; millis_t Temperature::next_auto_fan_check_ms = 0;
#endif #endif
unsigned char Temperature::soft_pwm[HOTENDS]; unsigned char Temperature::soft_pwm[HOTENDS];
@ -465,21 +465,21 @@ int Temperature::getHeaterPower(int heater) {
void Temperature::checkExtruderAutoFans() { void Temperature::checkExtruderAutoFans() {
const int8_t fanPin[] = { EXTRUDER_0_AUTO_FAN_PIN, EXTRUDER_1_AUTO_FAN_PIN, EXTRUDER_2_AUTO_FAN_PIN, EXTRUDER_3_AUTO_FAN_PIN }; const int8_t fanPin[] = { EXTRUDER_0_AUTO_FAN_PIN, EXTRUDER_1_AUTO_FAN_PIN, EXTRUDER_2_AUTO_FAN_PIN, EXTRUDER_3_AUTO_FAN_PIN };
const int fanBit[] = { 0, const int fanBit[] = {
EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN ? 0 : 1, 0,
EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN ? 0 : AUTO_1_IS_0 ? 0 : 1,
EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN ? 1 : 2, AUTO_2_IS_0 ? 0 : AUTO_2_IS_1 ? 1 : 2,
EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN ? 0 : AUTO_3_IS_0 ? 0 : AUTO_3_IS_1 ? 1 : AUTO_3_IS_2 ? 2 : 3
EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN ? 1 :
EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN ? 2 : 3
}; };
uint8_t fanState = 0; uint8_t fanState = 0;
HOTEND_LOOP() { HOTEND_LOOP() {
if (current_temperature[e] > EXTRUDER_AUTO_FAN_TEMPERATURE) if (current_temperature[e] > EXTRUDER_AUTO_FAN_TEMPERATURE)
SBI(fanState, fanBit[e]); SBI(fanState, fanBit[e]);
} }
uint8_t fanDone = 0; uint8_t fanDone = 0;
for (int8_t f = 0; f <= 3; f++) { for (int8_t f = 0; f < COUNT(fanPin); f++) {
int8_t pin = fanPin[f]; int8_t pin = fanPin[f];
if (pin >= 0 && !TEST(fanDone, fanBit[f])) { if (pin >= 0 && !TEST(fanDone, fanBit[f])) {
unsigned char newFanSpeed = TEST(fanState, fanBit[f]) ? EXTRUDER_AUTO_FAN_SPEED : 0; unsigned char newFanSpeed = TEST(fanState, fanBit[f]) ? EXTRUDER_AUTO_FAN_SPEED : 0;
@ -987,8 +987,6 @@ void Temperature::init() {
SET_OUTPUT(HEATER_BED_PIN); SET_OUTPUT(HEATER_BED_PIN);
#endif #endif
#if ENABLED(FAST_PWM_FAN) || ENABLED(FAN_SOFT_PWM)
#if HAS_FAN0 #if HAS_FAN0
SET_OUTPUT(FAN_PIN); SET_OUTPUT(FAN_PIN);
#if ENABLED(FAST_PWM_FAN) #if ENABLED(FAST_PWM_FAN)
@ -1019,8 +1017,6 @@ void Temperature::init() {
#endif #endif
#endif #endif
#endif // FAST_PWM_FAN || FAN_SOFT_PWM
#if ENABLED(HEATER_0_USES_MAX6675) #if ENABLED(HEATER_0_USES_MAX6675)
#if DISABLED(SDSUPPORT) #if DISABLED(SDSUPPORT)
@ -1068,17 +1064,45 @@ void Temperature::init() {
#endif #endif
#if HAS_AUTO_FAN_0 #if HAS_AUTO_FAN_0
#if EXTRUDER_0_AUTO_FAN_PIN == FAN1_PIN
SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
setPwmFrequency(EXTRUDER_0_AUTO_FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
#endif
#else
pinMode(EXTRUDER_0_AUTO_FAN_PIN, OUTPUT); pinMode(EXTRUDER_0_AUTO_FAN_PIN, OUTPUT);
#endif #endif
#if HAS_AUTO_FAN_1 && (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) #endif
#if HAS_AUTO_FAN_1 && !AUTO_1_IS_0
#if EXTRUDER_1_AUTO_FAN_PIN == FAN1_PIN
SET_OUTPUT(EXTRUDER_1_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
setPwmFrequency(EXTRUDER_1_AUTO_FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
#endif
#else
pinMode(EXTRUDER_1_AUTO_FAN_PIN, OUTPUT); pinMode(EXTRUDER_1_AUTO_FAN_PIN, OUTPUT);
#endif #endif
#if HAS_AUTO_FAN_2 && (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) && (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN) #endif
#if HAS_AUTO_FAN_2 && !AUTO_2_IS_0 && !AUTO_2_IS_1
#if EXTRUDER_2_AUTO_FAN_PIN == FAN1_PIN
SET_OUTPUT(EXTRUDER_2_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
setPwmFrequency(EXTRUDER_2_AUTO_FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
#endif
#else
pinMode(EXTRUDER_2_AUTO_FAN_PIN, OUTPUT); pinMode(EXTRUDER_2_AUTO_FAN_PIN, OUTPUT);
#endif #endif
#if HAS_AUTO_FAN_3 && (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) && (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN) && (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_2_AUTO_FAN_PIN) #endif
#if HAS_AUTO_FAN_3 && !AUTO_3_IS_0 && !AUTO_3_IS_1 && !AUTO_3_IS_2
#if EXTRUDER_3_AUTO_FAN_PIN == FAN1_PIN
SET_OUTPUT(EXTRUDER_3_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
setPwmFrequency(EXTRUDER_3_AUTO_FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
#endif
#else
pinMode(EXTRUDER_3_AUTO_FAN_PIN, OUTPUT); pinMode(EXTRUDER_3_AUTO_FAN_PIN, OUTPUT);
#endif #endif
#endif
// Use timer0 for temperature measurement // Use timer0 for temperature measurement
// Interleave temperature interrupt with millies interrupt // Interleave temperature interrupt with millies interrupt

Loading…
Cancel
Save