定时器1ch4(PA11)产生PWM ,在STM32正常,MM32卡死,是什么原因?
(使用MM32库)
void Tim1_Init()
{
/* TIM1 Peripheral Configuration */
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM1_TimeBaseStructure;
TIM_OCInitTypeDef TIM1_OCInitStructure;
TIM_BDTRInitTypeDef TIM1_BDTRInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE);
/* TIM1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM_DeInit(TIM1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Time Base configuration */
TIM1_TimeBaseStructure.TIM_Prescaler = 10;//0x0; 分频
TIM1_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM1_TimeBaseStructure.TIM_Period = 6500-1; //6500-1? 3600-1;
TIM1_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM1_TimeBaseStructure.TIM_RepetitionCounter = 0x0;
TIM_TimeBaseInit(TIM1,&TIM1_TimeBaseStructure);
// Channel 4 and 4 Configuration in PWM mode
TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM1_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM1_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM1_OCInitStructure.TIM_Pulse = 1800;
TIM1_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM1_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM1_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM1_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM1_OCInitStructure.TIM_Pulse = 1800 ; //50%
TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable); //使能TIMx在CCR2上的预装载寄存器
TIM_OC4Init(TIM1,&TIM1_OCInitStructure);
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE); //TIM1_CH4 PWM输出
} |
[url=]更多操作[/url]
|