What clock?
First, let's talk about what a clock is. The clock is the heart of the microcontroller. Every time it beats, all the circuits of the microcontroller move synchronously. It's like when we do radio gymnastics, the beats on the radio are 1234 2234 3234... Then all of us students follow this rhythm to perform one action after another. The faster the beat, the faster we move. The slower the beat, the slower we move.
Internal clock or external clock?
There are many models of PIC microcontrollers that can be set to use an external clock (such as an external 4MHZ quartz crystal), or an internal RC clock. In addition, there are many models that can select clocks of multiple frequencies.
For example, the internal clock of PICLF1823 can reach up to 32MHZ and down to 31kHz. This actually provides a new way to reduce power consumption. In general, microcontrollers often use sleep mode to reduce power consumption, and the CPU does nothing during sleep. If you want to reduce power consumption and keep the CPU working, lowering the clock frequency is undoubtedly a very good choice.
How to set the clock?
The clock setting is generally related to only two places: one is the configuration word, and the other is the oscillator control register OSCCON. Below we take PICLF1823 as an example to explain.
The clock-related bits in the PICLF1823 configuration word settings are FOSC<2:0>: oscillator selection bits, and PLLEN: PLL enable bits.
OSCCON is related to the internal clock frequency selection. If only an external clock is used, it is generally ignored. The following is a detailed introduction to the OSCCON register in the data sheet.
Example explanation:
Use the internal clock to set the clock frequency to 8MHZ
Development environment: MPLAB X IDE
Chip model:PICLF1823
#include
__CONFIG(FOSC_INTOSC&WDTE_OFF&PWRTE_ON&MCLRE_OFF&CP_ON&CPD_OFF&BOREN_ON&CLKOUTEN_OFF&IESO_ON&FCMEN_ON);
__CONFIG(PLLEN_OFF&LVP_OFF) ;//Set FOSC<2:0>: oscillator selection bits to INTOSC,
void init_fosc(void)
{
OSCCON = 0x70;//8MHZ IRCF<3:0> clock frequency selection bits set to 8MHZ
}
int main(int argc, char** argv) {
init_fosc();
while(1);
}
What is PLL used for? Its function is to convert the 8MHZ clock frequency into 32MHZ by X4. Remember, only 8MHZ can be used, other frequencies cannot be used.
Use the internal clock to set the clock frequency to 32MHZ
Development environment: MPLAB X IDE
Chip model:PICLF1823
#include
__CONFIG(FOSC_INTOSC&WDTE_OFF&PWRTE_ON&MCLRE_OFF&CP_ON&CPD_OFF&BOREN_ON
&CLKOUTEN_OFF&IESO_ON&FCMEN_ON);//This should be put on the previous line
__CONFIG(PLLEN_ON&LVP_OFF); //Set FOSC<2:0>: oscillator selection bits to INTOSC, enable PLLEN
void init_fosc(void)
{
OSCCON = 0xF0; //32MHZ IRCF<3:0> clock frequency selection bits set to 8MHZ, enable 4XPLL
}
int main(int argc, char** argv) {
init_fosc();
while(1);
}
Previous article:PIC Microcontroller - Buzzer Usage Example
Next article:PIC microcontroller development environment--MPLAB X IDE
- Popular Resources
- Popular amplifiers
- Practice of Serial Communication between Single Chip Microcomputer and Computer (Zhang Xiuguan)
- Engineering applications of motion controllers and CNC systems
- singlechip-implementation-of-levelcrossing-adc-for-ecg-sampling-2332-0796-1000219
- W83116WG pdf Datasheet(V11 Low Power Clock Gen for Intel CK50
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Use protues8.6 to simulate, SRF04 simulation fails, the code is correct,
- DM648 FVID_exchange failed
- Photoelectronic thermometer circuit diagram
- MM32F031 Development Board Review 11: Simulating Lighting of 0.96-inch OLED
- MicroPython - Python for microcontrollers
- Wireless transmission power quality monitoring system circuit
- 2020 Share my thoughts on Qian'an, a national healthy and civilized county-level city
- Current detection methods
- [CB5654 Intelligent Voice Development Board Review] Hardware Review
- FPGA Implementation of Floating-Point LMS Algorithm