用TIMERA的定时匹配中断拉高拉低IO口实现4096hz的方波(定时器中断间隔1/2*4096s),定时器分频因子是100(写入寄存器CR2[7...0]为99),写入 OCAR值为15(程序中是TIMx->OCAR = ( 15- 5 );其实写入的是10,不知道为什么这样?),运行后用示波器看IO口输出却是4174HZ,费解? 配置PCLK2为4096000*3 void clks_init(void) { RCCU_Div2Config (DISABLE); RCCU_PLL1Config(RCCU_PLL1_Mul_12, RCCU_Div_2); RCCU_RCLKSourceConfig (RCCU_PLL1_Output); RCCU_MCLKConfig(RCCU_DEFAULT); RCCU_PCLKConfig(RCCU_Div_2); //PCLK2=24MHz APB2 periph RCCU_FCLKConfig(RCCU_Div_2); //PCLK1=24MHz APB1 periph (fast) RCCU_PLL2Config(RCCU_PLL2_Mul_16, RCCU_Div_1); } 定时器初始化: TIM_Init(TIM0); TIM_PrescalerConfig(TIM0, 99);//4096000*12/2/(250)=98304 TIM_ITConfig(TIM0, TIM_OCA_IT, ENABLE); TIM_OCMPModeConfig( TIM0, TIM_CHANNEL_A, 15, TIM_TIMING, TIM_HIGH); EIC_Init(); EIC_IRQChannelConfig(T0TIMI_IRQChannel ,ENABLE);//HDLC 中断使能 EIC_IRQChannelPriorityConfig(T0TIMI_IRQChannel,2); EIC_IRQConfig(ENABLE); TIM_CounterConfig(TIM0, TIM_START);
后来用STR710,16M的外部晶振试着实现16khz的方波,结果出来的却是14.7k,请大家帮我看看,谢谢 |