用F1的核心板写的程序就可以用,用F4开发板写好后就没有反应。
不是说F103和F407接口一样么。
求解,三天了没搞懂。
#include "timer.h"
/**
* @brief ÅäÖÃTIM3¸′óÃêä3ö
WMê±óÃμ½μÄI/O
* @param ÎT
* @retval ÎT
*/
static void TIM3_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); // GPIOA and GPIOB clock enable
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // ¸′óÃíÆíìêä3ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; // I/Oòy½ÅËù¶è2M/S
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; //GPIOA Configuration: TIM3 channel 1 and 2 as alternate function push-pull
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/**
* @brief ÅäÖÃTIM1êä3öμÄ
WMDÅoÅμÄģ꽣¬èçÖüÆú¡¢¼«DÔ¡¢Õ¼¿Õ±è
* @param ÎT
* @retval ÎT
*/
/*
* TIMxCLK/CK_PSC --> TIMxCNT --> TIMx_ARR --> TIMxCNT ÖØD¼Æêy
* TIMx_CCR(μçƽ·¢éú±ä»ˉ)
* DÅoÅÖüÆú=(TIMx_ARR +1 ) * ê±ÖóÖüÆú
* Õ¼¿Õ±è=TIMx_CCR/(TIMx_ARR +1)
*/
static void TIM3_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
/* PWMDÅoÅμçƽìø±äÖμ */
u16 CCR1_Val = 6300; //Õ¼¿Õ±è0% £¬êä3öμíμçƽ
u16 CCR2_Val = 0; //Õ¼¿Õ±è0% £¬êä3öμíμçƽ
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3 , ENABLE); // ′ò¿a¶¨ê±Æ÷3μÄê±Öó
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 7200-2; //챶¨ê±Æ÷′ó0¼Æêyμ½7200-2£¬¼′Îa7200-1′Σ¬Îaò»¸ö¶¨ê±ÖüÆú
TIM_TimeBaseStructure.TIM_Prescaler = 0; //éèÖÃÔ¤·ÖÆμ£o2»Ô¤·ÖÆ죬¼′Îa72MHz
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ; //éèÖÃê±Öó·ÖÆμÏμêy£o2»·ÖÆμ(ÕaàïóÃ2»μ½)
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòéϼÆêyÄ£ê½
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //ÅäÖÃÎaPWMÄ£ê½1
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//êä3öê1Äü
TIM_OCInitStructure.TIM_OutputNState= TIM_OutputNState_Disable; //»¥21êä3öê§Äü£¨¸ß¼¶¶¨ê±Æ÷2ÅóD£©
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //챶¨ê±Æ÷¼ÆêyÖμD¡óúCCR1_Valê±Îa¸ßμçƽ
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; //챶¨ê±Æ÷¼ÆêyÖμD¡óúCCR1_Valê±Îa¸ßμçƽ
TIM_OCInitStructure.TIM_Pulse = CCR1_Val; //éèÖÃìø±äÖμ£¬μ±¼ÆêyÆ÷¼Æêyμ½Õa¸öÖμê±£¬μçƽ·¢éúìø±ä
TIM_OC1Init(TIM3, &TIM_OCInitStructure); //ê1Äüí¨μà1
TIM_OCInitStructure.TIM_Pulse = CCR2_Val; //éèÖÃìø±äÖμ£¬μ±¼ÆêyÆ÷¼Æêyμ½Õa¸öÖμê±£¬μçƽ·¢éúìø±ä
TIM_OC2Init(TIM3, &TIM_OCInitStructure); //ê1Äüí¨μà2
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable); //1í¨μàԤװÔØê1Äü
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable); //2í¨μàԤװÔØê1Äü
TIM_ARRPreloadConfig(TIM3, ENABLE); // ê1ÄüTIM3ÖØÔؼÄ′æÆ÷ARR
TIM_Cmd(TIM3, ENABLE); //ê1Äü¶¨ê±Æ÷3
}
/**
* @brief TIM1 êä3ö
WMDÅoÅ3õê¼»ˉ£¬Ö»òaμ÷óÃÕa¸öoˉêy
* TIM1μÄËĸöí¨μà¾í»áóDPWMDÅoÅêä3ö
* @param ÎT
* @retval ÎT
*/
void TIM3_PWM_Init(void)
{
TIM3_Mode_Config(); //¶¨ê±Æ÷TIM31¤×÷Ä£ê½ÅäÖÃ
TIM3_GPIO_Config(); //I/0êä3öòy½ÅÅäÖÃ
}
一周热门 更多>