if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
/* Pin PC.06 toggling with frequency = 73.24 Hz */ GPIO_WriteBit(GPIOC, GPIO_Pin_6, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_6))); capture = TIM_GetCapture1(TIM2); TIM_SetCompare1(TIM2, capture + CCR1_Val); }
/* Time base configuration */ TIM_TimeBaseStructure.TIM_Period =65535;//必须是65535才可以同上面中断中所用的CCR1自动溢出的方式进行同步,产生正确的结果,使得产生50%的pulse 决定的波形。
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;//0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
|