소스 검색

Use timer3 instead of timer5 on miniRambo

Alex Voinea 1 년 전
부모
커밋
f2f136e014
6개의 변경된 파일55개의 추가작업 그리고 23개의 파일을 삭제
  1. 2 3
      Firmware/MarlinSerial.h
  2. 3 0
      Firmware/macros.h
  3. 3 0
      Firmware/pins_Einsy_1_0.h
  4. 2 0
      Firmware/pins_Rambo_1_0.h
  5. 2 0
      Firmware/pins_Rambo_1_3.h
  6. 43 20
      Firmware/temperature.cpp

+ 2 - 3
Firmware/MarlinSerial.h

@@ -37,11 +37,10 @@
 						
 // These are macros to build serial port register names for the selected SERIAL_PORT (C preprocessor
 // requires two levels of indirection to expand macro values properly)
-#define SERIAL_REGNAME(registerbase,number,suffix) SERIAL_REGNAME_INTERNAL(registerbase,number,suffix)
 #if SERIAL_PORT == 0 && (!defined(UBRR0H) || !defined(UDR0)) // use un-numbered registers if necessary
-#define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##suffix
+#define SERIAL_REGNAME(registerbase,number,suffix) _REGNAME_SHORT(registerbase, suffix)
 #else
-#define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix
+#define SERIAL_REGNAME(registerbase,number,suffix) _REGNAME(registerbase, number, suffix)
 #endif
 
 // Registers used by MarlinSerial class (these are expanded 

+ 3 - 0
Firmware/macros.h

@@ -11,6 +11,9 @@
   #define CRITICAL_SECTION_END    SREG = _sreg;
 #endif //CRITICAL_SECTION_START
 
+#define _REGNAME(registerbase,number,suffix) registerbase##number##suffix
+#define _REGNAME_SHORT(registerbase,suffix) registerbase##suffix
+
 // Macros to make a string from a macro
 #define STRINGIFY_(M) #M
 #define STRINGIFY(M) STRINGIFY_(M)

+ 3 - 0
Firmware/pins_Einsy_1_0.h

@@ -78,6 +78,9 @@
 #define VOLT_IR_PIN          8 //A8
 
 
+#define TEMP_TIM 5
+
+
 #define E0_TMC2130_CS       66
 #define E0_TMC2130_DIAG     65
 #define E0_STEP_PIN         34

+ 2 - 0
Firmware/pins_Rambo_1_0.h

@@ -57,6 +57,8 @@
 #define TEMP_PINDA_PIN          1 //A1
 
 
+#define TEMP_TIM 3
+
 
 #define E0_STEP_PIN            34
 #define E0_DIR_PIN             43

+ 2 - 0
Firmware/pins_Rambo_1_3.h

@@ -60,6 +60,8 @@
 #define TEMP_PINDA_PIN          1 //A1
 
 
+#define TEMP_TIM 3
+
 
 #define E0_STEP_PIN            34
 #define E0_DIR_PIN             43

+ 43 - 20
Firmware/temperature.cpp

@@ -60,13 +60,36 @@
 
 // temperature manager timer configuration
 #define TEMP_MGR_INTV   0.27 // seconds, ~3.7Hz
-#define TIMER5_PRESCALE 256
-#define TIMER5_OCRA_OVF (uint16_t)(TEMP_MGR_INTV / ((long double)TIMER5_PRESCALE / F_CPU))
-#define TEMP_MGR_INT_FLAG_STATE()    (TIFR5 & (1<<OCF5A))
-#define TEMP_MGR_INT_FLAG_CLEAR()    TIFR5 |= (1<<OCF5A)
-#define TEMP_MGR_INTERRUPT_STATE()   (TIMSK5 & (1<<OCIE5A))
-#define ENABLE_TEMP_MGR_INTERRUPT()  TIMSK5 |=  (1<<OCIE5A)
-#define DISABLE_TEMP_MGR_INTERRUPT() TIMSK5 &= ~(1<<OCIE5A)
+#define TEMP_TIM_PRESCALE 256
+#define TEMP_TIM_OCRA_OVF (uint16_t)(TEMP_MGR_INTV / ((long double)TEMP_TIM_PRESCALE / F_CPU))
+#define TEMP_TIM_REGNAME(registerbase,number,suffix) _REGNAME(registerbase,number,suffix)
+#undef B0 //Necessary hack because of "binary.h" included in "Arduino.h" included in "system_timer.h" included in this file...
+#define TCCRxA TEMP_TIM_REGNAME(TCCR, TEMP_TIM, A)
+#define TCCRxB TEMP_TIM_REGNAME(TCCR, TEMP_TIM, B)
+#define TCCRxC TEMP_TIM_REGNAME(TCCR, TEMP_TIM, C)
+#define TCNTx TEMP_TIM_REGNAME(TCNT, TEMP_TIM,)
+#define OCRxA TEMP_TIM_REGNAME(OCR, TEMP_TIM, A)
+#define TIMSKx TEMP_TIM_REGNAME(TIMSK, TEMP_TIM,)
+#define TIFRx TEMP_TIM_REGNAME(TIFR, TEMP_TIM,)
+#define TIMERx_COMPA_vect TEMP_TIM_REGNAME(TIMER, TEMP_TIM, _COMPA_vect)
+#define CSx0 TEMP_TIM_REGNAME(CS, TEMP_TIM, 0)
+#define CSx1 TEMP_TIM_REGNAME(CS, TEMP_TIM, 1)
+#define CSx2 TEMP_TIM_REGNAME(CS, TEMP_TIM, 2)
+#define WGMx0 TEMP_TIM_REGNAME(WGM, TEMP_TIM, 0)
+#define WGMx1 TEMP_TIM_REGNAME(WGM, TEMP_TIM, 1)
+#define WGMx2 TEMP_TIM_REGNAME(WGM, TEMP_TIM, 2)
+#define WGMx3 TEMP_TIM_REGNAME(WGM, TEMP_TIM, 3)
+#define COMxA0 TEMP_TIM_REGNAME(COM, TEMP_TIM, A0)
+#define COMxB0 TEMP_TIM_REGNAME(COM, TEMP_TIM, B0)
+#define COMxC0 TEMP_TIM_REGNAME(COM, TEMP_TIM, C0)
+#define OCIExA TEMP_TIM_REGNAME(OCIE, TEMP_TIM, A)
+#define OCFxA TEMP_TIM_REGNAME(OCF, TEMP_TIM, A)
+
+#define TEMP_MGR_INT_FLAG_STATE()    (TIFRx & (1<<OCFxA))
+#define TEMP_MGR_INT_FLAG_CLEAR()    TIFRx |= (1<<OCFxA)
+#define TEMP_MGR_INTERRUPT_STATE()   (TIMSKx & (1<<OCIExA))
+#define ENABLE_TEMP_MGR_INTERRUPT()  TIMSKx |=  (1<<OCIExA)
+#define DISABLE_TEMP_MGR_INTERRUPT() TIMSKx &= ~(1<<OCIExA)
 
 #ifdef TEMP_MODEL
 // temperature model interface
@@ -1837,27 +1860,27 @@ void temp_mgr_init()
     adc_init();
     adc_start_cycle();
 
-    // initialize timer5
+    // initialize temperature timer
     ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
 
         // CTC
-        TCCR5B &= ~(1<<WGM53);
-        TCCR5B |=  (1<<WGM52);
-        TCCR5A &= ~(1<<WGM51);
-        TCCR5A &= ~(1<<WGM50);
+        TCCRxB &= ~(1<<WGMx3);
+        TCCRxB |=  (1<<WGMx2);
+        TCCRxA &= ~(1<<WGMx1);
+        TCCRxA &= ~(1<<WGMx0);
 
         // output mode = 00 (disconnected)
-        TCCR5A &= ~(3<<COM5A0);
-        TCCR5A &= ~(3<<COM5B0);
+        TCCRxA &= ~(3<<COMxA0);
+        TCCRxA &= ~(3<<COMxB0);
 
         // x/256 prescaler
-        TCCR5B |=  (1<<CS52);
-        TCCR5B &= ~(1<<CS51);
-        TCCR5B &= ~(1<<CS50);
+        TCCRxB |=  (1<<CSx2);
+        TCCRxB &= ~(1<<CSx1);
+        TCCRxB &= ~(1<<CSx0);
 
         // reset counter
-        TCNT5 = 0;
-        OCR5A = TIMER5_OCRA_OVF;
+        TCNTx = 0;
+        OCRxA = TEMP_TIM_OCRA_OVF;
 
         // clear pending interrupts, enable COMPA
         TEMP_MGR_INT_FLAG_CLEAR();
@@ -2178,7 +2201,7 @@ static void temp_mgr_isr()
         temp_mgr_pid();
 }
 
-ISR(TIMER5_COMPA_vect)
+ISR(TIMERx_COMPA_vect)
 {
     // immediately schedule a new conversion
     if(adc_values_ready != true) return;