微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > PIC关于占空比的疑问

PIC关于占空比的疑问

时间:10-02 整理:3721RD 点击:
关于以下代码中  PDC1 = PHASE1 / 2;        // Initialize as 0 voltage  应该是50%占空比  为什么注释中注释的是0%占空比0V电压?是我理解错了?

/*********************************************************************
  Function:        void InitMCPWM(void)
  PreCondition:    None.
  Input:           None.
  Output:          None.
  Side Effects:    None.
  Overview:        InitMCPWM, intializes the PWM as follows:
                   1. FPWM = 20000 hz
                   2. Complementary PWMs with center aligned
                   3. Set Duty Cycle to 0 for complementary, which is half
                      the period
                   4. Set ADC to be triggered by PWM special trigger
                   5. Configure deadtime to be 2 us       
  Note:            None.
********************************************************************/
void InitMCPWM(void)
{
        PHASE1 = (FCY/FPWM - 1);
        PHASE2 = (FCY/FPWM - 1);
        PHASE3 = (FCY/FPWM - 1);
        IOCON1 = 0;
        IOCON2 = 0;
        IOCON3 = 0;
        DTR1 = 0x0000;        // 2 us of dead time
        DTR2 = 0x0000;        // 2 us of dead time
        DTR3 = 0x0000;        // 2 us of dead time
        ALTDTR1 = 2*ALTDTR_div2;        // 2 us of dead time               
        ALTDTR2 = 2*ALTDTR_div2;        // 2 us of dead time
        ALTDTR3 = 2*ALTDTR_div2;        // 2 us of dead time
        //Note: ALTDTR_div2 define in svm.c should be half of ALTDTRx

        PTCON2 = 0x0000;        // Divide by 1 to generate PWM
        PWMCON1 = 0x0604;        // Enable PWM output pins and configure them as
        PWMCON2 = 0x0204;        // complementary mode
        PWMCON3 = 0x0204;
        PDC1 = PHASE1 / 2;        // Initialize as 0 voltage
        PDC2 = PHASE2 / 2;        // Initialize as 0 voltage
        PDC3 = PHASE3 / 2;        // Initialize as 0 voltage
        SEVTCMP = 1;            // Enable triggering for ADC
       
        //fault enabled       
        FCLCON1 = 0x0005;
        FCLCON2 = 0x0005;
        FCLCON3 = 0x0005;
       
        PTCON = 0x8000;                // start PWM
        return;                                 
}

这是一段PWM初始化程序吧,不是控制程序

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top