本帖最后由 thefly 于 2010-3-8 20:29 编辑
利用TIM3 CH3产生了一个PWM,并且想动态改变占空比,利用如下中断程序测试指示灯无反应,请问为什么?
/* -----------------------------------------------------------------------
TIM3 Configuration: generate PWM signal with duty cycle:
TIM3 CLK = 36 MHz, Prescaler = 0x0, TIM3 counter clock = 36 MHz
TIM3 ARR Register = 719 => TIM3 Frequency = TIM3 counter clock/(ARR + 1)
TIM3 Frequency = 100 KHz.
TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR)* 100 = 50% CRRx_Val = 360
TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR)* 100 = 37.5%
TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR)* 100 = 25% CRRx_Val = 180
TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR)* 100 = 12.5%
----------------------------------------------------------------------- */
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 719;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
// Clear TIM2 update pending flag
TIM_ClearFlag(TIM3, TIM_FLAG_Update);
// Enabel interrupt
//TIM_ITConfig(TIM3, TIM_IT_CC3, ENABLE);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
//TIM_UpdateRequestConfig(TIM3,TIM_UpdateSource_Regular);
/* PWM1 Mode configuration: Channel3 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC3Init(TIM3, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
//TIM_ARRPreloadConfig(TIM3,DISABLE);
TIM_ARRPreloadConfig(TIM3, ENABLE);
/* TIM3 enable counter */
TIM_Cmd(TIM3, ENABLE);
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_CC3)!= RESET)
{
GPIO_WriteBit(GPIO_LED, GPIO_LED0_PIN, (BitAction)((1-GPIO_ReadOutputDataBit(GPIO_LED, GPIO_LED0_PIN))));
//IC3value = TIM_GetCapture3(TIM3);
TIM_ClearITPendingBit(TIM3, TIM_IT_CC3);
}
}
另外还有个问题: "在中断里面放一个变量自加,再观察变量是否变化,可以检查I/O配置是否正确" 这个方法具体如何操作?斑竹能否指教一二,谢谢 |