初级会员
- 积分
- 184
- 金钱
- 184
- 注册时间
- 2012-11-12
- 在线时间
- 36 小时
|
5金钱
本帖最后由 核子霹雳 于 2018-4-28 11:24 编辑
#define TIME3_CCR1_Val 60
void Time_Configuration(FunctionalState enable)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
uint16_t PrescalerValue;
/* Compute the prescaler value */
PrescalerValue = (uint16_t) (SystemCoreClock / 6000) - 1;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* Output Compare Toggle Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = TIME3_CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);
/* TIM enable counter */
TIM_Cmd(TIM3, enable);
/* TIM IT enable */
TIM_ITConfig(TIM3, TIM_IT_CC1, enable);
}
//放在定时器中断里面TIM3_IRQHandler
void STM32_TIM3_IRQHandler(void)
{
u32 capture;
if (TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);
capture = TIM_GetCapture1(TIM3);
TIM_SetCompare1(TIM3, capture + TIME3_CCR1_Val);
if(BitFalg==0)
{
BitFalg =1;
P_Led2_OUT_HI
}
else if(BitFalg==1)
{
BitFalg =0;
P_Led2_OUT_LO
}
}
}
产生10MS 方波 但是方波不稳定,中间会夹杂其他方波 如图 红色框表示 , 用的是 STM3F0 内部高速时钟8M。 什么原因会照成这样的结果? 和用的内部时钟有关系吗? 请大神指教。
|
-
|