Add HAL_timer_start to HAL.h
Co-Authored-By: ejtagle <ejtagle@hotmail.com>
This commit is contained in:
parent
1b1e15623a
commit
63af814d4d
34
Marlin/HAL.h
34
Marlin/HAL.h
@ -100,7 +100,8 @@ inline uint8_t HAL_get_reset_source(void) { return MCUSR; }
|
|||||||
#define STEPPER_TIMER_PRESCALE 8
|
#define STEPPER_TIMER_PRESCALE 8
|
||||||
#define STEP_TIMER_MIN_INTERVAL 8 // minimum time in µs between stepper interrupts
|
#define STEP_TIMER_MIN_INTERVAL 8 // minimum time in µs between stepper interrupts
|
||||||
|
|
||||||
#define TEMP_TIMER_FREQUENCY ((F_CPU) / 64.0 / 256.0)
|
#define TEMP_TIMER_PRESCALE 64
|
||||||
|
#define TEMP_TIMER_FREQUENCY ((F_CPU) / float(TEMP_TIMER_PRESCALE) / 256.0)
|
||||||
|
|
||||||
#define TIMER_OCR_1 OCR1A
|
#define TIMER_OCR_1 OCR1A
|
||||||
#define TIMER_COUNTER_1 TCNT1
|
#define TIMER_COUNTER_1 TCNT1
|
||||||
@ -118,7 +119,36 @@ inline uint8_t HAL_get_reset_source(void) { return MCUSR; }
|
|||||||
#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
|
#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
|
||||||
#define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0B)
|
#define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0B)
|
||||||
|
|
||||||
#define HAL_timer_start(timer_num, frequency)
|
FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||||
|
UNUSED(frequency);
|
||||||
|
switch (timer_num) {
|
||||||
|
case STEP_TIMER_NUM:
|
||||||
|
// waveform generation = 0100 = CTC
|
||||||
|
SET_WGM(1, CTC_OCRnA);
|
||||||
|
|
||||||
|
// output mode = 00 (disconnected)
|
||||||
|
SET_COMA(1, NORMAL);
|
||||||
|
|
||||||
|
// Set the timer pre-scaler
|
||||||
|
// Generally we use a divider of 8, resulting in a 2MHz timer
|
||||||
|
// frequency on a 16MHz MCU. If you are going to change this, be
|
||||||
|
// sure to regenerate speed_lookuptable.h with
|
||||||
|
// create_speed_lookuptable.py
|
||||||
|
SET_CS(1, PRESCALER_8); // CS 2 = 1/8 prescaler
|
||||||
|
|
||||||
|
// Init Stepper ISR to 122 Hz for quick starting
|
||||||
|
// (F_CPU) / (STEPPER_TIMER_PRESCALE) / frequency
|
||||||
|
OCR1A = 0x4000;
|
||||||
|
TCNT1 = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TEMP_TIMER_NUM:
|
||||||
|
// Use timer0 for temperature measurement
|
||||||
|
// Interleave temperature interrupt with millies interrupt
|
||||||
|
OCR0B = 128;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define _CAT(a, ...) a ## __VA_ARGS__
|
#define _CAT(a, ...) a ## __VA_ARGS__
|
||||||
#define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
|
#define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
|
||||||
|
@ -1947,22 +1947,8 @@ void Stepper::init() {
|
|||||||
E_AXIS_INIT(4);
|
E_AXIS_INIT(4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// waveform generation = 0100 = CTC
|
|
||||||
SET_WGM(1, CTC_OCRnA);
|
|
||||||
|
|
||||||
// output mode = 00 (disconnected)
|
|
||||||
SET_COMA(1, NORMAL);
|
|
||||||
|
|
||||||
// Set the timer pre-scaler
|
|
||||||
// Generally we use a divider of 8, resulting in a 2MHz timer
|
|
||||||
// frequency on a 16MHz MCU. If you are going to change this, be
|
|
||||||
// sure to regenerate speed_lookuptable.h with
|
|
||||||
// create_speed_lookuptable.py
|
|
||||||
SET_CS(1, PRESCALER_8); // CS 2 = 1/8 prescaler
|
|
||||||
|
|
||||||
// Init Stepper ISR to 122 Hz for quick starting
|
// Init Stepper ISR to 122 Hz for quick starting
|
||||||
OCR1A = 0x4000;
|
HAL_timer_start(STEP_TIMER_NUM, 122); // OCR1A = 0x4000
|
||||||
TCNT1 = 0;
|
|
||||||
|
|
||||||
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
||||||
|
|
||||||
|
@ -1209,9 +1209,7 @@ void Temperature::init() {
|
|||||||
HAL_ANALOG_SELECT(FILWIDTH_PIN);
|
HAL_ANALOG_SELECT(FILWIDTH_PIN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Use timer0 for temperature measurement
|
HAL_timer_start(TEMP_TIMER_NUM, TEMP_TIMER_FREQUENCY);
|
||||||
// Interleave temperature interrupt with millies interrupt
|
|
||||||
OCR0B = 128;
|
|
||||||
ENABLE_TEMPERATURE_INTERRUPT();
|
ENABLE_TEMPERATURE_INTERRUPT();
|
||||||
|
|
||||||
#if HAS_AUTO_FAN_0
|
#if HAS_AUTO_FAN_0
|
||||||
|
Loading…
Reference in New Issue
Block a user