想看看在TIM1的重复计数器等于0的情况下,更新中断是在计数器上溢时发生,还是在下溢时发生 。就配置了下面的代码,在更新中断里面反转PD2引脚电平,与通道一输出的pwm波比较,用于指示更新中断产生的时刻,结果测量波形显示,在每一个计数周期中产生好几次更细中断,不知道这是为什么???求大神帮忙啊- int main(void)
- {
- /* TIM Configuration */
- TIM_Config();
- /* Infinite loop */
- while (1)
- {
- }
- }
- /**
- * @brief Configure the TIM1 Pins.
- * @param None
- * @retval None
- */
- static void TIM_Config(void)
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- /* GPIOA, GPIOB and GPIOE Clocks enable */
- RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOD, ENABLE);
-
- /* GPIOA Configuration: Channel 1, as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 ;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_2);
-
- /*·´×ªÒý½Å*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
-
- /* Compute the value to be set in ARR regiter to generate signal frequency at 17.57 Khz */
- TimerPeriod = (SystemCoreClock / 17570 ) - 1;
- /* Compute CCR1 value to generate a duty cycle at 50% for channel 1 and 1N */
- Channel1Pulse = (uint16_t) (((uint32_t) 5 * (TimerPeriod - 1)) / 10);
- /* TIM1 clock enable */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);
-
- /* Time Base configuration */
- TIM_TimeBaseStructure.TIM_Prescaler = 0;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned3;
- TIM_TimeBaseStructure.TIM_Period = TimerPeriod;
- TIM_TimeBaseStructure.TIM_ClockDivision = 0;
- TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
- TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
- /* Channel 1, 2,3 and 4 Configuration in PWM mode */
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
- TIM_OCInitStructure.TIM_Pulse = Channel1Pulse;
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
- TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
- TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
- TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
- TIM_OC1Init(TIM1, &TIM_OCInitStructure);
- TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
-
- /* TIM1 counter enable */
- TIM_Cmd(TIM1, ENABLE);
- /* TIM1 Main Output Enable */
- TIM_CtrlPWMOutputs(TIM1, ENABLE);
-
- /* Enable the TIM1 Trigger and commutation interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- */
- void TIM1_BRK_UP_TRG_COM_IRQHandler(void)
- {
- if(TIM_GetITStatus(TIM1,TIM_IT_Update))
- {
- GPIOD->ODR ^=GPIO_Pin_2;
- }
- }
复制代码
|