Posted on : Fri , 02 2014 by : virusi
THEORY ON MCU CLOCK :
Clock is the heart of the microcontroller. It is impossible for the microcontroller to function without the clock. Depending on the Clock frequency that can be applied to the microcontroller depends how many instruction can be executed in a timeframe. So let’s take a look at different clock sources that can be applied to a microcontroller. Be aware that not to all microcontroller can be applied the featured described, if you to check if your microcontroller supports this type of clock source than you should check your microcontroller datasheet.
Fig 1 shows the block diagram of the clock generation for LPC17xx but this can be applied to almost all microcontrollers. As you can see from the Fig. 1 there are three independent oscillators. These are the Main Oscillator(osc_clk) , the Internal RC oscillator(rtc_clk) and the RTC(rtc_clk) oscillator. Each oscillator can be used for more than one purpose as required in a particular application. If you are interested in different oscillator configuration than click here.
Internal RC oscillator :
The Internal RC Oscillator (IRC) may be used as the clock source for the watchdog timer, and/or as the clock that drives PLL0( Phase Locked Loop 0 ) and subsequently the CPU. The precision of the IRC does not allow for use of the USB interface, which requires a much more precise time base in order to comply with the USB specification. Also, the IRC should not be used with the CAN1/2 block if the CAN baud rate is higher than 100 kbit/s. The nominal IRC frequency is 4 MHz.
Upon power-up or any chip reset, the LPC17xx uses the IRC as the clock source. This allows systems to operate without any external crystal, and allows the boot loader code to operate at a known frequency. Software may later switch to one of the other available clock sources.
Main oscillator :
The main oscillator can be used as the clock source for the CPU, with or without using PLL0. The main oscillator operates at frequencies of 1 MHz to 25 MHz. This frequency can be boosted to a higher frequency, up to the maximum CPU operating frequency, by the Main PLL (PLL0). The oscillator output is called OSC_CLK.
The on-board oscillator in the LPC17xx can operate in one of two modes: slave mode and oscillation mode.
In slave mode the input clock signal should be coupled by means of a capacitor of 100 pF, with amplitude between 200 mVrms and 1000 mVrms. This corresponds to a square wave signal with a signal swing of between 280 mV and 1.4 V. The XTAL2 pin in this configuration can be left unconnected.
External components and models used in oscillation mode are shown in Fig. 3. Since the feedback resistance is integrated on chip, only a crystal and the capacitances CX1and CX2need to be connected externally in case of fundamental mode oscillation (the fundamental frequency is represented by L, CL and RS). Parameters FC, CL, RS and CP are supplied by the crystal manufacturer.
RTC oscillator :
The RTC oscillator provides a 1 Hz clock to the RTC and a 32 kHz clock output that can be used as the clock source for PLL0 and CPU and/or the watchdog timer. The RTC oscillator must not be used as a clock source when the PLL0 output is selected to drive the USB controller. In this case select the main oscillator as clock source for PLL0.
PLL0 Phase Locked Loop 0 :
The PLL input, in the range of 32 kHZ to 50 MHz, may initially be divided down by a value “N”, which may be in the range of 1 to 256. This input division provides a greater number of possibilities in providing a wide range of output frequencies from the same input frequency.
Following the PLL input divider is the PLL multiplier. This can multiply the input divider output through the use of a Current Controlled Oscillator (CCO) by a value “M”, in the range of 6 through 512. The resulting frequency must be in the range of 275 MHz to 550 MHz. The multiplier works by dividing the CCO output by the value of M, then using a phase-frequency detector to compare the divided CCO output to the multiplier input. The error value is used to adjust the CCO frequency.
There are additional dividers at the output of PLL0 to bring the frequency down to what is needed for the CPU, peripherals, and potentially the USB subsystem.
So depending on your application you should use different types of oscillators. Before you configure the oscillator you should check what microcontroller’s functions you will use because if you will use the usb you will have to use main oscillator with the PLL0 activated. Be aware that after reset the MCU uses IRC until it is switched by the application.