static void ADVANCE_TIM_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(ADVANCE_TIM_CH1_GPIO_CLK|ADVANCE_TIM_CH2_GPIO_CLK|ADVANCE_TIM_CH3_GPIO_CLK, ENABLE);
GPIO_InitStructure.GPIO_Pin = ADVANCE_TIM_CH1_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(ADVANCE_TIM_CH1_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = ADVANCE_TIM_CH2_PIN;
GPIO_Init(ADVANCE_TIM_CH2_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = ADVANCE_TIM_CH3_PIN;
GPIO_Init(ADVANCE_TIM_CH3_PORT, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(ADVANCE_TIM_CH1N_GPIO_CLK|ADVANCE_TIM_CH2N_GPIO_CLK|ADVANCE_TIM_CH3N_GPIO_CLK, ENABLE);
GPIO_InitStructure.GPIO_Pin = ADVANCE_TIM_CH1N_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(ADVANCE_TIM_CH1N_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = ADVANCE_TIM_CH2N_PIN;
GPIO_Init(ADVANCE_TIM_CH2N_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = ADVANCE_TIM_CH3N_PIN;
GPIO_Init(ADVANCE_TIM_CH3N_PORT, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(ADVANCE_TIM_BKIN_GPIO_CLK, ENABLE);
GPIO_InitStructure.GPIO_Pin = ADVANCE_TIM_BKIN_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(ADVANCE_TIM_BKIN_PORT, &GPIO_InitStructure);
GPIO_ResetBits(ADVANCE_TIM_BKIN_PORT,ADVANCE_TIM_BKIN_PIN);
}
static void ADVANCE_TIM_Mode_Config(void)
{
ADVANCE_TIM_APBxClock_FUN(ADVANCE_TIM_CLK,ENABLE);
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period=ADVANCE_TIM_PERIOD;
TIM_TimeBaseStructure.TIM_Prescaler= ADVANCE_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_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = ADVANCE_TIM_PULSE;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;
TIM_OC1Init(ADVANCE_TIM, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(ADVANCE_TIM, TIM_OCPreload_Enable);
TIM_OC2Init(ADVANCE_TIM, &TIM_OCInitStructure);
TIM_OC3Init(ADVANCE_TIM, &TIM_OCInitStructure);
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
TIM_BDTRInitStructure.TIM_DeadTime = 22; //305ns
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(ADVANCE_TIM, &TIM_BDTRInitStructure);
TIM_Cmd(ADVANCE_TIM, ENABLE);
TIM_CtrlPWMOutputs(ADVANCE_TIM, ENABLE);
}
void ADVANCE_TIM_Config(void)
{
ADVANCE_TIM_GPIO_Config();
ADVANCE_TIM_Mode_Config();
SysTick_Delay_Us( (ADVANCE_TIM_PERIOD+1)/3);
TIM_OC2PreloadConfig(ADVANCE_TIM, TIM_OCPreload_Enable);
SysTick_Delay_Us( (ADVANCE_TIM_PERIOD+1)/3);
TIM_OC3PreloadConfig(ADVANCE_TIM, TIM_OCPreload_Enable);
}
以上代码是通过例程修改而来,现在想把三个通道分别延时三分之一同期再输出,通过延时三分之一周期再使能通道2,再延时三分之一周期使能通道3,不知道这方法行不行。我没示波器也不知道有没有延时输出。 |