帮忙看下这个代码,为什么同样的思路 用F1板子写就没有问题。
F4写的一直不知道哪里的问题,示波器也不出波形
#include "TIM3_PWM.H"
#include "sys.h"
void TIM3_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructuer;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
GPIO_InitStructuer.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructuer.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructuer.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructuer.GPIO_OType=GPIO_OType_PP;
GPIO_Init(GPIOA,&GPIO_InitStructuer);
}
void TIM3_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStruce;
/* PWMDÅoÅμçƽìø±äÖμ */
u16 CCR1_Val = 500;
u16 CCR2_Val = 200;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
//¶¨ê±Æ÷ÅäÖÃ
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period=500;
TIM_TimeBaseStructure.TIM_Prescaler= 84-1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_OCInitStruce.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStruce.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStruce.TIM_OutputNState= TIM_OutputNState_Disable;
TIM_OCInitStruce.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OCInitStruce.TIM_OCNPolarity=TIM_OCPolarity_Low;
TIM_OCStructInit(&TIM_OCInitStruce);
TIM_OCInitStruce.TIM_Pulse=CCR1_Val;
TIM_OC1Init(TIM3,&TIM_OCInitStruce);
TIM_OCInitStruce.TIM_Pulse=CCR2_Val;
TIM_OC2Init(TIM3,&TIM_OCInitStruce);
TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3,ENABLE);
TIM_Cmd (TIM3,ENABLE);
}
void TIM3_PWM_Init(void)
{
TIM3_Mode_Config () ;
TIM3_GPIO_Config () ;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>