|
我现在使用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); } |
| 我找到问题所在了, RCC_PLLConfig(RCC_PLLSource_HSE,8,360,16,7);这里设置有问题,应该将16改为2。我使用RCC_GetClocksFreq(&Clock);这个函数查到的。还有就是如我想了解RCC_PLLConfig(RCC_PLLSource_HSE,8,360,16,7);函数中的参数,具体大家找函数中的解释吧,或者查固件库手册,希望对大家会有所帮助。 |
| 还没等大家看自己就解决了,代码供大家参考吧 |
|
无刷电机PWM输出配置
CubeMX+STM32F407VGT6+配置lwip的httpd功能,工程编译报错
workbench5.3.1生成代码问题
motor control workbench新建自主工程,STM32F405,生成代码,执行pilot,显示检测不到母线电压,电流,一直不转,检测不到极对数
STM32F4以太网 MAC Loopback(MAC回环)的实现
串口空闲+DMA接收GPS信号,空闲中断触发时间不对。
想要一个成熟产品OTG通信的程序。
stm32f407烧录hal库代码不能正常运行,之前是可以的
请教下,使用 filex 文件系统需要支持中文的目录及文件名要怎么配置呀 ?
STM32F429V烧录是无法识别到芯片怎么办?
微信公众号
手机版