初中生
最后登录1970-1-1
在线时间 小时
注册时间2017-1-14
|
#include "bsp_Advance_Tim.h"
static void Advance_TIM_GPIOConfig()
{
GPIO_InitTypeDef GPIO_TimStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_TimStruct.GPIO_Pin = GPIO_Pin_8;
GPIO_TimStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_TimStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_TimStruct);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_TimStruct.GPIO_Pin = GPIO_Pin_13;
GPIO_TimStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_TimStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_TimStruct);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_TimStruct.GPIO_Pin = GPIO_Pin_12;
GPIO_TimStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_TimStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_TimStruct);
GPIO_ResetBits(GPIOB,GPIO_Pin_12);
}
static void AdvanceTim_Config()
{
TIM_TimeBaseInitTypeDef Advance_TimBaseStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
Advance_TimBaseStruct.TIM_ClockDivision = TIM_CKD_DIV1;
Advance_TimBaseStruct.TIM_CounterMode = TIM_CounterMode_Up;
Advance_TimBaseStruct.TIM_Period = (9 - 1);
Advance_TimBaseStruct.TIM_Prescaler = (8 - 1);
Advance_TimBaseStruct.TIM_RepetitionCounter = 4;
TIM_TimeBaseInit(TIM1,&Advance_TimBaseStruct);
TIM_OCInitTypeDef AdvanceOC_TimStruct;
AdvanceOC_TimStruct.TIM_OCIdleState = TIM_OCIdleState_Set;
AdvanceOC_TimStruct.TIM_OCMode = TIM_OCMode_PWM1;
AdvanceOC_TimStruct.TIM_OCNIdleState = TIM_OCNIdleState_Set;
AdvanceOC_TimStruct.TIM_OCNPolarity = TIM_OCNPolarity_High;
AdvanceOC_TimStruct.TIM_OCPolarity = TIM_OCPolarity_High;
AdvanceOC_TimStruct.TIM_OutputNState = TIM_OutputNState_Enable;
AdvanceOC_TimStruct.TIM_OutputState = TIM_OutputState_Enable;
AdvanceOC_TimStruct.TIM_Pulse = TIM_OPMode_Single;
TIM_OC1Init(TIM1,&AdvanceOC_TimStruct);
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
// TIM_OC1PolarityConfig(TIM1,TIM_OCPolarity_High);
// TIM_OC1NPolarityConfig(TIM1,TIM_OCNPolarity_High);
TIM_CCxCmd(TIM1,TIM_Channel_1,TIM_CCx_Enable);
TIM_BDTRInitTypeDef AdvanceTimStruct;
AdvanceTimStruct.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
AdvanceTimStruct.TIM_Break = TIM_Break_Enable;
AdvanceTimStruct.TIM_BreakPolarity = TIM_BreakPolarity_Low;
AdvanceTimStruct.TIM_DeadTime = 11;
AdvanceTimStruct.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
AdvanceTimStruct.TIM_OSSIState = TIM_OSSIState_Enable;
AdvanceTimStruct.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRConfig(TIM1,&AdvanceTimStruct);
TIM_Cmd(TIM1,ENABLE);
TIM_ClearFlag(TIM1,TIM_FLAG_Break);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
}
void Advance_Tim_Init()
{
Advance_TIM_GPIOConfig();
AdvanceTim_Config();
}
|
-
不接地波形图 ,接地直接没波
|