Use timer3 instead of timer5 on miniRambo

This commit is contained in:
Alex Voinea 2022-08-24 10:18:45 +03:00
parent 7907e14cbf
commit f2f136e014
6 changed files with 55 additions and 23 deletions

View File

@ -37,11 +37,10 @@
// These are macros to build serial port register names for the selected SERIAL_PORT (C preprocessor // 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) // 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 #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 #else
#define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix #define SERIAL_REGNAME(registerbase,number,suffix) _REGNAME(registerbase, number, suffix)
#endif #endif
// Registers used by MarlinSerial class (these are expanded // Registers used by MarlinSerial class (these are expanded

View File

@ -11,6 +11,9 @@
#define CRITICAL_SECTION_END SREG = _sreg; #define CRITICAL_SECTION_END SREG = _sreg;
#endif //CRITICAL_SECTION_START #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 // Macros to make a string from a macro
#define STRINGIFY_(M) #M #define STRINGIFY_(M) #M
#define STRINGIFY(M) STRINGIFY_(M) #define STRINGIFY(M) STRINGIFY_(M)

View File

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

View File

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

View File

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

View File

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