功能:10ms中断
今天突然发现了一个奇怪问题,分频因子不起作用!
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;//时钟分频因子
程序代码如下,stm32f1,F2通用:- /*TIM6初始化 用于LCD backlight */
- //TIM_Period:自动重装值(u32)
- //TIM_Prescaler:时钟预分频值(u16)
- //定时时间计算 T=(TIM_Period+1)*(TIM_Prescaler+1)/TIMxCLK(60Mhz)=(359+1)*(199+1)/36MHz=1ms
- void TIM6_Configuration(void)
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
- NVIC_InitTypeDef NVIC_InitStructure;
-
- NVIC_InitStructure.NVIC_IRQChannel = TIM6_DAC_IRQn; // Enable the TIM6 Interrupt
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // 先占优先级 1
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; // 从优先级 6
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // IRQ通道被使能
- NVIC_Init(&NVIC_InitStructure);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);//使能TIM6时钟 =系统时钟60M
- TIM_TimeBaseInitStruct.TIM_Period = (100-1);//重装载值(1ms)
- TIM_TimeBaseInitStruct.TIM_Prescaler = (6000-1); //预分频 f=(TIM_Prescaler+1)
- <font color="#ff0000"> /*TIM_CKD_DIV2, TIM_CKD_DIV4 is Not Action,Why? */
- TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;//时钟分频因子</font>
- TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up; //向上计数模式
- //TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0x0000;///高级定时器有效(TIM1&TIM 8)
-
- TIM_TimeBaseInit(TIM6,&TIM_TimeBaseInitStruct);
- //TIM_UpdateRequestConfig(TIM7,TIM_UpdateSource_Regular);//只有上溢或下溢才产生更新事件
- TIM_ClearFlag(TIM6, TIM_FLAG_Update);
- TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE);
-
- TIM_Cmd(TIM6,ENABLE);
- }
复制代码- void TIM6_DAC_IRQHandler()
- {
- if(TIM_GetITStatus(TIM6,TIM_IT_Update)!=RESET)
- {
- TIM_ClearITPendingBit(TIM6,TIM_FLAG_Update);
- LED2_TOGGLE;
- }
- }
复制代码 希望有朋友帮我看看撒?修改分频因子不起作用~
|
一般意义上的分频就设置PSC就行了
用示波器测量的撒?嘿嘿,我解决了分享给大家
功能:10ms中断
有道理,呵呵
厉害!~!