mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-07 13:28:48 +00:00
[fix][timer] fix timing that cause inaccurate
This commit is contained in:
parent
673ba04e8e
commit
5b9495137c
1 changed files with 38 additions and 9 deletions
|
@ -368,10 +368,6 @@ BL_Err_Type TIMER_Init(TIMER_CFG_Type *timerCfg)
|
||||||
CHECK_PARAM(IS_TIMER_PRELOAD_TRIG_TYPE(timerCfg->plTrigSrc));
|
CHECK_PARAM(IS_TIMER_PRELOAD_TRIG_TYPE(timerCfg->plTrigSrc));
|
||||||
CHECK_PARAM(IS_TIMER_COUNTMODE_TYPE(timerCfg->countMode));
|
CHECK_PARAM(IS_TIMER_COUNTMODE_TYPE(timerCfg->countMode));
|
||||||
|
|
||||||
if (timerCfg->matchVal0 < 2 || timerCfg->matchVal1 < 2 || timerCfg->matchVal2 < 2) {
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Configure timer clock source */
|
/* Configure timer clock source */
|
||||||
tmpVal = BL_RD_REG(TIMER_BASE, TIMER_TCCR);
|
tmpVal = BL_RD_REG(TIMER_BASE, TIMER_TCCR);
|
||||||
|
|
||||||
|
@ -403,12 +399,45 @@ BL_Err_Type TIMER_Init(TIMER_CFG_Type *timerCfg)
|
||||||
if (timerCfg->countMode == TIMER_COUNT_PRELOAD) {
|
if (timerCfg->countMode == TIMER_COUNT_PRELOAD) {
|
||||||
/* Configure timer preload value */
|
/* Configure timer preload value */
|
||||||
TIMER_SetPreloadValue(timerCh, timerCfg->preLoadVal);
|
TIMER_SetPreloadValue(timerCh, timerCfg->preLoadVal);
|
||||||
}
|
|
||||||
|
|
||||||
/* Configure match compare values */
|
/* Configure match compare values */
|
||||||
|
if (timerCfg->matchVal0 > 1 + timerCfg->preLoadVal) {
|
||||||
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_0, timerCfg->matchVal0 - 2);
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_0, timerCfg->matchVal0 - 2);
|
||||||
|
} else {
|
||||||
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_0, timerCfg->matchVal0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timerCfg->matchVal1 > 1 + timerCfg->preLoadVal) {
|
||||||
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_1, timerCfg->matchVal1 - 2);
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_1, timerCfg->matchVal1 - 2);
|
||||||
|
} else {
|
||||||
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_1, timerCfg->matchVal1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timerCfg->matchVal2 > 1 + timerCfg->preLoadVal) {
|
||||||
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_2, timerCfg->matchVal2 - 2);
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_2, timerCfg->matchVal2 - 2);
|
||||||
|
} else {
|
||||||
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_2, timerCfg->matchVal2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Configure match compare values */
|
||||||
|
if (timerCfg->matchVal0 > 1) {
|
||||||
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_0, timerCfg->matchVal0 - 2);
|
||||||
|
} else {
|
||||||
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_0, timerCfg->matchVal0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timerCfg->matchVal1 > 1) {
|
||||||
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_1, timerCfg->matchVal1 - 2);
|
||||||
|
} else {
|
||||||
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_1, timerCfg->matchVal1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timerCfg->matchVal2 > 1) {
|
||||||
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_2, timerCfg->matchVal2 - 2);
|
||||||
|
} else {
|
||||||
|
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_2, timerCfg->matchVal2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef BFLB_USE_HAL_DRIVER
|
#ifndef BFLB_USE_HAL_DRIVER
|
||||||
Interrupt_Handler_Register(TIMER_CH0_IRQn, TIMER_CH0_IRQHandler);
|
Interrupt_Handler_Register(TIMER_CH0_IRQn, TIMER_CH0_IRQHandler);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue