mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-19 22:19:10 +08:00
Merge pull request #134 from qjones81/timer-fix
Fix microsecond timer delay code.
This commit is contained in:
@@ -69,6 +69,8 @@
|
||||
#define TIM_APB1_CLOCK_HZ 84000000
|
||||
#define TIM_APB1_PERIOD_CLOCKS 4096
|
||||
#define TIM_APB1_DEADTIME_CLOCKS 40
|
||||
#define TIM_TIME_BASE TIM14
|
||||
|
||||
|
||||
#define M0_nCS_Pin GPIO_PIN_13
|
||||
#define M0_nCS_GPIO_Port GPIOC
|
||||
|
||||
@@ -187,13 +187,13 @@ uint32_t timeout_to_deadline(uint32_t timeout_ms) {
|
||||
|
||||
// @brief: Returns number of microseconds since system startup
|
||||
uint32_t micros(void) {
|
||||
uint32_t usTicks = HAL_RCC_GetSysClockFreq() / 1000000;
|
||||
register uint32_t ms, cycle_cnt;
|
||||
do {
|
||||
ms = HAL_GetTick();
|
||||
cycle_cnt = SysTick->VAL;
|
||||
} while (ms != HAL_GetTick());
|
||||
return (ms * 1000) + (usTicks * 1000 - cycle_cnt) / usTicks;
|
||||
cycle_cnt = TIM_TIME_BASE->CNT;
|
||||
} while (ms != HAL_GetTick());
|
||||
|
||||
return (ms * 1000) + cycle_cnt;
|
||||
}
|
||||
|
||||
// @brief: Busy wait delay for given amount of microseconds (us)
|
||||
@@ -203,4 +203,4 @@ void delay_us(uint32_t us)
|
||||
while (micros() - start < (uint32_t) us) {
|
||||
__ASM("nop");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user