打印

STM32F0产生PWM问题

[复制链接]
3029|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
llglqh|  楼主 | 2012-7-16 20:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
之前产生PWM是正常的,但是加了NVIC配置以后,就不产生PWM波形了,大侠知道怎么回事吗?

#include "stm32f0xx.h"
#include "stm32f0_discovery.h"

void TIM_Config(void);
void NVIC_Configuration(void);

int main(void)
{
  NVIC_Configuration();
  TIM_Config();
  STM_EVAL_LEDInit(LED3);
  while (1)
  {}
}
void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  
  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 TIM_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  /* GPIOA Clocks enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, 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);
  
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_OCInitTypeDef  TIM_OCInitStructure;
    /* TIM1 clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);
  
  /* Time Base configuration */
  TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock/1000)-1;  
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up ; TIM_TimeBaseStructure.TIM_Period = 2000-1;  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  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_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
  TIM_OCInitStructure.TIM_Pulse = 500;
  TIM_OC1Init(TIM1, &TIM_OCInitStructure);
  /* TIM1 counter enable */
  TIM_Cmd(TIM1, ENABLE);
  /* TIM1 Main Output Enable */
  TIM_CtrlPWMOutputs(TIM1, ENABLE);
  
//  TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
//  TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE );
//  TIM_ARRPreloadConfig(TIM1, ENABLE);
}
沙发
llglqh|  楼主 | 2012-7-16 21:00 | 只看该作者
就是多了 NVIC_Configuration();这个函数,他就不产生PWM了,但是这句话注释掉又正常了,其他都没变。

使用特权

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

本版积分规则

0

主题

28

帖子

0

粉丝