From 1748e3258b23217803802e046947ff8b5de099c0 Mon Sep 17 00:00:00 2001 From: midopple Date: Fri, 30 Mar 2012 11:02:05 +0300 Subject: Command M106 / M107 for control the fan can use PWM New function to check the used PWM pins --- Sprinter/Sprinter.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprinter/Sprinter.h b/Sprinter/Sprinter.h index 9873843..66e6c59 100644 --- a/Sprinter/Sprinter.h +++ b/Sprinter/Sprinter.h @@ -91,6 +91,7 @@ typedef struct { void FlushSerialRequestResend(); void ClearToSend(); +void analogWrite_check(uint8_t check_pin, int val); void showString (PGM_P s); void manage_inactivity(byte debug); -- cgit v1.2.1 From 52f7f3040874dc8b2ef4b0d570f7fa9d0291dfc3 Mon Sep 17 00:00:00 2001 From: midopple Date: Fri, 30 Mar 2012 11:03:41 +0300 Subject: Command M106 / M107 for control the fan can use PWM New function to check the used PWM pins --- Sprinter/Sprinter.pde | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 53d42b8..308ee19 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -554,6 +554,39 @@ int FreeRam1(void) return free_memory; } +//------------------------------------------------ +//Function the check the Analog OUT pin for not using the Timer1 +//------------------------------------------------ +void analogWrite_check(uint8_t check_pin, int val) +{ + #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) + //Atmega168 / 328 can not useed OCR1A and OCR1B + //This are PINS PB1 / PB2 or on Ardurino D9 / D10 + if((check_pin != 9) && (check_pin != 10)) + { + analogWrite(check_pin, val); + } + #endif + + #if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) + //Atmega664P / 1284P can not useed OCR1A and OCR1B + //This are PINS PD4 / PD5 or on Ardurino D12 / D13 + if((check_pin != 12) && (check_pin != 13)) + { + analogWrite(check_pin, val); + } + #endif + + #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) + //Atmega1280 / 2560 can not useed OCR1A, OCR1B and OCR1C + //This are PINS PB5,PB6,PB7 or on Ardurino D11,D12,and D13 + if((check_pin != 11) && (check_pin != 12) && (check_pin != 13)) + { + analogWrite(check_pin, val); + } + #endif +} + //------------------------------------------------ //Print a String from Flash to Serial (save RAM) //------------------------------------------------ @@ -1499,16 +1532,16 @@ FORCE_INLINE void process_commands() if (code_seen('S')) { WRITE(FAN_PIN, HIGH); - //analogWrite(FAN_PIN, constrain(code_value(),0,255) ); + analogWrite_check(FAN_PIN, constrain(code_value(),0,255) ); } else { WRITE(FAN_PIN, HIGH); - //analogWrite(FAN_PIN, 255 ); + analogWrite_check(FAN_PIN, 255 ); } break; case 107: //M107 Fan Off - //analogWrite(FAN_PIN, 0); + analogWrite_check(FAN_PIN, 0); WRITE(FAN_PIN, LOW); break; #endif -- cgit v1.2.1