/******************************************************************************
;  *   	@MCU				 : MC51F003A4
;  *   	@Create Date         : 2021.10.11
;  *   	@Author/Corporation  : Martin/SinoMCU
;  *   	@晟矽微技术支持QQ 	 : 2048615934
;  *    @晟矽微官网		     : http://www.sinomcu.com/
;  *   	@Copyright           : 2020 SINOMCU Corporation,All Rights Reserved.
;  *----------------------Abstract Description---------------------------------
;  *			          PWM1设置                              		
******************************************************************************/

#include "PWM1.h"

/************************************************
;  *    @Function Name       : PWM1_User_Init
;  *    @Description         : PWM1设置
;  *    @IN_Parameter      	 :
;  *    @Return parameter    :
;  ***********************************************/
void PWM1_User_Init(void)
{
    PWM1_InitTypeDef PWM1_initstructure;

    PWM1_T_Set(1000 - 1); //T=(p+1)/Fsys ((999+1)/(16M/16))=0.001us=1ms
    PWM1_D0_Set(600 - 1);
    //	PWM1_D1_Set(500 - 1);		//互补模式此通道设置无效
    PWM1_D2_Set(500 - 1);
    //	PWM1_D3_Set(500 - 1);		//互补模式此通道设置无效
    PWM1_D4_Set(400 - 1);
    //	PWM1_D5_Set(500 - 1);		//互补模式此通道设置无效

    PWM1_initstructure.PWM1_FB_polarity = PWM1_FB_POL_DOWN;                                                              //刹车下降沿
    PWM1_initstructure.PWM1_FB_OE = PWM1_FB_OE_ENABLE;                                                                   //刹车IO使能
    PWM1_initstructure.PWM1_out_cmp_chx = PWM1_OUT_CMP_ALL;                                                              //全部使能输出
    PWM1_initstructure.PWM1_clock_source = PWM1_CLK_FSYS;                                                                //时钟源系统时钟
    PWM1_initstructure.PWM1_mode = PWM1_MODE_COMPLEMENTARY_01 | PWM1_MODE_COMPLEMENTARY_23 | PWM1_MODE_COMPLEMENTARY_45; //互补模式
    PWM1_initstructure.PWM1_clock_division = PWM1_CLK_DIV_16;                                                            //时钟分频
    PWM1_initstructure.PWM1_auto_load = PWM1_AUTO_LOAD_ENABLE;                                                           //自动重载
    PWM1_initstructure.PWM1_deat_oe = PWM1_DEAT_OE_ENABLE_01 | PWM1_DEAT_OE_ENABLE_23 | PWM1_DEAT_OE_ENABLE_45;          //死区使能
    PWM1_initstructure.PWM1_polarity = PWM1_POL_HIGH_01 | PWM1_POL_HIGH_23 | PWM1_POL_HIGH_45;                           //极性高
    PWM1_initstructure.PWM1_interrupt = ENABLE;                                                                          //使能PWM中断
    PWM1_initstructure.PWM1_interrupt_priority = LOW;                                                                    //中断优先级低
    PWM1_initstructure.PWM1_FB_interrupt = ENABLE;                                                                       //使能刹车中断
    PWM1_initstructure.PWM1_FB_interrupt_priority = HIGH;                                                                //中断优先级低

    PWM1_Init(&PWM1_initstructure);

    PWM1_Deat_Time01_Set(30);
    PWM1_Deat_Time23_Set(20);
    PWM1_Deat_Time45_Set(10);
}

/**************************** end of file *********************************************/
