上图引自LPC1768的用词手册,从框图也可以看出,我们需要配置时钟源多路选择器,Main PLL(PLL0)等多个模块,涉及到以下多个寄存器:
CLKSRCSEL Clock Source Select Register
Phase Locked Loop (PLL0, Main PLL)
PLL0CON PLL0 Control Register
PLL0CFG PLL0 Configuration Register
PLL1CFG PLL1 Configuration Register
CCLKCFG CPU Clock Configuration Register
PCONP Power Control for Peripherals Register
我们本次并未使用时钟频率输出,因此CLKOUTCFG Clock Output Configuration Register寄存器并未配置使用。
时钟的配置需要稳定与可靠,所以配置的流程也相当重要,我们按照官方手册来设计配置流程:
The following sequence must be followed step by step in order to have PLL0 initialized
and running:
1. Disconnect PLL0 with one feed sequence if PLL0 is already connected.
2. Disable PLL0 with one feed sequence.
3. Change the CPU Clock Divider setting to speed up operation without PLL0, if desired.
4. Write to the Clock Source Selection Control register to change the clock source if
needed.
5. Write to the PLL0CFG and make it effective with one feed sequence. The PLL0CFG
can only be updated when PLL0 is disabled.
6. Enable PLL0 with one feed sequence.
7. Change the CPU Clock Divider setting for the operation with PLL0. It is critical to do
this before connecting PLL0.
8. Wait for PLL0 to achieve lock by monitoring the PLOCK0 bit in the PLL0STAT register,
or using the PLOCK0 interrupt, or wait for a fixed time when the input clock to PLL0 is
slow (i.e. 32 kHz). The value of PLOCK0 may not be stable when the PLL reference
frequency (FREF, the frequency of REFCLK, which is equal to the PLL input
frequency divided by the pre-divider value) is less than 100 kHz or greater than
20 MHz. In these cases, the PLL may be assumed to be stable after a start-up time
has passed. This time is 500 µs when FREF is greater than 400 kHz and 200 / FREF
seconds when FREF is less than 400 kHz.
9. Connect PLL0 with one feed sequence.
时钟配置完成之后,我们使用systick的计时中断,并通过IAR调试环境的实时刷新数据来粗略估计配置的正确性。代码如下:
- void main(void)
- {
- uint8_t i = 0;
- setXtalToMax();
- SysTick_Config(100000);
- while(1)
- {
- i++;
- }
- }
- void SysTick_Handler(void)
- {
- gCnt++;
- }
复制代码
其实,我们应该使用时钟的分频输出功能,将时钟主频输出并使用示波器来测量。好吧,就偷个懒吧!
TO BE CONTINUED.