TIM1_TimeBaseStructure.TIM_Prescaler =71;
TIM1_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM1_TimeBaseStructure.TIM_Period = 1999;
TIM1_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM1_TimeBaseStructure.TIM_RepetitionCounter = 0x0;
TIM_TimeBaseInit(TIM1,&TIM1_TimeBaseStructure);
/* Channel 1, 2,3 and 4 Configuration in PWM mode */
TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM1_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM1_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM1_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM1_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM1_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM1_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM1_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM1,&TIM1_OCInitStructure);
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM1_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM1_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM1_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
TIM1_BDTRInitStructure.TIM_DeadTime = 0x75;
TIM1_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
TIM1_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM1_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM1,&TIM1_BDTRInitStructure);
/* TIM1 counter enable */
TIM_Cmd(TIM1,DISABLE);
/* Main Output Enable */
TIM_CtrlPWMOutputs(TIM1,DISABLE);
TIM_ARRPreloadConfig(TIM1, ENABLE);
while(1)
{
TIM_Cmd(TIM1,DISABLE);
CCR1_Val=VAL[0];
TIM1_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OC1Init(TIM1,&TIM1_OCInitStructure);
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
Delay(2);
TIM_Cmd(TIM1,DISABLE);
CCR1_Val=VAL[1];
TIM1_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OC1Init(TIM1,&TIM1_OCInitStructure);
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
Delay(2);
TIM_Cmd(TIM1,DISABLE);
CCR1_Val=VAL[2];
TIM1_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OC1Init(TIM1,&TIM1_OCInitStructure);
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
Delay(2);
TIM_Cmd(TIM1,DISABLE);
CCR1_Val=VAL[3];
TIM1_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OC1Init(TIM1,&TIM1_OCInitStructure);
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
Delay(2);
TIM_Cmd(TIM1,DISABLE);
CCR1_Val=VAL[4];
TIM1_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OC1Init(TIM1,&TIM1_OCInitStructure);
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
Delay(2);
TIM_Cmd(TIM1,DISABLE);
}
u16 VAL[5]={500,800,1000,1500,1600}; |