如果知道频率是100hz,自动重装载值和预分频系数是怎么算出来的呢?
void TIM6_Configuration(unsigned int TIM_Period,unsigned int TIM_Prescaler)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
TIM_TimeBaseStruct.TIM_Period=1799;//初值
TIM_TimeBaseStruct.TIM_Prescaler=9;//预分频
TIM_TimeBaseStruct.TIM_ClockDivision=0;
TIM_TimeBaseStruct.TIM_CounterMode=TIM_CounterMode_Up;//向上
TIM_TimeBaseInit(TIM6,&TIM_TimeBaseStruct);
// TIM_ClearFlag(TIM6,TIM_IT_Update);
TIM_ITConfig(TIM6,TIM_IT_Update,ENABLE);
// TIM_Cmd(TIM6,ENABLE);
}
void NVIC_Tim6_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
面向人计算从1~10好理解
面向机器 从0~9执行
这个之间就会差一个1
一周热门 更多>