LPC1768之时钟
一锁相环和CPU时钟。
CPU时钟=锁相环0输出/CPU时钟配置寄存器的预分频值即:Fcpu=Fcco/CCLKCFG+1。锁相环可以把外部时钟倍频到较高频率,PLL0输出频率是:
Fcco = (2xMxFin)/N;
M=MSEL0+1,N=NSEL0+1。MSEL0和NSEL0分别是PLL0CFG_Val 的低字和高字。N值得取值范围是1~32,而M的取值是在较高的振荡器频率下(超过1MHz)允许范围是6~512。
得到PLL0输出值之后,在经过CPU时钟配置寄存器就可以得到CPU时钟。
在这个system_lpc17xx.c文件中,修改#define PLL0CFG_Val 0x00050063的宏定义值就可以了。
例如:00050063这个状态下PLL0输出400MHz。
M = 0x63(16进制) + 1 = 100(10进制);
N = 0x05 + 1 = 6;
Fcco = 2X12x100/6 = 400M
Fcpu=Fcco/2^(CCLKCFG+1)=400M/4=100M.
分频值CCLKSEL只能是0和奇数值(1、3、5…,255),CCLK从PLL0输出信号中得到,通过CCLKSEL+1分频
二:定时器时钟:定时器可以使用PC和PR进行再分频
预分频系数:LPC_TIM1->PR
定时器的计数频率=Fcclk/LPC_TIM1->PR
重载值: LPC_TIM0->MR0
中断一次所需的时间=重载值/定时器的计数频率。
http://blog.csdn.net/aquakguo0he1/article/details/8513923
void delayMs(uint8_t timer_num, uint32_t delayInMs)
{
if ( timer_num == 0 )
{
LPC_TIM0->TCR = 0x02; /* reset timer */
LPC_TIM0->PR = 0x00; /* set prescaler to zero */
LPC_TIM0->MR0 = delayInMs * (9000000 / 1000-1);
LPC_TIM0->IR = 0xff; /* reset all interrrupts */
LPC_TIM0->MCR = 0x04; /* stop timer on match */
LPC_TIM0->TCR = 0x01; /* start timer */
/* wait until delay time has elapsed */
while (LPC_TIM0->TCR & 0x01);
}
else if ( timer_num == 1 )
{
LPC_TIM1->TCR = 0x02; /* reset timer */
LPC_TIM1->PR = 0x00; /* set prescaler to zero */
LPC_TIM1->MR0 = delayInMs * (9000000 / 1000-1);
LPC_TIM1->IR = 0xff; /* reset all interrrupts */
LPC_TIM1->MCR = 0x04; /* stop timer on match */
LPC_TIM1->TCR = 0x01; /* start timer */
/* wait until delay time has elapsed */
while (LPC_TIM1->TCR & 0x01);
}
return;
}
{
if ( timer_num == 0 )
{
LPC_TIM0->TCR = 0x02; /* reset timer */
LPC_TIM0->PR = 0x00; /* set prescaler to zero */
LPC_TIM0->MR0 = delayInMs * (9000000 / 1000-1);
LPC_TIM0->IR = 0xff; /* reset all interrrupts */
LPC_TIM0->MCR = 0x04; /* stop timer on match */
LPC_TIM0->TCR = 0x01; /* start timer */
/* wait until delay time has elapsed */
while (LPC_TIM0->TCR & 0x01);
}
else if ( timer_num == 1 )
{
LPC_TIM1->TCR = 0x02; /* reset timer */
LPC_TIM1->PR = 0x00; /* set prescaler to zero */
LPC_TIM1->MR0 = delayInMs * (9000000 / 1000-1);
LPC_TIM1->IR = 0xff; /* reset all interrrupts */
LPC_TIM1->MCR = 0x04; /* stop timer on match */
LPC_TIM1->TCR = 0x01; /* start timer */
/* wait until delay time has elapsed */
while (LPC_TIM1->TCR & 0x01);
}
return;
}
二systick:
2.1时钟源:CPU提供货P3.26(STCLK)
2.2 10ms专用中断。若想循环产生中断则要定时装入STRELOAD,默认时间间隔在STCALIB中
2.3裸机专用定时的定时器