#include "bsp_Tim.h"
/*。。。。。。。。。。信号输出通道设置。。。。。。。。。。。。。。。
TIM_GPIO_CLK RCC_APB2Periph_GPIOA
TIM_PORT GPIOA
TIM_WF1_CH_PIN GPIO_Pin_8 //左骻
TIM_WF2_CH_PIN GPIO_Pin_9 //左膝
TIM_WF3_CH_PIN GPIO_Pin_10 //右骻
TIM_WF4_CH_PIN GPIO_Pin_11 //右膝
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。*/
static void TIM_GPIO_Config(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
/*GPIOA_PIN8通道初始化设置*/
GPIO_InitStructure.GPIO_Pin = TIM_WF1_CH_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(TIM_PORT, &GPIO_InitStructure);
/*GPIOA_PIN9通道初始化设置*/
GPIO_InitStructure.GPIO_Pin = TIM_WF2_CH_PIN;
GPIO_Init(TIM_PORT, &GPIO_InitStructure);
/*GPIOA_PIN10通道初始化设置*/
GPIO_InitStructure.GPIO_Pin = TIM_WF3_CH_PIN;
GPIO_Init(TIM_PORT, &GPIO_InitStructure);
/*GPIOB_PIN11通道初始化设置*/
GPIO_InitStructure.GPIO_Pin = TIM_WF4_CH_PIN;
GPIO_Init(TIM_PORT, &GPIO_InitStructure);
}
/*。。。。。。。。定时器初始化配置。。。。。。。。。。。。。。。。。。。。。。
主要参数:ADVANCE_TIM, ADVANCE_TIM_APBxClock_FUN,
TIM_CLK TIM_PERIOD, TIM_PSC,
TIM_WF1_ITCC, TIM_WF2_ITCC,
TIM_WF3_ITCC, TIM_WF4_ITCC
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。*/
static void TIM_Mode_Config(void)
{
/*开启定时器内部时钟*/
ADVANCE_TIM_APBxClock_FUN(TIM_CLK,ENABLE);
/*--------------------时基结构体初始化-------------------------*/
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// 自动重装载寄存器的值,没有用到
TIM_TimeBaseStructure.TIM_Period=TIM_PERIOD ;
// 驱动CNT计数器的时钟 = Fck_int/(psc+1)
TIM_TimeBaseStructure.TIM_Prescaler= TIM_PSC ;
// 时钟分频因子 ,配置死区时间时需要用到
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
// 计数器计数模式,设置为向上计数
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
// 重复计数器的值,没用到不用管
TIM_TimeBaseStructure.TIM_RepetitionCounter=0;
// 初始化定时器
TIM_TimeBaseInit(ADVANCE_TIM, &TIM_TimeBaseStructure);
/*--------------------输出比较结构体初始化-------------------*/
TIM_OCInitTypeDef TIM_OCInitStructure;
//设置输出模式为比较输出模式
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
//输出使能
TIM_OCInitStructure.TIM_OutputState =TIM_OutputState_Enable;
// 输出通道电平极性配置
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
// 输出通道空闲电平极性配置
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OC1Init(ADVANCE_TIM, &TIM_OCInitStructure); //配置CH1通道
TIM_OC1PreloadConfig(ADVANCE_TIM,TIM_OCPreload_Disable); //预加载寄存器配置
TIM_OC2Init(ADVANCE_TIM, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(ADVANCE_TIM,TIM_OCPreload_Disable);
TIM_OC3Init(ADVANCE_TIM, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(ADVANCE_TIM,TIM_OCPreload_Disable);
TIM_OC4Init(ADVANCE_TIM, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(ADVANCE_TIM,TIM_OCPreload_Disable);
//使能计数器
TIM_Cmd(ADVANCE_TIM, ENABLE);
// //主输出使能
TIM_CtrlPWMOutputs(ADVANCE_TIM, ENABLE);
}
/*。。。。。。。。。。。。。。定时器中断配置。。。。。。。。。。。。。。。。
.........................................................................*/
static void TIM_IRQ_Config(void)
{
/*。。。。输出比较通道中断使能。。。。。*/
TIM_ITConfig(ADVANCE_TIM,TIM_WF1_ITCC,ENABLE);
TIM_ITConfig(ADVANCE_TIM,TIM_WF2_ITCC,ENABLE);
TIM_ITConfig(ADVANCE_TIM,TIM_WF3_ITCC,ENABLE);
TIM_ITConfig(ADVANCE_TIM,TIM_WF4_ITCC,ENABLE);
/*。。。。。。中断结构体初始化。。。。。。。。*/
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStruct.NVIC_IRQChannel =TIM1_CC_IRQn;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE ;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_Init (&NVIC_InitStruct);
}
void OUTPUT_CONFIG(void)
{
TIM_GPIO_Config();
TIM_Mode_Config();
TIM_IRQ_Config();
}
|