学习KEA之时钟
程序员文章站
2024-02-25 15:03:27
...
我们以KEA64系列来学习时钟, 其中KEA64系列包括:
- SKEAZN16AMLC®
- SKEAZN32AMLC®
- SKEAZN64AMLC®
- SKEAZN32AMLH®
- SKEAZN64AMLH®
其它系列的和KEA64类似,但也有点不同,具体要看各自的参考手册。
时钟框图
片上有三种时钟源模块:
- Internal Clock Source (ICS) module:
- The main clock source generator providing bus clock and other reference clocks to peripherals
- System Oscillator (OSC) module:
- The system oscillator providing reference clock to internal clock source (ICS), the real-time clock counter clock module (RTC), and other MCU sub-systems
- Low-Power Oscillator (LPO) module:
- The on-chip low-power oscillator providing 1 kHz reference clock to RTC and Watchdog (WDOG)
- The on-chip low-power oscillator providing 1 kHz reference clock to RTC and Watchdog (WDOG)
配置内部时钟
我们以内部晶振为例,最终目标是:
- Core Clock to 40MHz
- Bus Clock to 20MHz
- BUSOUT to 156.25 KHz
/***********************************************************************************************
*
* @brief CLK_Init - Initialize Core Clock to 40MHz, Bus Clock to 20MHz
* @param none
* @return none
*
************************************************************************************************/
void Clk_Init(void)
{
OSC_CR = 0x00; /* (default value) */
/* OSCEN=0: OSC module disabled */
/* OSCSTEN=0: OSC clock disabled in Stop mode */
/* OSCOS=0: Ext clk source (don't care here) */
/* RANGE=0: Low Freq range of 32 KHz */
/* HGO=0: low power High Gan Osc mode (don't care here) */
ICS_C1 |= ICS_C1_IRCLKEN_MASK; /* Enable the internal reference clock*/
ICS_C3= 0x50; /* Reference clock frequency = 39.0625 kHz*/
while(!(ICS_S & ICS_S_LOCK_MASK)); /* Wait for PLL lock, now running at 40 MHz (1024*39.0625 kHz) */
ICS_C2|=ICS_C2_BDIV(1) ; /*BDIV=2, Bus clock = 20 MHz*/
ICS_S |= ICS_S_LOCK_MASK ; /* Clear Loss of lock sticky bit */
}
int main(void)
{
SIM_SOPT |= SIM_SOPT_CLKOE_MASK | SIM_SOPT_BUSREF(0b111); /*Enable BUSOUT on PTH2, Bus clock divided by 128 */
Clk_Init();
for(;;)
{
;
}
}
运行程序后,可以在PTH2/BUSOUT(Pin6)中察看输出的BUS分频时钟:20 MHz / 128 = 156.25 KHz:
注:我这里实际是161.3 KHz,有点点偏差
持续更新
下一篇: 情感分析中机器学习和深度学习的运用