请教一下各位高手关于STM8L151比较输出配置的问题,以下是配置:外部晶振16M
void
tim_init(void)
{
GPIO_Init(GPIOD, GPIO_Pin_2, GPIO_Mode_Out_PP_Low_Fast);//ca
CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE);
TIM1_DeInit();
TIM1_TimeBaseInit(320, TIM1_CounterMode_Up,50000, 0);
TIM1_OC1Init(TIM1_OCMode_Toggle,TIM1_OutputState_Enable, TIM1_OutputNState_Disable,25000,
TIM1_OCPolarity_High, TIM1_OCNPolarity_High, TIM1_OCIdleState_Reset,
TIM1_OCNIdleState_Reset);
TIM1_ITConfig(TIM1_IT_CC1, ENABLE);
TIM1_CtrlPWMOutputs(ENABLE);
TIM1_Cmd(ENABLE);
enableInterrupts();
}
INTERRUPT_HANDLER(TIM1_CC_IRQHandler, 24)
{
TIM1_ClearITPendingBit(TIM1_IT_CC1);
TIM1_SetCounter(0);
}
输出比较到底是怎么工作的,TIM1_CNTR=50000,TIM1_CCR1=25000,难道不是TIM1_CCR1=TIM1_CNTR才发生电平反转?为什么我测出来的频率是300多赫兹啊?按我的理解,TIME1一个周期是1秒,现在设置为0.5秒处做比较并反转电平,这不是输出频率该1HZ么?
不知道那里理解错了,请高手们解惑!
此帖出自
小平头技术问答
一周热门 更多>