Hello everyone.
My code is as follows:
void Timer_init(void)
{
Hwi_Params hwiParams;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
Power_setDependency(PERIPH_GPT0); // Set Power dependecies & constraints
//配置GPT0模块定时器B.
TIM_TimeBaseStructure.GPT_Separate = GPT_CFG_CFG_16BIT_TIMER;
TIM_TimeBaseStructure.GPT_OneShotOrPeriodic = GPT_TAMR_TAMR_PERIODIC;
TIM_TimeBaseStructure.GPT_CounterMode = GPT_TAMR_TACDIR_UP;
TIM_TimeBaseStructure.GPT_Period = 4800; //48M/4800 = 10KHz
TIM_TimeBaseInit(GPT0_BASE, TIMER_B, TIM_TimeBaseStructure);
TIM_IMRConfig(GPT0_BASE, TIMER_TIMB_TIMEOUT, ENABLE); //使能中断
TIM_Cmd(GPT0_BASE, TIMER_B, ENABLE); //使能定时器
Hwi_Params_init(&hwiParams);
Hwi_construct(&TimerHwi, INT_TIMER0B, Timer_Isr,&hwiParams, NULL); //注册中断服务函数
Power_setConstraint(Power_SB_DISALLOW); //
}
static void Timer_Isr(UArg arg)
{
static bool ak = 0;
//JLX_12864Fxn->lcd_DisplayString_8x16(1,0,(uint8 *)JLX_12864Fxn->lcd_Numtostr(HWREG(GPT0_BASE+GPT_O_TBILR)));
ak = PIN_getOutputValue(Board_S3);
PIN_setOutputValue(&lState, PIN_ID(Board_S3), !ak);
TimerIntClear(GPT0_BASE, TIMER_TIMB_TIMEOUT); //Clear this event flag
HWREG(NVIC_UNPEND1) |= 1<<(INT_TIMER0B-16); //clear CM3 interrupt
//HWREG(GPT0_BASE + GPT_O_TBILR) = 4800; //If add this, the frequency is 5KHz..
}
I get the frequency of the waveform is 365Hz(48000000 / 65535 / 2 = 366),why?
Data sheet is described below:
“When the timer is counting down and reaches the time-out event (0x0), the timer reloads its start value
from the [GPT_TnILR] and [GPT_TnPR] registers on the next cycle. When the timer is counting up and
reaches the time-out event (the value in the [GPT_TnILR] and the optional [GPT_TnPR] registers),
thetimer reloads with 0x0.” But it doesn't seem like this.....
Waiting for your answer.