你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32F429定时器时钟配置问题

[复制链接]
suna-2027220 提问时间:2014-12-21 20:42 /
我现在使用TIMER3和中断来做一个LED灯的闪烁功能,在Timer3的中断中将LED灯电平翻转,Timer3使用的是APB1的时钟,按我的配置应该是90MHz,我配置Timer3的TIM_Prescaler=18000,故Timer3的时钟就是5kHz,那么在设置TIM_Period=2000-1的情况下,得到的情况应该是高低电平各0.4秒,周期为0.8秒。但是实际情况如下图:

低电平时间

低电平时间

高电平时间

高电平时间

下面贴上我的程序:
void SysInit(void)
{
                //Resets the RCC clock configuration to the default reset state
                RCC_DeInit();
                //Configures the External High Speed oscillator (HSE)
                RCC_HSEConfig(RCC_HSE_ON);
                //Waits for HSE start-up
                while( RCC_WaitForHSEStartUp() != SUCCESS );
                //Configures the main PLL clock source, multiplication and division factors
                //M=8,N=360,P=16,Q=7
                RCC_PLLConfig(RCC_PLLSource_HSE,8,360,16,7);
                //Enables or disables the main PLL
                RCC_PLLCmd(ENABLE);
                //Configures the system clock (SYSCLK)
                RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
                //Configures the AHB clock (HCLK)
                 RCC_HCLKConfig(RCC_HCLK_Div1);
                 //Configures the Low Speed APB clock (PCLK1)
                 RCC_PCLK1Config(RCC_HCLK_Div4);
                 //Configures the High Speed APB clock (PCLK2).
                 RCC_PCLK2Config(RCC_HCLK_Div2);
}
void TIMER_cfg(void)
{
                /*Define Time3 Initial type structure*/
                TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
                /*Deinit Time3*/
                TIM_DeInit(TIM3);
                /*Enable Timer3 Clock*/
                RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
                /*Using internal clock for TIM3*/
                TIM_InternalClockConfig(TIM3);
                /*What's this?*/               
                TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
                /*CK_CNT=90000000/18000=5kHz*/
                TIM_TimeBaseStructure.TIM_Prescaler=18000;
                /*Counting mode is up*/
                TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
                /*Specifies the period value to be loaded into the active Auto-Reload Register at the next update event*/
                TIM_TimeBaseStructure.TIM_Period=2000-1;
                /*It will generate an interrupt when the overfow number  reach the RepetitionCounter number*/
                TIM_TimeBaseStructure.TIM_RepetitionCounter=0;
                TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
                /*Clear up the Time updata flag*/
                TIM_ClearFlag(TIM3,TIM_FLAG_Update);
                /*Disable the preload buffer of arr*/
                TIM_ARRPreloadConfig(TIM3,DISABLE);
                /*Enable the TIM3 IT*/
                TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
}

收藏 评论3 发布时间:2014-12-21 20:42

举报

3个回答
suna-2027220 回答时间:2014-12-22 00:44:52
我找到问题所在了, RCC_PLLConfig(RCC_PLLSource_HSE,8,360,16,7);这里设置有问题,应该将16改为2。我使用RCC_GetClocksFreq(&Clock);这个函数查到的。还有就是如我想了解RCC_PLLConfig(RCC_PLLSource_HSE,8,360,16,7);函数中的参数,具体大家找函数中的解释吧,或者查固件库手册,希望对大家会有所帮助。
小贾-370388 回答时间:2014-12-22 10:47:03
还没等大家看自己就解决了,代码供大家参考吧
晓枫VS枯叶 回答时间:2014-12-22 12:14:25
  1. *=============================================================================
  2.   *                    Supported STM32F42xxx/43xxx devices
  3.   *-----------------------------------------------------------------------------
  4.   *        System Clock source                    | PLL (HSE)
  5.   *-----------------------------------------------------------------------------
  6.   *        SYSCLK(Hz)                             | 180000000
  7.   *-----------------------------------------------------------------------------
  8.   *        HCLK(Hz)                               | 180000000
  9.   *-----------------------------------------------------------------------------
  10.   *        AHB Prescaler                          | 1
  11.   *-----------------------------------------------------------------------------
  12.   *        APB1 Prescaler                         | 4
  13.   *-----------------------------------------------------------------------------
  14.   *        APB2 Prescaler                         | 2
  15.   *-----------------------------------------------------------------------------
  16.   *        HSE Frequency(Hz)                      | 25000000
  17.   *-----------------------------------------------------------------------------
  18.   *        PLL_M                                  | 25
  19.   *-----------------------------------------------------------------------------
  20.   *        PLL_N                                  | 360
  21.   *-----------------------------------------------------------------------------
  22.   *        PLL_P                                  | 2
  23.   *-----------------------------------------------------------------------------
  24.   *        PLL_Q                                  | 7
  25.   *-----------------------------------------------------------------------------
  26.   *        PLLI2S_N                               | NA
  27.   *-----------------------------------------------------------------------------
  28.   *        PLLI2S_R                               | NA
  29.   *-----------------------------------------------------------------------------
  30.   *        I2S input clock                        | NA
  31.   *-----------------------------------------------------------------------------
  32.   *        VDD(V)                                 | 3.3
  33.   *-----------------------------------------------------------------------------
  34.   *        Main regulator output voltage          | Scale1 mode
  35.   *-----------------------------------------------------------------------------
  36.   *        Flash Latency(WS)                      | 5
  37.   *-----------------------------------------------------------------------------
  38.   *        Prefetch Buffer                        | ON
  39.   *-----------------------------------------------------------------------------
  40.   *        Instruction cache                      | ON
  41.   *-----------------------------------------------------------------------------
  42.   *        Data cache                             | ON
  43.   *-----------------------------------------------------------------------------
  44.   *        Require 48MHz for USB OTG FS,          | Disabled
  45.   *        SDIO and RNG clock                     |
  46.   *-----------------------------------------------------------------------------
  47.   *=============================================================================
复制代码
  1. #if !defined  (HSE_VALUE)
  2.   #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
  3.   
  4. #endif /* HSE_VALUE */
复制代码
楼主可以直接修改stm32f4xx.h和system_stm32f4xx.c中的HSE_VALUE 、PLL_M这两个参数就够了,其他的都不用改,更不用多一个配置时钟的函数!                     





所属标签

相似问题

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版