Add HAL_timer_start for AVR, use stepper timer to time pulses
This commit is contained in:
parent
e970e429b6
commit
3701869e6c
|
@ -34,6 +34,7 @@
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
|
#include "HAL.h"
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// Externals
|
// Externals
|
||||||
|
@ -74,9 +75,11 @@
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
#if ENABLED(SDSUPPORT)
|
#if ENABLED(SDSUPPORT)
|
||||||
|
|
||||||
#include "../../sd/SdFatUtil.h"
|
#include "../../sd/SdFatUtil.h"
|
||||||
int freeMemory() { return SdFatUtil::FreeRam(); }
|
int freeMemory() { return SdFatUtil::FreeRam(); }
|
||||||
#else
|
|
||||||
|
#else // !SDSUPPORT
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern char __bss_end;
|
extern char __bss_end;
|
||||||
|
@ -93,7 +96,6 @@ extern "C" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //!SDSUPPORT
|
#endif // !SDSUPPORT
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif // __AVR__
|
||||||
|
|
|
@ -124,7 +124,7 @@ extern "C" {
|
||||||
|
|
||||||
#define STEP_TIMER_NUM 1
|
#define STEP_TIMER_NUM 1
|
||||||
#define TEMP_TIMER_NUM 0
|
#define TEMP_TIMER_NUM 0
|
||||||
#define PULSE_TIMER_NUM TEMP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
|
||||||
#define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE
|
#define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE
|
||||||
#define HAL_TICKS_PER_US ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
|
#define HAL_TICKS_PER_US ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
|
||||||
|
@ -139,7 +139,7 @@ extern "C" {
|
||||||
#define TIMER_OCR_0 OCR0A
|
#define TIMER_OCR_0 OCR0A
|
||||||
#define TIMER_COUNTER_0 TCNT0
|
#define TIMER_COUNTER_0 TCNT0
|
||||||
|
|
||||||
#define PULSE_TIMER_PRESCALE 8
|
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
||||||
|
|
||||||
#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
|
#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
|
||||||
#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
|
||||||
|
@ -149,7 +149,36 @@ extern "C" {
|
||||||
#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)
|
||||||
|
|
|
@ -1993,27 +1993,8 @@ void Stepper::init() {
|
||||||
E_AXIS_INIT(4);
|
E_AXIS_INIT(4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __AVR__
|
|
||||||
// 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
|
|
||||||
OCR1A = 0x4000;
|
|
||||||
TCNT1 = 0;
|
|
||||||
#else
|
|
||||||
// Init Stepper ISR to 122 Hz for quick starting
|
// Init Stepper ISR to 122 Hz for quick starting
|
||||||
HAL_timer_start(STEP_TIMER_NUM, 122);
|
HAL_timer_start(STEP_TIMER_NUM, 122);
|
||||||
#endif
|
|
||||||
|
|
||||||
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
||||||
|
|
||||||
|
|
|
@ -1234,14 +1234,7 @@ void Temperature::init() {
|
||||||
HAL_ANALOG_SELECT(FILWIDTH_PIN);
|
HAL_ANALOG_SELECT(FILWIDTH_PIN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// todo: HAL: fix abstraction
|
|
||||||
#ifdef __AVR__
|
|
||||||
// Use timer0 for temperature measurement
|
|
||||||
// Interleave temperature interrupt with millies interrupt
|
|
||||||
OCR0B = 128;
|
|
||||||
#else
|
|
||||||
HAL_timer_start(TEMP_TIMER_NUM, TEMP_TIMER_FREQUENCY);
|
HAL_timer_start(TEMP_TIMER_NUM, TEMP_TIMER_FREQUENCY);
|
||||||
#endif
|
|
||||||
ENABLE_TEMPERATURE_INTERRUPT();
|
ENABLE_TEMPERATURE_INTERRUPT();
|
||||||
|
|
||||||
#if HAS_AUTO_FAN_0
|
#if HAS_AUTO_FAN_0
|
||||||
|
|
Loading…
Reference in a new issue