stm8l15x TIM3 PWM配置

	
	CLK_PeripheralClockConfig(CLK_Peripheral_TIM3, ENABLE);
/*
		set SB_TX_LOCK mode:
		PWM mode,T = 60us, 
		Duty Ratio: 3/4  represents  send bit 1
								1/2  represents  send bit 0
								1/4  represents  a  respond
        TIM3_Prescaler_16,and T = 60;						
	*/
	GPIO_Init(SB_TX_LOCK_PORT,SB_TX_LOCK_PIN,GPIO_Mode_Out_PP_High_Fast);
	
	TIM3_DeInit();
	
#if (SYS_CLOCK_16M)
	TIM3_TimeBaseInit(TIM3_Prescaler_16, TIM3_CounterMode_Up,PWM_T); 
#endif
#if (SYS_CLOCK_8M)
	TIM3_TimeBaseInit(TIM3_Prescaler_8, TIM3_CounterMode_Up,PWM_T); 
#endif
#if (SYS_CLOCK_4M)
	TIM3_TimeBaseInit(TIM3_Prescaler_4, TIM3_CounterMode_Up,PWM_T); 
#endif

  /* PWM1 Mode configuration: Channel1 default Duty Ratio is 1/2 */ 
  TIM3_OC1Init(TIM3_OCMode_PWM1, TIM3_OutputState_Enable,PWM_T/2,TIM3_OCPolarity_High,TIM3_OCIdleState_Set);
  TIM3_OC1PreloadConfig(ENABLE);
	TIM3_ARRPreloadConfig(ENABLE);
	TIM3_ITConfig(TIM3_IT_Update,ENABLE);
	/*enable PWM output*/
	TIM3_CtrlPWMOutputs(ENABLE);   
  /* TIM3 enable counter */
	TIM3_Cmd(ENABLE);
该代码已经测试通过。占空比是50%,周期是PWM_T.

你可能感兴趣的:(stm8l15xx)