static void TIME_NVIC_Configuration1(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/*设置NVIC中断分组1位抢占优先级,3位响应优先级*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // 中断优先级最高
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM1_PWMConfig()
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
/******************** PWM引脚的设置 **********************/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //
GPIO_Init(GPIOB, &GPIO_InitStructure);
/******************** TIME1基本配置 **********************/
TIM_TimeBaseInitStructure.TIM_Period=90 - 1; // 90*2*2/72m=50us 200KHZ
TIM_TimeBaseInitStructure.TIM_Prescaler= 2 - 1;
TIM_TimeBaseInitStructure.TIM_ClockDivision=0;
TIM_TimeBaseInitStructure.TIM_CounterMode= TIM_CounterMode_CenterAligned1 ; //现在是进行上下计数;
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0; //重复计数的初始值
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseInitStructure);
TIM_ClearFlag(TIM1, TIM_FLAG_Update);//清楚中断标志
TIM_ITConfig(TIM1, TIM_IT_Update|TIM_IT_Trigger, DISABLE); //使能中断源
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //向上计数 TIMx_CNT<TIMx_CCRn,N通道输出有效电平 否则为无效电平。
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState =TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //高有效
TIM_OCInitStructure.TIM_OCNPolarity =TIM_OCNPolarity_High; //
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
//通道1
TIM_OCInitStructure.TIM_Pulse =45 ;
TIM_OC1Init(TIM1,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable); //可以进行重装载植
//死区时间的设置 这里使能
TIM_BDTRInitStructure.TIM_AutomaticOutput=TIM_AutomaticOutput_Enable;
TIM_BDTRInitStructure.TIM_Break=TIM_Break_Disable;//TIM_Break_Enable;
TIM_BDTRInitStructure.TIM_BreakPolarity=TIM_BreakPolarity_High;
TIM_BDTRInitStructure.TIM_DeadTime=28; //(28/900)*50us=1.555us /4 500ns死区时间
TIM_BDTRInitStructure.TIM_LOCKLevel=TIM_LOCKLevel_OFF;
TIM_BDTRInitStructure.TIM_OSSIState=TIM_OSSIState_Disable;//TIM_OSSIState_Disable;//TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_OSSRState=TIM_OSSRState_Disable;//TIM_OSSRState_Disable;//TIM_OSSRState_Enable;
TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure);
TIM_ARRPreloadConfig(TIM1,ENABLE);
//TIM_CtrlPWMOutputs(TIM1,ENABLE);//MOE=1,??OC?OCN??
TIME_NVIC_Configuration1();
//TIM_Cmd(TIM1,ENABLE);
}
void input(void)
{
//+++++++++++++++++++++++++++++++++++++++++++++++++++停止脉冲输出
if(IN_TZ==0)
{
TIM_CtrlPWMOutputs(TIM1,DISABLE);//MOE=0,
TIM_Cmd(TIM1,DISABLE);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++启动脉冲输出
if(IN_QD==0)
{
TIM_CtrlPWMOutputs(TIM1,ENABLE);//MOE=1,
TIM_Cmd(TIM1,ENABLE);
}
}
学硬件的,问题是这样怎么改成可调频率和死区时间的输出。。。。。
|
PB13 PB8输出互补对称PWM用与全桥控制电路,目前可以开可关,可是频率不知道怎么改成可调的