打印
[STM32F2]

pwm波形出不来,求大神们帮帮忙!

[复制链接]
1146|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wanshon|  楼主 | 2014-12-29 17:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
GPIO_Configuration();        
NVIC_Configuration4();
  TIM4_Configuration();
TIM_ClearFlag(TIM4, TIM_FLAG_Update);
  TIM_ARRPreloadConfig(TIM4, DISABLE);

  TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);   
        TIM_SelectOutputTrigger(TIM4,TIM_TRGOSource_Update);
  TIM_Cmd(TIM4, ENABLE);         
main(1)
{
}
void NVIC_Configuration4(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM4_Configuration(void)
{
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        TIM_OCInitTypeDef TIM_OCInitStructure;
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
        TIM_DeInit(TIM4);
  TIM_TimeBaseStructure.TIM_Period = (10-1); //100K
  TIM_TimeBaseStructure.TIM_Prescaler = (60-1);
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
        /* Output Compare Active Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle; //PWM??2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //??????
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;//??????
TIM_OCInitStructure.TIM_Pulse = 5; //????
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //????
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; //??????
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;TIM_OC1Init(TIM2,&TIM_OCInitStructure); //??1
TIM_OC3Init(TIM4, &TIM_OCInitStructure); //??TIM_OCInitStruct???????????TIMx
TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable); //??TIMx?CCR3????????

TIM_ARRPreloadConfig(TIM4, ENABLE); //??TIMx?ARR????????
/* TIM4 enable counter */
TIM_Cmd(TIM4, ENABLE); //??TIMx??
        TIM_CtrlPWMOutputs(TIM4, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;        
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC, ENABLE);         

//PB
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; //
         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//GPIO_Mode_Out_PP;//;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
        //GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;        
GPIO_Init(GPIOB, &GPIO_InitStructure);        
        

        
}
void TIM4_IRQHandler(void)
{
        /*if (TIM_GetITStatus(TIM4, TIM_IT_CC2) != RESET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC2);
TIM_SetCompare2(TIM4, TIM_GetCapture2(TIM4) + 5);
}*/

        if(TIM_GetITStatus(TIM4, TIM_IT_Update))            //????update????  
    {  
        TIM_ClearITPendingBit(TIM4, TIM_IT_Update);     //??update??????  
                        test_TIM4++;
    }  
        flag_time=1;}
这是原程序,怎么波形就出不来呢?
沙发
小浣熊| | 2014-12-29 17:28 | 只看该作者
我用的不是F2,希望可以有人帮你解决。。。

使用特权

评论回复
板凳
mmuuss586| | 2014-12-29 20:40 | 只看该作者
TIM_PWMOutput.rar (51.53 KB)
仅供参考;

使用特权

评论回复
地板
wanshon|  楼主 | 2014-12-30 10:58 | 只看该作者
我的系统里面怎么就没有TIM_HandleTypeDef这个结构体呢?

使用特权

评论回复
5
七宝汇| | 2015-3-26 23:21 | 只看该作者
//TIM4CH3应该是PD14,哥们你是不是没有配置这个引脚,配置的时候需要配置为复用引脚,楼下是我的
        GPIO_PinAFConfig(GPIOE, GPIO_PinSource9, GPIO_AF_TIM1);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOE,&GPIO_InitStructure);

使用特权

评论回复
6
wind~风| | 2015-4-30 22:05 | 只看该作者
楼上正解,相应引脚要配置为复用功能

使用特权

评论回复
7
那就地方iv| | 2015-5-1 09:49 | 只看该作者
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; 换成 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

12

帖子

0

粉丝