Merge pull request #7890 from thinkyhead/bf2_integer_HAL_TIMER_RATE
[2.0.x] Apply fixes for DUE
This commit is contained in:
commit
f63e546b3e
@ -102,10 +102,10 @@ extern "C" {
|
||||
#define TEMP_TIMER_NUM 0
|
||||
#define TEMP_TIMER_FREQUENCY (F_CPU / 64.0 / 256.0)
|
||||
|
||||
#define HAL_TIMER_RATE ((F_CPU) / 8.0)
|
||||
#define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE
|
||||
#define STEPPER_TIMER_PRESCALE INT0_PRESCALER
|
||||
#define HAL_TICKS_PER_US (((F_CPU) / 8) / 1000000) // Can not be of type double
|
||||
#define HAL_TIMER_RATE ((F_CPU) / 8) // i.e., 2MHz or 2.5MHz
|
||||
#define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE
|
||||
#define STEPPER_TIMER_PRESCALE INT0_PRESCALER
|
||||
#define HAL_TICKS_PER_US ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
|
||||
|
||||
#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
|
||||
#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
|
||||
|
@ -46,7 +46,7 @@
|
||||
#define STEP_TIMER_NUM 3 // index of timer to use for stepper
|
||||
#define TEMP_TIMER_NUM 4 // index of timer to use for temperature
|
||||
|
||||
#define HAL_TIMER_RATE ((F_CPU) / 2.0) // frequency of timers peripherals
|
||||
#define HAL_TIMER_RATE ((F_CPU) / 2) // frequency of timers peripherals
|
||||
#define STEPPER_TIMER_PRESCALE 1.0 // prescaler for setting stepper frequency
|
||||
#define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
|
||||
#define HAL_TICKS_PER_US ((HAL_STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per us
|
||||
|
@ -33,22 +33,22 @@
|
||||
|
||||
void HAL_timer_init(void) {
|
||||
SBI(LPC_SC->PCONP, 1); // power on timer0
|
||||
LPC_TIM0->PR = ((HAL_TIMER_RATE / HAL_STEPPER_TIMER_RATE) - 1); // Use prescaler to set frequency if needed
|
||||
LPC_TIM0->PR = (HAL_TIMER_RATE) / (HAL_STEPPER_TIMER_RATE) - 1; // Use prescaler to set frequency if needed
|
||||
|
||||
SBI(LPC_SC->PCONP, 2); // power on timer1
|
||||
LPC_TIM1->PR = ((HAL_TIMER_RATE / 1000000) - 1);
|
||||
LPC_TIM1->PR = (HAL_TIMER_RATE) / 1000000 - 1;
|
||||
}
|
||||
|
||||
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
switch (timer_num) {
|
||||
case 0:
|
||||
LPC_TIM0->MCR = 3; // Match on MR0, reset on MR0
|
||||
LPC_TIM0->MR0 = (uint32_t)(HAL_STEPPER_TIMER_RATE / frequency); // Match value (period) to set frequency
|
||||
LPC_TIM0->MR0 = uint32_t(HAL_STEPPER_TIMER_RATE) / frequency; // Match value (period) to set frequency
|
||||
LPC_TIM0->TCR = _BV(0); // enable
|
||||
break;
|
||||
case 1:
|
||||
LPC_TIM1->MCR = 3;
|
||||
LPC_TIM1->MR0 = (uint32_t)(HAL_TEMP_TIMER_RATE / frequency);;
|
||||
LPC_TIM1->MR0 = uint32_t(HAL_TEMP_TIMER_RATE) / frequency;
|
||||
LPC_TIM1->TCR = _BV(0);
|
||||
break;
|
||||
default: break;
|
||||
|
@ -93,14 +93,14 @@ Timer_clock4: Prescaler 128 -> 656.25kHz
|
||||
* TODO: Calculate Timer prescale value, so we get the 32bit to adjust
|
||||
*/
|
||||
|
||||
void HAL_timer_start (uint8_t timer_num, uint32_t frequency) {
|
||||
void HAL_timer_start(uint8_t timer_num, uint32_t frequency) {
|
||||
switch (timer_num) {
|
||||
case STEP_TIMER_NUM:
|
||||
StepperTimer.pause();
|
||||
StepperTimer.setCount(0);
|
||||
StepperTimer.setPrescaleFactor(STEPPER_TIMER_PRESCALE);
|
||||
StepperTimer.setOverflow(0xFFFF);
|
||||
StepperTimer.setCompare (STEP_TIMER_CHAN, (HAL_STEPPER_TIMER_RATE / frequency));
|
||||
StepperTimer.setCompare(STEP_TIMER_CHAN, uint32_t(HAL_STEPPER_TIMER_RATE) / frequency);
|
||||
StepperTimer.refresh();
|
||||
StepperTimer.resume();
|
||||
break;
|
||||
@ -109,14 +109,14 @@ void HAL_timer_start (uint8_t timer_num, uint32_t frequency) {
|
||||
TempTimer.setCount(0);
|
||||
TempTimer.setPrescaleFactor(TEMP_TIMER_PRESCALE);
|
||||
TempTimer.setOverflow(0xFFFF);
|
||||
TempTimer.setCompare (TEMP_TIMER_CHAN, ((F_CPU / TEMP_TIMER_PRESCALE) / frequency));
|
||||
TempTimer.setCompare(TEMP_TIMER_CHAN, (F_CPU) / (TEMP_TIMER_PRESCALE) / frequency);
|
||||
TempTimer.refresh();
|
||||
TempTimer.resume();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_timer_enable_interrupt (uint8_t timer_num) {
|
||||
void HAL_timer_enable_interrupt(uint8_t timer_num) {
|
||||
switch (timer_num) {
|
||||
case STEP_TIMER_NUM:
|
||||
StepperTimer.attachInterrupt(STEP_TIMER_CHAN, stepTC_Handler);
|
||||
@ -129,7 +129,7 @@ void HAL_timer_enable_interrupt (uint8_t timer_num) {
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_timer_disable_interrupt (uint8_t timer_num) {
|
||||
void HAL_timer_disable_interrupt(uint8_t timer_num) {
|
||||
switch (timer_num) {
|
||||
case STEP_TIMER_NUM:
|
||||
StepperTimer.detachInterrupt(STEP_TIMER_CHAN);
|
||||
|
@ -59,7 +59,7 @@
|
||||
|
||||
#define HAL_TIMER_RATE (FTM0_TIMER_RATE)
|
||||
#define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE
|
||||
#define HAL_TICKS_PER_US (HAL_STEPPER_TIMER_RATE/1000000)
|
||||
#define HAL_TICKS_PER_US ((HAL_STEPPER_TIMER_RATE) / 1000000)
|
||||
|
||||
#define TEMP_TIMER_FREQUENCY 1000
|
||||
|
||||
|
@ -224,7 +224,7 @@ inline void servo_probe_test() {
|
||||
* - Machine continues to operate
|
||||
* - Reports changes to endstops
|
||||
* - Toggles LED_PIN when an endstop changes
|
||||
* - Can not reliably catch the 5mS pulse from BLTouch type probes
|
||||
* - Cannot reliably catch the 5mS pulse from BLTouch type probes
|
||||
*
|
||||
* M43 T - Toggle pin(s) and report which pin is being toggled
|
||||
* S<pin> - Start Pin number. If not given, will default to 0
|
||||
|
@ -207,7 +207,7 @@
|
||||
/**
|
||||
* Hidden options for developer
|
||||
*/
|
||||
// Double stepping start from STEP_DOUBLER_FREQUENCY + 1, quad stepping start from STEP_DOUBLER_FREQUENCY * 2 + 1
|
||||
// Double stepping starts at STEP_DOUBLER_FREQUENCY + 1, quad stepping starts at STEP_DOUBLER_FREQUENCY * 2 + 1
|
||||
#ifndef STEP_DOUBLER_FREQUENCY
|
||||
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
||||
#define STEP_DOUBLER_FREQUENCY 60000 // Hz
|
||||
|
@ -303,10 +303,9 @@ class Stepper {
|
||||
|
||||
#ifdef CPU_32_BIT
|
||||
// In case of high-performance processor, it is able to calculate in real-time
|
||||
timer = (uint32_t)(HAL_STEPPER_TIMER_RATE) / step_rate;
|
||||
if (timer < (HAL_STEPPER_TIMER_RATE / (STEP_DOUBLER_FREQUENCY * 2))) { // (STEP_DOUBLER_FREQUENCY * 2 kHz - this should never happen)
|
||||
timer = (HAL_STEPPER_TIMER_RATE / (STEP_DOUBLER_FREQUENCY * 2));
|
||||
}
|
||||
constexpr uint32_t MIN_TIME_PER_STEP = (HAL_STEPPER_TIMER_RATE) / ((STEP_DOUBLER_FREQUENCY) * 2);
|
||||
timer = uint32_t(HAL_STEPPER_TIMER_RATE) / step_rate;
|
||||
NOLESS(timer, MIN_TIME_PER_STEP); // (STEP_DOUBLER_FREQUENCY * 2 kHz - this should never happen)
|
||||
#else
|
||||
NOLESS(step_rate, F_CPU / 500000);
|
||||
step_rate -= F_CPU / 500000; // Correct for minimal speed
|
||||
|
Loading…
Reference in New Issue
Block a user