在我没有修改这个函数的时候,软件仿真是正常的,出现了四个不同的PWM方波,但是,我也只是修改了一下注释,调了一下语句的顺序,程序没有错,但是,没有方波出现了,怎么回事啊??
下面是我修改后的程序段:
/*
* º¯ÊýÃû£ºTIM3_Mode_Config
* ÃèÊö £ºÅäÖÃTIM3Êä³öµ&AumlWMÐźŵÄģʽ£¬ÈçÖÜÆÚ¡¢¼«ÐÔ¡¢Õ¼¿Õ±È
* ÊäÈë £ºÎÞ
* Êä³ö £ºÎÞ
* µ÷Óà £ºÄÚ²¿µ÷ÓÃ
*/
static void TIM3_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
/* PWMÐźŵçƽÌø±äÖµ */
u16 CCR1_Val = 500;
u16 CCR2_Val = 375;
u16 CCR3_Val = 250;
u16 CCR4_Val = 125;
/* -----------------------------------------------------------------------
TIM3 Configuration: generate 4 PWM signals with 4 different duty cycles:
TIM3CLK = 72 MHz, Prescaler = 0x0, TIM3 counter clock = 72 MHz
TIM3 ARR Register = 999 => TIM3 Frequency = TIM3 counter clock/(ARR + 1)
TIM3 Frequency = 72 KHz.
TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR)* 100 = 50%
TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR)* 100 = 37.5%
TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR)* 100 = 25%
TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR)* 100 = 12.5%
----------------------------------------------------------------------- */
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 999; //µ±¶¨Ê±Æ÷´Ó0¼ÆÊýµ½999£¬¼´Îª1000´Î£¬ÎªÒ»¸ö¶¨Ê±ÖÜÆÚ
TIM_TimeBaseStructure.TIM_Prescaler = 0; //ÉèÖÃÔ¤·ÖƵ£º²»Ô¤·ÖƵ£¬¼´Îª72MHz
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ; //ÉèÖÃʱÖÓ·ÖƵϵÊý£º²»·ÖƵ
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòÉϼÆÊýģʽ
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);//³õʼ»¯TIMxµÄʱ¼ä»ùÊýµ¥Î»
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //ÅäÖÃÎ&ordfWMģʽ1£¨È«²¿Í¨µÀ¶¼ÓÐÊ¡ÂÔдÁË£©
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //Êä³ö¼«ÐÔ ¸ß£¨È«²¿Í¨µÀ¶¼ÓÐÊ¡ÂÔдÁË£©
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //ÓÃÓÚÑ¡ÔñÊä³ö±È½Ï״̬ʹÄÜ
TIM_OCInitStructure.TIM_Pulse = CCR1_Val; //Ìø±äÖµ
TIM_OC1Init(TIM3, &TIM_OCInitStructure);//³õʼ»¯Í¨µÀ1
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);//ʹÄÜԤװÔؼĴæÆ÷£¨OC1£©
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//ÓÃÓÚÑ¡ÔñÊä³ö±È½Ï״̬ʹÄÜ
TIM_OCInitStructure.TIM_Pulse = CCR2_Val;//Ìø±äÖµ
TIM_OC2Init(TIM3, &TIM_OCInitStructure);//³õʼ»¯Í¨µÀ2
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);//ʹÄÜԤװÔؼĴæÆ÷£¨OC2£©
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//ÓÃÓÚÑ¡ÔñÊä³ö±È½Ï״̬ʹÄÜ
TIM_OCInitStructure.TIM_Pulse = CCR3_Val; //Ìø±äÖµ
TIM_OC3Init(TIM3, &TIM_OCInitStructure);//³õʼ»¯Í¨µÀ3
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);//ʹÄÜԤװÔؼĴæÆ÷£¨OC3£©
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//ÓÃÓÚÑ¡ÔñÊä³ö±È½Ï״̬ʹÄÜ
TIM_OCInitStructure.TIM_Pulse = CCR4_Val; //Ìø±äÖµ
TIM_OC4Init(TIM3, &TIM_OCInitStructure);//³õʼ»¯Í¨µÀ4
TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable);//ʹÄÜԤװÔؼĴæÆ÷£¨OC4£©
TIM_ARRPreloadConfig(TIM3, ENABLE); //ʹÄÜTIMxÔÚARRÉϵÄԤװÔؼĴæÆ÷
} |