865 views|1 replies

205

Posts

0

Resources
The OP
 

How to set up a programmable crystal oscillator? [Copy link]

1. Many people don’t know how to set up a programmable crystal oscillator. In addition to following the instructions, you can also watch video tutorials, especially for the settings of programmable crystal oscillators. These details are all options. You can also consult a professional FAE engineer for analysis.

2. Definition of programmable crystal oscillator External crystal oscillator macro definition. The writing of macro definition is as follows: #define HSE_VALUE ((uint32_t)24000000) Write as much as you want for the external crystal oscillator. If it is a 24M external crystal oscillator, write 2400000.

3. If macro definition is not needed, just find the macro definition part in the header file of the microcontroller. The default macro definition of the header file is 16M external crystal oscillator, which can be modified to the actual crystal oscillator value.

4. Configure the external crystal. When configuring the external crystal, you need to enable the external clock and wait until the crystal is stable. The statements configured using the library function are as follows: void CLK_Init(){CLK_HSECmd(enable); //External clock turns on while(set!=CLK_get flag status(CLK_flag_hser dy)); //Wait for the external crystal to vibrate. CLK_clock switch command(enable); //Switch enable

5. CLK_Clock switch configuration (CLK_Switch mode_Manual, CLK_Source_HSE, Disable, CLK_Current clock state_Disable); //Switch to external crystal oscillator CLK_SYSCLKConfig(CLK_Prescaler_CPU div 1); //1 division}

6. Initialize in main() Initialize CLK_Init() in main(). At this point, the external crystal oscillator is configured, but when the program is executed, it is found that the crystal oscillator fails to start oscillation. The default setting of the program in CLK_clock switch configuration is no wait state, which needs to be changed to 1 wait state. In fact, this part is reflected in the data sheet: When using a high-speed external clock (HSE) at a higher frequency of up to 24 MHz, a wait state is required. In this case, the device option byte should be programmed to insert this wait state. See the option byte section of the data sheet. After the settings are completed, download the program, and you will find that the crystal oscillator has started to vibrate normally.

7. Generally speaking, you need to master certain programming techniques when setting a programmable crystal oscillator, because only after mastering the programming techniques can you do a good job of programming. These codes are for reference only, because different programmable crystal oscillators may be edited differently. In these aspects, you should make your own reasonable judgments or let the manufacturer set it directly.

This post is from Discrete Device

Latest reply

You need to write the corresponding chip model  Details Published on 2024-2-22 17:41
 
 

2624

Posts

6

Resources
2
 

You need to write the corresponding chip model


This post is from Discrete Device
 
 
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list