野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13113|回复: 3

重映射问题

[复制链接]
发表于 2015-1-16 18:16:36 | 显示全部楼层 |阅读模式

复制代码


回复

使用道具 举报

 楼主| 发表于 2015-1-16 18:17:31 | 显示全部楼层
  1. static void TIM3_GPIO_Config(void)
  2. {
  3.   GPIO_InitTypeDef GPIO_InitStructure;

  4. //        /* éèÖÃTIM3CLK Îa 72MHZ */
  5. //  RCC_APB1PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
  6. //        GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE);
  7.   /* GPIOA and GPIOB clock enable */
  8.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE|RCC_APB2Periph_AFIO|RCC_APB2Periph_TIM1, ENABLE);

  9. //          GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE);
  10.     GPIO_PinRemapConfig(GPIO_PartialRemap_TIM1, ENABLE);
  11.        
  12.   /*GPIOA Configuration: TIM3 channel 1 and 2 as alternate function push-pull */
  13.   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_9 | GPIO_Pin_11|GPIO_Pin_13 | GPIO_Pin_14;
  14.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;                    // ¸′óÃíÆíìêä3ö
  15.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  16.   GPIO_Init(GPIOE, &GPIO_InitStructure);

  17. //  /*GPIOB Configuration: TIM3 channel 3 and 4 as alternate function push-pull */
  18. //  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_0 | GPIO_Pin_1;
  19. //  GPIO_Init(GPIOB, &GPIO_InitStructure);
  20. }

  21. /**
  22.   * @brief  ÅäÖÃTIM3êä3öμÄPWMDÅoÅμÄģ꽣¬èçÖüÆú¡¢¼«DÔ¡¢Õ¼¿Õ±è
  23.   * @param  ÎT
  24.   * @retval ÎT
  25.   */
  26. /*
  27. * TIMxCLK/CK_PSC --> TIMxCNT --> TIMx_ARR --> TIMxCNT ÖØD¼Æêy
  28. *                    TIMx_CCR(μçƽ·¢éú±ä»ˉ)
  29. * DÅoÅÖüÆú=(TIMx_ARR +1 ) * ê±ÖóÖüÆú
  30. * Õ¼¿Õ±è=TIMx_CCR/(TIMx_ARR +1)
  31. */
  32. static void TIM3_Mode_Config(void)
  33. {
  34.         TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  35.         TIM_OCInitTypeDef  TIM_OCInitStructure;

  36.         /* PWMDÅoÅμçƽìø±äÖμ */
  37.         u16 CCR1_Val = 500;        
  38.         u16 CCR2_Val = 375;
  39.         u16 CCR3_Val = 250;
  40.         u16 CCR4_Val = 125;

  41. /* -----------------------------------------------------------------------
  42.     TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR+1)* 100% = 50%
  43.     TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR+1)* 100% = 37.5%
  44.     TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR+1)* 100% = 25%
  45.     TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR+1)* 100% = 12.5%
  46.   ----------------------------------------------------------------------- */

  47.   /* Time base configuration */                 
  48.   TIM_TimeBaseStructure.TIM_Period = 999;       //챶¨ê±Æ÷′ó0¼Æêyμ½999£¬¼′Îa1000′Σ¬Îaò»¸ö¶¨ê±ÖüÆú
  49.   TIM_TimeBaseStructure.TIM_Prescaler = 0;            //éèÖÃÔ¤·ÖÆμ£o2»Ô¤·ÖÆ죬¼′Îa72MHz
  50.   TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;        //éèÖÃê±Öó·ÖÆμÏμêy£o2»·ÖÆμ(ÕaàïóÃ2»μ½)
  51.   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //ÏòéϼÆêyÄ£ê½
  52.   TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

  53.   /* PWM1 Mode configuration: Channel1 */
  54.   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;            //ÅäÖÃÎaPWMÄ£ê½1
  55.   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;       
  56.   TIM_OCInitStructure.TIM_Pulse = CCR1_Val;           //éèÖÃìø±äÖμ£¬μ±¼ÆêyÆ÷¼Æêyμ½Õa¸öÖμê±£¬μçƽ·¢éúìø±ä
  57.   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;  //챶¨ê±Æ÷¼ÆêyÖμD¡óúCCR1_Valê±Îa¸ßμçƽ
  58.   TIM_OC1Init(TIM1, &TIM_OCInitStructure);         //ê1Äüí¨μà1
  59.   TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);

  60.   /* PWM1 Mode configuration: Channel2 */
  61.   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  62.   TIM_OCInitStructure.TIM_Pulse = CCR2_Val;          //éèÖÃí¨μà2μÄμçƽìø±äÖ죬êä3öáííaò»¸öÕ¼¿Õ±èμÄPWM
  63.   TIM_OC2Init(TIM1, &TIM_OCInitStructure);          //ê1Äüí¨μà2
  64.   TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);

  65.   /* PWM1 Mode configuration: Channel3 */
  66.   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  67.   TIM_OCInitStructure.TIM_Pulse = CCR3_Val;        //éèÖÃí¨μà3μÄμçƽìø±äÖ죬êä3öáííaò»¸öÕ¼¿Õ±èμÄPWM
  68.   TIM_OC3Init(TIM1, &TIM_OCInitStructure);         //ê1Äüí¨μà3
  69.   TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);

  70.   /* PWM1 Mode configuration: Channel4 */
  71.   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  72.   TIM_OCInitStructure.TIM_Pulse = CCR4_Val;        //éèÖÃí¨μà4μÄμçƽìø±äÖ죬êä3öáííaò»¸öÕ¼¿Õ±èμÄPWM
  73.   TIM_OC4Init(TIM1, &TIM_OCInitStructure);        //ê1Äüí¨μà4
  74.   TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable);
  75.   TIM_ARRPreloadConfig(TIM1, ENABLE);                         // ê1ÄüTIM3ÖØÔؼÄ′æÆ÷ARR
  76. //GPIO_PinConfig(GPIOA, GPIO_PinSource6, GPIO_AF_TIM3);
  77.   /* TIM3 enable counter */
  78.   TIM_Cmd(TIM1, ENABLE);                   //ê1Äü¶¨ê±Æ÷3       
  79. }

  80. /**
  81.   * @brief  TIM3 êä3öPWMDÅoÅ3õê¼»ˉ£¬Ö»òaμ÷óÃÕa¸öoˉêy
  82.   *         TIM3μÄËĸöí¨μà¾í»áóDPWMDÅoÅêä3ö
  83.   * @param  ÎT
  84.   * @retval ÎT
  85.   */
  86. void TIM3_PWM_Init(void)
  87. {
  88.         TIM3_GPIO_Config();
  89.         TIM3_Mode_Config();       
  90. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-1-16 18:34:43 | 显示全部楼层
我查没查到结果。谢谢
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-1-17 20:22:33 | 显示全部楼层
还是没出结果
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-11-23 12:32 , Processed in 0.029083 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表