|
LPC24xx系列ARM7 系统时钟配置代码(转自微控制器硬件及驱动网)
[复制链接]
NXP公司 LPC246x系列ARM7功能强大,最高主频可达72MHz。主频需要通过锁相环倍频产生,因此配置比较麻烦,不像51等单片机简单明了。配置主频主要就是要根据硬件晶振频率和你希望得到的系统主频,计算出M, N, 分频系数等几个重要参数。
该代码为LPC246x系统时钟PLL配置代码。范例代码给出了硬件配置为晶振24MHz,配置后系统主频为最高频率72MHz的配置方法。更改M,N和分频系数后可以得到更多的系统主频。
M,N和分频系数如何计算,芯片用户手册上有介绍,但比较复杂。我为此制作了代码生成器,自动计算参数并生成配置代码。只要在主函数开始初始化时调用void ConfigurePLL (void)就可以完成配置,非常方便。
使用代码生成器可以访问 http://www.hdmcu.com/codegenerator_html/webcg-6.html
//---------------------------------------------------------
//使用需#include “LPC246x.h“
//晶振频率 24MHHz
//预设主频 72MHz
//---------------------------------------------------------
#include “LPC246x.h“
void ConfigurePLL (void)
{
unsigned long MValue=0, NValue=0;
//关键参数值
unsigned short PLL_M=6, PLL_N=1;
unsigned char PLL_FcclkDiv=0;
unsigned char PLL_FusbDiv=6;
if(PLL_M==0) //M=0 is Caculate error, system can-y-o-u-g-a-n-g-‘t work
while(1);
//no Caculate error
if ( PLLSTAT & (1 << 25) )
{
PLLCON = 1; /* Enable PLL, disconnected */
PLLFEED = 0xaa;
PLLFEED = 0x55;
}
PLLCON = 0; /* Disable PLL, disconnected */
PLLFEED = 0xaa;
PLLFEED = 0x55;
SCS |= 0x20; /* Enable main OSC */
while( !(SCS & 0x40) ); /* Wait until main OSC is usable */
CLKSRCSEL = 0x1; /* select main OSC, 12MHz, as the PLL clock source */
PLLCFG = ((U32)PLL_M-1) | (((U32)PLL_N-1)<< 16);
PLLFEED = 0xaa;
PLLFEED = 0x55;
PLLCON = 1; /* Enable PLL, disconnected */
PLLFEED = 0xaa;
PLLFEED = 0x55;
CCLKCFG = (PLL_FcclkDiv-1); /* Set clock divider */
//配置USB_48M
PCONP |= 0x80000000;
USBCLKCFG = PLL_FusbDiv; /* usbclk = 48 MHz */
while ( ((PLLSTAT & (1 << 26)) == 0) ); /* Check lock bit status */
MValue = PLLSTAT & 0x00007FFF;
NValue = (PLLSTAT & 0x00FF0000) >> 16;
while (((MValue+1) != PLLinfo_M) && ( (NValue+1) != PLLinfo_N) );
PLLCON = 3; /* enable and connect */
PLLFEED = 0xaa;
PLLFEED = 0x55;
while ( ((PLLSTAT & (1 << 25)) == 0) ); /* Check connect bit status */
return;
}
|
|