打印
[STM32F0]

求stm32f030f4p6系统时钟变36MHZ的方法

[复制链接]
1718|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
求stm32f030f4p6系统时钟变36MHZ的方法。不知道怎么去改。有图形
沙发
289947679|  楼主 | 2016-1-8 17:05 | 只看该作者
求stm32f030f4p6系统时钟变36MHZ的方法

QQ截图20160108165948.png (74.59 KB )

QQ截图20160108165948.png

使用特权

评论回复
板凳
Varus| | 2016-1-8 17:06 | 只看该作者
楼主用的内部还是外部时钟,是不是用分频

使用特权

评论回复
地板
289947679|  楼主 | 2016-1-8 17:07 | 只看该作者
这个图才是对的

QQ截图20160108170637.png (71.95 KB )

QQ截图20160108170637.png

使用特权

评论回复
5
xmshao| | 2016-1-9 11:53 | 只看该作者
看来大家对STM32Cube 运用得很熟啊

楼主也下载个STM32CUBEMX玩玩 很方便的

使用特权

评论回复
6
289947679|  楼主 | 2016-1-9 13:54 | 只看该作者
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)
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_OCInitTypeDef TIM_OCInitSrtucture;
       
GPIO_InitTypeDef GPIO_InitStructure;
        //TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE);
        RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, ENABLE);
        /* ÅäÖÃGPIO¹Ü½Å¸´ÓÃ*/
  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);
        //Ó³ÉäI/OΪÍâÉèËùÓÃ
         GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_0);
       
// GPIO_InitTypeDef GPIO_InitStructure;

  /* ʹÄÜGPIOʱÖÓ */
// RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, ENABLE);
  
//  /* ÅäÖÃGPIO¹Ü½Å¸´ÓÃ*/
//  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_1);
//  GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_2);
//  GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_2);
//  GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_2);

}

void TIM_PWM_Config(void)
{
        /* TIM14 µÄÅäÖà ---------------------------------------------------PB1Êä³ö36Mhz clock
   TIM1 ÊäÈëʱÖÓ(TIM1CLK) ÉèÖÃΪ APB2 ʱÖÓ (PCLK2)   
    => TIM1CLK = PCLK2 = SystemCoreClock
   TIM1CLK = SystemCoreClock, Prescaler = 0, TIM1 counter clock = SystemCoreClock
   SystemCoreClock Ϊ48 MHz
   
   ÎÒÃǵÄÄ¿±ê²úÉú 4 ·PWM ÐźÅÔÚ17.57 KHz:
     - TIM1_Period = (SystemCoreClock / 17570) - 1
   ÐŵÀ1ÉèÖõÄÕ¼¿Õ±ÈΪ 50%
   ÐŵÀ2ÉèÖõÄÕ¼¿Õ±ÈΪ 37.5%
   ÐŵÀ3ÉèÖõÄÕ¼¿Õ±ÈΪ 25%
   ÐŵÀ4ÉèÖõÄÕ¼¿Õ±ÈΪ 12.5%
   ¶¨Ê±Æ÷Âö³åµÄ¼ÆË㷽ʽÈçÏÂ:
     - ChannelxPulse = DutyCycle * (TIM1_Period - 1) / 100
        */  
    /*¼ÆËãÔ¤¶¨±íµÄÖµ£¬Ò²¾ÍÊǶàÉÙ¸öʱÖÓ¼ÆÊýΪһ¸öÖÜÆÚ*/
  //TimerPeriod = (SystemCoreClock / 17570 ) - 1;
        //TimerPeriod = (SystemCoreClock/1000000) -1 ;
        TimerPeriod = (SystemCoreClock/1000000) -1 ;
  /*¼ÆËãCCR1 Ìøתֵ ÔÚÕ¼¿Õ±ÈΪ50%ʱ*/
  Channel1Pulse = (uint16_t) (((uint32_t) 5 * ( TimerPeriod - 1)) / 10);
/*¼ÆËãCCR2 Ìøתֵ ÔÚÕ¼¿Õ±ÈΪ37.5%ʱ*/
//  Channel2Pulse = (uint16_t) (((uint32_t) 375 * (TimerPeriod - 1)) / 1000);
//  /*¼ÆËãCCR3 Ìøתֵ ÔÚÕ¼¿Õ±ÈΪ25%ʱ*/
//  Channel3Pulse = (uint16_t) (((uint32_t) 25 * (TimerPeriod - 1)) / 100);
// /*¼ÆËãCCR4Ìøתֵ ÔÚÕ¼¿Õ±ÈΪ12.5%ʱ*/
//  Channel4Pulse = (uint16_t) (((uint32_t) 125 * (TimerPeriod- 1)) / 1000);

  /* TIM14 ʱÖÓʹÄÜ */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14 , ENABLE);
  
  /* Time ¶¨Ê±»ù´¡ÉèÖÃ*/
//         u16 CCR1= 0;           
//   u16 CCR2= 0;
  TIM_TimeBaseStructure.TIM_Prescaler =0 ;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  /* Time ¶¨Ê±ÉèÖÃΪÉÏÉýÑؼÆËãģʽ*/
        //TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;  /* Time ¶¨Ê±ÉèÖÃΪÏÂÉýÑؼÆËãģʽ*/
  TIM_TimeBaseStructure.TIM_Period = TimerPeriod;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  TIM_TimeBaseInit(TIM14, &TIM_TimeBaseStructure);

  /* ƵµÀ1£¬2£¬3£¬4µÄPWM ģʽÉèÖà */
  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_OCInitStructure.TIM_Pulse = Channel1Pulse;//ʹÄÜƵµÀ1ÅäÖÃ
  TIM_OC1Init(TIM14, &TIM_OCInitStructure);

//  TIM_OCInitStructure.TIM_Pulse = Channel2Pulse;//ʹÄÜƵµÀ2ÅäÖÃ
//  TIM_OC2Init(TIM1, &TIM_OCInitStructure);

//  TIM_OCInitStructure.TIM_Pulse = Channel3Pulse;//ʹÄÜƵµÀ3ÅäÖÃ
//  TIM_OC3Init(TIM1, &TIM_OCInitStructure);

//  TIM_OCInitStructure.TIM_Pulse = Channel4Pulse;//ʹÄÜƵµÀ4ÅäÖÃ
//  TIM_OC4Init(TIM1, &TIM_OCInitStructure);
       
  /* TIM1 ¼ÆËãÆ÷ʹÄÜ*/
  TIM_Cmd(TIM14, ENABLE);
       
//  /* TIM1 Ö÷Êä³öʹÄÜ */
  TIM_CtrlPWMOutputs(TIM14, ENABLE);       
//  TIM_ITConfig(TIM3,TIM_IT_CC1,ENABLE);
////        .NVIC_IRQChannel=TIM3_IRQN;
////        NVIC_Init
        }

使用特权

评论回复
7
289947679|  楼主 | 2016-1-9 13:55 | 只看该作者
现在系统时钟达到36M,但是PWM搞不出36MHZ
,有人帮我看看

使用特权

评论回复
8
309030| | 2016-1-9 16:49 | 只看该作者
系统时钟达到36M,但是PWM搞不出36MHZ

PWM频率要这么高吗

使用特权

评论回复
9
UBC-Jason| | 2016-1-13 16:40 | 只看该作者
看官帮顶,学习学习!

使用特权

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

本版积分规则

4

主题

22

帖子

1

粉丝