打印

STM32管脚无PWM输出,KEIL4仿真却有。。

[复制链接]
4433|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
car_software|  楼主 | 2012-10-29 16:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
芯片是100个脚的 STM32F103VE  ,实验TIM1_CH1 (PA8脚)的PWM,
程序烧录到芯片中,示波器一直测试不到A8脚的PWM信号,
但同一程序,在KEIL 4下仿真,却能看到正常的PWM信号; 占空比也是对的;

无语中......

以下是程序:

//PWM func ,use PA8 pin and TIM1 timer, 2012-10-23 16:53:33
u16 capture = 0;
u16 CCR2_Val = 0xFFFF/100*50 ;   //占空比   50  


/*
通过示波器察看PA.08的输出波形。
由于TIM1计数器的时钟频率为72MHz,希望各通道输出频率fTIM1为17.57KHz,
根据:fTIM1=TIM1CLK/(TIM1_Period + 1),可得到TIM1预分频器的值TIM1_Period为0xFFFF。
根据公式:通道输出占空比 = TIM1_CCRx/(TIM1_Period + 1),可以得到各通道比较/捕获寄存器的计数值。
*/

void PWM_Init(void)
{
TIM_TimeBaseInitTypeDef  TIM1_TimeBaseStructure;
TIM_OCInitTypeDef  TIM1_OCInitStructure;
TIM_BDTRInitTypeDef TIM1_BDTRInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;

  /* GPIOA Configuration: Channel 1 Output */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  
//时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 | RCC_APB2Periph_GPIOA , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);  
                        
  /* TIM1 Peripheral Configuration */
  TIM_DeInit(TIM1);

  /* Time Base configuration */
  TIM1_TimeBaseStructure.TIM_Prescaler = 0x0;
  TIM1_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM1_TimeBaseStructure.TIM_Period = 0xFFFF;
  TIM1_TimeBaseStructure.TIM_ClockDivision = 0x0;
  TIM1_TimeBaseStructure.TIM_RepetitionCounter = 0x0;

  TIM_TimeBaseInit(TIM1,&TIM1_TimeBaseStructure);

  /* Channel 1, 2,3 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 = CCR2_Val;
  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;         
  
  TIM_OC1Init(TIM1,&TIM1_OCInitStructure);

  /* Automatic Output enable, Break, dead time and lock configuration*/
  TIM1_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
  TIM1_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
  TIM1_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
  TIM1_BDTRInitStructure.TIM_DeadTime = 0x75;
  TIM1_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
  TIM1_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
  TIM1_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;

  TIM_BDTRConfig(TIM1,&TIM1_BDTRInitStructure);

  /* TIM1 counter enable */
  TIM_Cmd(TIM1,ENABLE);

  /* Main Output Enable */
  TIM_CtrlPWMOutputs(TIM1,ENABLE);        
}
沙发
wlx583193113| | 2012-10-30 15:46 | 只看该作者
这个问题解决了吗  我也遇到这种问题  用逻辑分析仪 怎么都没有看到信号

使用特权

评论回复
板凳
laoguren1122| | 2014-12-6 21:19 | 只看该作者
楼主解决了么?我现在也是的

使用特权

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

本版积分规则

2

主题

44

帖子

0

粉丝