打印
[STM32F0]

STM32F030输出不了 二分频的24MHZ的PWM

[复制链接]
1224|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
289947679|  楼主 | 2016-1-9 15:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
帮我看一下程序
include "time.h"
#include "led.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;
uint16_t TimerPeriod = 0;
uint16_t Channel1Pulse = 0, Channel2Pulse = 0, Channel3Pulse = 0, Channel4Pulse = 0;
void TIM_Config(void)
{






GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE);
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, ENABLE);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;// | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
  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(GPIOB, &GPIO_InitStructure);

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_0);


void TIM_PWM_Config(void)

{

  
TimerPeriod = (SystemCoreClock/2000000) -1 ;

  Channel1Pulse = (uint16_t) (((uint32_t) 5 * ( TimerPeriod - 1)) / 10);


  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14 , ENABLE);

  TIM_TimeBaseStructure.TIM_Prescaler =0 ;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  /* Time ¶¨Ê±ÉèÖÃΪÉÏÉýÑؼÆËãģʽ*/

  TIM_TimeBaseStructure.TIM_Period = 0;//TimerPeriod;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
  TIM_TimeBaseInit(TIM14, &TIM_TimeBaseStructure);

  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
  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_OCInitStructure.TIM_Pulse = Channel1Pulse;//ʹÄÜƵµÀ1ÅäÖÃ
  TIM_OC1Init(TIM14, &TIM_OCInitStructure);


  TIM_Cmd(TIM14, ENABLE);

//  /* TIM1 Ö÷Êä³öʹÄÜ */
  TIM_CtrlPWMOutputs(TIM14, ENABLE);
//  TIM_ITConfig(TIM3,TIM_IT_CC1,ENABLE);
//// .NVIC_IRQChannel=TIM3_IRQN;
//// NVIC_Init
}

沙发
豆腐块| | 2016-1-10 21:50 | 只看该作者
这程序编译通过了吗,少个 } 吧

使用特权

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

本版积分规则

4

主题

22

帖子

1

粉丝