[STM32F4] 时钟设置

[复制链接]
441|14
 楼主| wenfen 发表于 2020-12-14 23:56 | 显示全部楼层 |阅读模式

同样的定时器程序NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);/
        delay_init(168);  //
        LED_Init();                                //

        TIM3_Int_Init(5000-1,8400-1);        
        while(1)
        {
                LED0=!LED0;//DS0·-×a
                delay_ms(200);//
        };
我用例子里面的代码,定时500ms,刷写到原子的板子是500ms,刷写到我的板子变2s,隔了4倍。。晶振都是一样的。。这是为什么?
happy_10 发表于 2020-12-15 18:53 | 显示全部楼层
把系统时钟读出来,测试下,现在的时钟倍频到多少
 楼主| wenfen 发表于 2020-12-15 18:57 | 显示全部楼层
一样的程序一样的设置,时钟也都是8M的。。。
 楼主| wenfen 发表于 2020-12-15 19:01 | 显示全部楼层
只是两块PCB不同。。。
 楼主| wenfen 发表于 2020-12-15 19:05 | 显示全部楼层
void delay_init(u8 SYSCLK)
{
#if SYSTEM_SUPPORT_OS                                                 //Èç¹ûÐèÒªÖ§³ÖOS.
        u32 reload;
#endif
        SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
        fac_us=SYSCLK/8;                                                //²»ÂÛÊÇ·ñʹÓÃOS,fac_us¶¼ÐèҪʹÓÃ
#if SYSTEM_SUPPORT_OS                                                 //Èç¹ûÐèÒªÖ§³ÖOS.
        reload=SYSCLK/8;                                                //ÿÃëÖӵļÆÊý´ÎÊý µ¥Î»ÎªM           
        reload*=1000000/delay_ostickspersec;        //¸ù¾Ýdelay_ostickspersecÉ趨Òç³öʱ¼ä
                                                                                        //reloadΪ24λ¼Ä´æÆ÷,×î´óÖµ:16777216,ÔÚ168MÏÂ,Ô¼ºÏ0.7989s×óÓÒ        
        fac_ms=1000/delay_ostickspersec;                //´ú±íOS¿ÉÒÔÑÓʱµÄ×îÉÙµ¥Î»           
        SysTick->CTRL|=SysTick_CTRL_TICKINT_Msk;           //¿ªÆôSYSTICKÖжÏ
        SysTick->LOAD=reload;                                         //ÿ1/delay_ostickspersecÃëÖжÏÒ»´Î        
        SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;         //¿ªÆôSYSTICK   
#else
        fac_ms=(u16)fac_us*1000;                                //·ÇOSÏÂ,´ú±íÿ¸ömsÐèÒªµÄsystickʱÖÓÊý   
#endif
}                                    
 楼主| wenfen 发表于 2020-12-15 19:08 | 显示全部楼层

void SystemInit(void)
{
  /* FPU settings ------------------------------------------------------------*/
  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
    SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */
  #endif
  /* Reset the RCC clock configuration to the default reset state ------------*/
  /* Set HSION bit */
  RCC->CR |= (uint32_t)0x00000001;

  /* Reset CFGR register */
  RCC->CFGR = 0x00000000;

  /* Reset HSEON, CSSON and PLLON bits */
  RCC->CR &= (uint32_t)0xFEF6FFFF;

  /* Reset PLLCFGR register */
  RCC->PLLCFGR = 0x24003010;

  /* Reset HSEBYP bit */
  RCC->CR &= (uint32_t)0xFFFBFFFF;

  /* Disable all interrupts */
  RCC->CIR = 0x00000000;

#if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
  SystemInit_ExtMemCtl();
#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
         
  /* Configure the System clock source, PLL Multiplier and Divider factors,
     AHB/APBx prescalers and Flash settings ----------------------------------*/
  SetSysClock();

  /* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM
  SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif
}
supernan 发表于 2020-12-15 19:13 | 显示全部楼层
主控芯片一样不
ousj 发表于 2020-12-15 19:16 | 显示全部楼层
写一个简单的定时器 看看时间有什么不同
lium 发表于 2020-12-15 19:19 | 显示全部楼层
用系统的那个感觉不太准确
 楼主| wenfen 发表于 2020-12-15 19:23 | 显示全部楼层

唉,还是没有什么结果,算了,多谢大家啦
wowu 发表于 2021-1-9 16:13 | 显示全部楼层
时钟源用的是什么
xiaoqizi 发表于 2021-1-9 16:15 | 显示全部楼层
是不是外部晶振不一样
木木guainv 发表于 2021-1-9 16:16 | 显示全部楼层
用示波器量一下波形
磨砂 发表于 2021-1-9 16:21 | 显示全部楼层
晶振的质量不过关也有可能
晓伍 发表于 2021-1-9 16:22 | 显示全部楼层
弱电就是如此莫名其妙
您需要登录后才可以回帖 登录 | 注册

本版积分规则

737

主题

8940

帖子

8

粉丝
快速回复 在线客服 返回列表 返回顶部