TI中文支持网
TI专业的中文技术问题搜集分享网站

TMS320F28069的HRPWM的产生

我用TI自带的28069的HRPWM的例程,发现端口没有脉冲产生,我仔细核对了一下TI提供的SPRUH18D(讲诉3HRPWM的技术文档)中给的关于HRPWM的说明与例子,发现对HRPWM的初始化都是相同的,现在一直没找到原因在哪里,求助啊啊?????????????现在把程序贴出来,供各位解读!

#include "F2806x_Device.h"         // F2806x Headerfile

 #include "F2806x_Examples.h"       // F2806x Examples Headerfile

#include "F2806x_EPwm_defines.h"   // useful defines for initialization

void HRPWM1_Config(int);

void HRPWM2_Config(int);

void HRPWM3_Config(int);

void HRPWM4_Config(int);

Uint16 i,j, DutyFine, PeriodFine ,n,update;

Uint32 temp;

void main(void)

 {

      InitSysCtrl();

      InitEPwm1Gpio();   

     InitEPwm2Gpio();   

     InitEPwm3Gpio();   

     InitEPwm4Gpio();

     DINT;

     InitPieCtrl();

     IER = 0x0000;   

     IFR = 0x0000;

    InitPieVectTable();

     update =1;    DutyFine =0;    PeriodFine =0;   

     EALLOW;   

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;   

    EDIS;

    HRPWM1_Config(10);     // ePWM1 target, Period = 10   

    HRPWM2_Config(20);     // ePWM2 target, Period = 20   

    HRPWM3_Config(10);     // ePWM3 target, Period = 10   

    HRPWM4_Config(20);     // ePWM4 target, Period = 20

     EALLOW;   

     EPwm1Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm1 period  

     EPwm2Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm2 period  

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;     //Enable TBCLKSYNC   

      EDIS;  

    while (update ==1)  //测试微调HRPWM的占空比,精度可以达到0.02%

   {

        for(DutyFine =1; DutyFine <256 ;DutyFine ++)          {

        // Example, write to the HRPWM extension of CMPA       

        EPwm1Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits        

       EPwm2Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits

        // Example, 32-bit write to CMPA:CMPAHR      

       EPwm3Regs.CMPA.all = ((Uint32)EPwm3Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);        

       EPwm4Regs.CMPA.all = ((Uint32)EPwm4Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);

       for (i=0;i<10000;i++){}                         // Dummy delay between MEP changes   

       }

 }

void HRPWM1_Config(period)

{

    EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;         // set Immediate load,立即装载TBPRD寄存器的值  

    EPwm1Regs.TBPRD = period-1;                      // PWM frequency = 1 / period  设置周期值  

    EPwm1Regs.CMPA.half.CMPA = period / 2;              // set duty 50% initially,设置占空比    

    EPwm1Regs.CMPA.half.CMPAHR = (1 << 8);              // initialize HRPWM extension  EPwm1Regs.CMPB = period / 2;                     // set duty 50% initially   

    EPwm1Regs.TBPHS.all = 0;  EPwm1Regs.TBCTR = 0;

     EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;   //向上计数方式

     EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;          // EPwm1 is the Master

     EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;  //disable EPWMxSYNCO signal

     EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;   //TBCLK的时钟等于系统时钟 

     EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

      EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;  

      EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

      EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;

      EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;

       EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;               // PWM toggle low/high

       EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

       EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET;

       EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;

       EALLOW;  EPwm1Regs.HRCNFG.all = 0x0;

       EPwm1Regs.HRCNFG.bit.EDGMODE = HR_REP;    //MEP control on Rising edge  

      EPwm1Regs.HRCNFG.bit.CTLMODE = HR_CMP;    //选择CMPAHR寄存器和TBPRDHR寄存器控制 the edge position  

      EPwm1Regs.HRCNFG.bit.HRLOAD  = HR_CTR_ZERO;

       EDIS;

}

其他的HRPWM的配置都是和HRPWM1的配置相同,这里把void InitEPwm1Gpio(void)的代码页贴出来:

void InitEPwm1Gpio(void)

 {   

       EALLOW;

       GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;    // Disable pull-up on GPIO0 (EPWM1A)    

       GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;

       GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;   // Configure GPIO0 as EPWM1A   

       GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;   // Configure GPIO1 as EPWM1B    

       GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;

      EDIS;

}

请各位帮忙找找问题在哪,在GPIO0管脚始终没有PWM脉冲,GPIO1和其他的都没有!我通过延时程序可以在GPIO0处产生PWM波,硬件上应该没有什么问题,不知道是不是哪里设置有问题!

 

10#:

rong zou

通过延时程序可以在GPIO0处产生PWM波,硬件上应该没有什么问题

这是在哪里如何延时处理的?仍然是PWM功能,还是通过GPIO功能?

另外,你这个程序看上去好像不是例程,而是经过你的修改,有试过直接调用TI的例程吗?

如果不使能高精度,正常的ePWM能输出吗?

我怀疑ePWM的时钟是否有打开。。。

我用TI自带的28069的HRPWM的例程,发现端口没有脉冲产生,我仔细核对了一下TI提供的SPRUH18D(讲诉3HRPWM的技术文档)中给的关于HRPWM的说明与例子,发现对HRPWM的初始化都是相同的,现在一直没找到原因在哪里,求助啊啊?????????????现在把程序贴出来,供各位解读!

#include "F2806x_Device.h"         // F2806x Headerfile

 #include "F2806x_Examples.h"       // F2806x Examples Headerfile

#include "F2806x_EPwm_defines.h"   // useful defines for initialization

void HRPWM1_Config(int);

void HRPWM2_Config(int);

void HRPWM3_Config(int);

void HRPWM4_Config(int);

Uint16 i,j, DutyFine, PeriodFine ,n,update;

Uint32 temp;

void main(void)

 {

      InitSysCtrl();

      InitEPwm1Gpio();   

     InitEPwm2Gpio();   

     InitEPwm3Gpio();   

     InitEPwm4Gpio();

     DINT;

     InitPieCtrl();

     IER = 0x0000;   

     IFR = 0x0000;

    InitPieVectTable();

     update =1;    DutyFine =0;    PeriodFine =0;   

     EALLOW;   

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;   

    EDIS;

    HRPWM1_Config(10);     // ePWM1 target, Period = 10   

    HRPWM2_Config(20);     // ePWM2 target, Period = 20   

    HRPWM3_Config(10);     // ePWM3 target, Period = 10   

    HRPWM4_Config(20);     // ePWM4 target, Period = 20

     EALLOW;   

     EPwm1Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm1 period  

     EPwm2Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm2 period  

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;     //Enable TBCLKSYNC   

      EDIS;  

    while (update ==1)  //测试微调HRPWM的占空比,精度可以达到0.02%

   {

        for(DutyFine =1; DutyFine <256 ;DutyFine ++)          {

        // Example, write to the HRPWM extension of CMPA       

        EPwm1Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits        

       EPwm2Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits

        // Example, 32-bit write to CMPA:CMPAHR      

       EPwm3Regs.CMPA.all = ((Uint32)EPwm3Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);        

       EPwm4Regs.CMPA.all = ((Uint32)EPwm4Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);

       for (i=0;i<10000;i++){}                         // Dummy delay between MEP changes   

       }

 }

void HRPWM1_Config(period)

{

    EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;         // set Immediate load,立即装载TBPRD寄存器的值  

    EPwm1Regs.TBPRD = period-1;                      // PWM frequency = 1 / period  设置周期值  

    EPwm1Regs.CMPA.half.CMPA = period / 2;              // set duty 50% initially,设置占空比    

    EPwm1Regs.CMPA.half.CMPAHR = (1 << 8);              // initialize HRPWM extension  EPwm1Regs.CMPB = period / 2;                     // set duty 50% initially   

    EPwm1Regs.TBPHS.all = 0;  EPwm1Regs.TBCTR = 0;

     EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;   //向上计数方式

     EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;          // EPwm1 is the Master

     EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;  //disable EPWMxSYNCO signal

     EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;   //TBCLK的时钟等于系统时钟 

     EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

      EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;  

      EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

      EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;

      EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;

       EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;               // PWM toggle low/high

       EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

       EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET;

       EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;

       EALLOW;  EPwm1Regs.HRCNFG.all = 0x0;

       EPwm1Regs.HRCNFG.bit.EDGMODE = HR_REP;    //MEP control on Rising edge  

      EPwm1Regs.HRCNFG.bit.CTLMODE = HR_CMP;    //选择CMPAHR寄存器和TBPRDHR寄存器控制 the edge position  

      EPwm1Regs.HRCNFG.bit.HRLOAD  = HR_CTR_ZERO;

       EDIS;

}

其他的HRPWM的配置都是和HRPWM1的配置相同,这里把void InitEPwm1Gpio(void)的代码页贴出来:

void InitEPwm1Gpio(void)

 {   

       EALLOW;

       GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;    // Disable pull-up on GPIO0 (EPWM1A)    

       GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;

       GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;   // Configure GPIO0 as EPWM1A   

       GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;   // Configure GPIO1 as EPWM1B    

       GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;

      EDIS;

}

请各位帮忙找找问题在哪,在GPIO0管脚始终没有PWM脉冲,GPIO1和其他的都没有!我通过延时程序可以在GPIO0处产生PWM波,硬件上应该没有什么问题,不知道是不是哪里设置有问题!

 

rong zou:

回复 10#:

我提到的可以在GPIO0处产生PWM是将其设置成IO端口,利用延时让其端口电平翻转产生PWM,而不是用利用特殊功能产生的!时钟是设置好了的!在InitSysCtrl()函数里面, 这个函数里面主要是IntOsc1Sel()和InitPll(DSP28_PLLCR,DSP28_DIVSEL)以及InitPeripheralClocks()函数来设置时钟的,采用的是internal oscillator 1,频率为10MHZ,程序如下:

 void IntOsc1Sel (void)

{

      EALLOW;

      SysCtrlRegs.CLKCTL.bit.INTOSC1OFF = 0;

      SysCtrlRegs.CLKCTL.bit.OSCCLKSRCSEL=0; // Clk Src = INTOSC1

      SysCtrlRegs.CLKCTL.bit.XCLKINOFF=1; // Turn off XCLKIN

      SysCtrlRegs.CLKCTL.bit.XTALOSCOFF=1; // Turn off XTALOSC

      SysCtrlRegs.CLKCTL.bit.INTOSC2OFF=1; // Turn off INTOSC2

      EDIS;

}

 然后通过InitPll(DSP28_PLLCR,DSP28_DIVSEL)函数将系统时钟设置为80MHZ,而InitPeripheralClocks()函数就是设置外设时钟的,程序如下:

void InitPeripheralClocks(void)

{

     EALLOW; // LOSPCP prescale register settings, normally it will be set to default values

     GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 3; // GPIO18 = XCLKOUT

     SysCtrlRegs.LOSPCP.all = 0x0002; // XCLKOUT to SYSCLKOUT ratio. By default XCLKOUT = 1/4 SYSCLKOUT

     SysCtrlRegs.XCLK.bit.XCLKOUTDIV=2; //对系统时钟进行四分频 

     SysCtrlRegs.PCLKCR1.bit.EPWM1ENCLK = 1; // ePWM1

     SysCtrlRegs.PCLKCR1.bit.EPWM2ENCLK = 1; // ePWM2

     SysCtrlRegs.PCLKCR1.bit.EPWM3ENCLK = 1; // ePWM3

     SysCtrlRegs.PCLKCR1.bit.EPWM4ENCLK = 1; // ePWM4

     SysCtrlRegs.PCLKCR1.bit.EPWM5ENCLK = 1; // ePWM5

     SysCtrlRegs.PCLKCR1.bit.EPWM6ENCLK = 1; // ePWM6

     SysCtrlRegs.PCLKCR1.bit.EPWM7ENCLK = 1; // ePWM7

     SysCtrlRegs.PCLKCR1.bit.EPWM8ENCLK = 1; // ePWM8

     SysCtrlRegs.PCLKCR0.bit.HRPWMENCLK = 1; // HRPWM

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Enable TBCLK within the ePWM

     SysCtrlRegs.PCLKCR1.bit.EQEP1ENCLK = 1; // eQEP1

     SysCtrlRegs.PCLKCR1.bit.EQEP2ENCLK = 1; // eQEP2

     SysCtrlRegs.PCLKCR1.bit.ECAP1ENCLK = 1; // eCAP1

    SysCtrlRegs.PCLKCR1.bit.ECAP2ENCLK = 1; // eCAP2

    SysCtrlRegs.PCLKCR1.bit.ECAP3ENCLK = 1; // eCAP3

    SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; // ADC

    SysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1; // COMP1

    SysCtrlRegs.PCLKCR3.bit.COMP2ENCLK = 1; // COMP2

    SysCtrlRegs.PCLKCR3.bit.COMP3ENCLK = 1; // COMP3

    SysCtrlRegs.PCLKCR3.bit.CPUTIMER0ENCLK = 1; // CPU Timer 0

    SysCtrlRegs.PCLKCR3.bit.CPUTIMER1ENCLK = 1; // CPU Timer 1

    SysCtrlRegs.PCLKCR3.bit.CPUTIMER2ENCLK = 1; // CPU Timer 2

    SysCtrlRegs.PCLKCR3.bit.DMAENCLK = 1; // DMA

    SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1; // GPIO input clock

     SysCtrlRegs.PCLKCR3.bit.CLA1ENCLK = 1; // CLA1

     SysCtrlRegs.PCLKCR0.bit.I2CAENCLK = 1; // I2C

     SysCtrlRegs.PCLKCR0.bit.SPIAENCLK = 1; // SPI-A

     SysCtrlRegs.PCLKCR0.bit.SPIBENCLK = 1; // SPI-B

     SysCtrlRegs.PCLKCR0.bit.SCIAENCLK = 1; // SCI-A

     SysCtrlRegs.PCLKCR0.bit.SCIBENCLK = 1; // SCI-B

     SysCtrlRegs.PCLKCR0.bit.MCBSPAENCLK=1; // McBSP-A

     SysCtrlRegs.PCLKCR0.bit.ECANAENCLK=1; // eCAN-A

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Enable TBCLK within the ePWM

     EDIS; 

}

 这里面就有使能EPWM的时钟和HRPWM的时钟设置啊!我在想是不是和SF0_V6.h和SFO_TI_Build_V6b.lib有关,因为这个HRPWM的产生与MEP_ScaleFactor有关,我看TI提供的文档说,这个设置TI提供了SF0_V6.h和SFO_TI_Build_V6b.lib来帮助用户自动完成设置,但是我不知道这个在主程序里还有如何设置啊,我只是把这两个文件添加到了工程当中,并没有在主函数里进行其他的任何操作!

我用TI自带的28069的HRPWM的例程,发现端口没有脉冲产生,我仔细核对了一下TI提供的SPRUH18D(讲诉3HRPWM的技术文档)中给的关于HRPWM的说明与例子,发现对HRPWM的初始化都是相同的,现在一直没找到原因在哪里,求助啊啊?????????????现在把程序贴出来,供各位解读!

#include "F2806x_Device.h"         // F2806x Headerfile

 #include "F2806x_Examples.h"       // F2806x Examples Headerfile

#include "F2806x_EPwm_defines.h"   // useful defines for initialization

void HRPWM1_Config(int);

void HRPWM2_Config(int);

void HRPWM3_Config(int);

void HRPWM4_Config(int);

Uint16 i,j, DutyFine, PeriodFine ,n,update;

Uint32 temp;

void main(void)

 {

      InitSysCtrl();

      InitEPwm1Gpio();   

     InitEPwm2Gpio();   

     InitEPwm3Gpio();   

     InitEPwm4Gpio();

     DINT;

     InitPieCtrl();

     IER = 0x0000;   

     IFR = 0x0000;

    InitPieVectTable();

     update =1;    DutyFine =0;    PeriodFine =0;   

     EALLOW;   

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;   

    EDIS;

    HRPWM1_Config(10);     // ePWM1 target, Period = 10   

    HRPWM2_Config(20);     // ePWM2 target, Period = 20   

    HRPWM3_Config(10);     // ePWM3 target, Period = 10   

    HRPWM4_Config(20);     // ePWM4 target, Period = 20

     EALLOW;   

     EPwm1Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm1 period  

     EPwm2Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm2 period  

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;     //Enable TBCLKSYNC   

      EDIS;  

    while (update ==1)  //测试微调HRPWM的占空比,精度可以达到0.02%

   {

        for(DutyFine =1; DutyFine <256 ;DutyFine ++)          {

        // Example, write to the HRPWM extension of CMPA       

        EPwm1Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits        

       EPwm2Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits

        // Example, 32-bit write to CMPA:CMPAHR      

       EPwm3Regs.CMPA.all = ((Uint32)EPwm3Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);        

       EPwm4Regs.CMPA.all = ((Uint32)EPwm4Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);

       for (i=0;i<10000;i++){}                         // Dummy delay between MEP changes   

       }

 }

void HRPWM1_Config(period)

{

    EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;         // set Immediate load,立即装载TBPRD寄存器的值  

    EPwm1Regs.TBPRD = period-1;                      // PWM frequency = 1 / period  设置周期值  

    EPwm1Regs.CMPA.half.CMPA = period / 2;              // set duty 50% initially,设置占空比    

    EPwm1Regs.CMPA.half.CMPAHR = (1 << 8);              // initialize HRPWM extension  EPwm1Regs.CMPB = period / 2;                     // set duty 50% initially   

    EPwm1Regs.TBPHS.all = 0;  EPwm1Regs.TBCTR = 0;

     EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;   //向上计数方式

     EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;          // EPwm1 is the Master

     EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;  //disable EPWMxSYNCO signal

     EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;   //TBCLK的时钟等于系统时钟 

     EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

      EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;  

      EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

      EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;

      EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;

       EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;               // PWM toggle low/high

       EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

       EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET;

       EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;

       EALLOW;  EPwm1Regs.HRCNFG.all = 0x0;

       EPwm1Regs.HRCNFG.bit.EDGMODE = HR_REP;    //MEP control on Rising edge  

      EPwm1Regs.HRCNFG.bit.CTLMODE = HR_CMP;    //选择CMPAHR寄存器和TBPRDHR寄存器控制 the edge position  

      EPwm1Regs.HRCNFG.bit.HRLOAD  = HR_CTR_ZERO;

       EDIS;

}

其他的HRPWM的配置都是和HRPWM1的配置相同,这里把void InitEPwm1Gpio(void)的代码页贴出来:

void InitEPwm1Gpio(void)

 {   

       EALLOW;

       GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;    // Disable pull-up on GPIO0 (EPWM1A)    

       GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;

       GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;   // Configure GPIO0 as EPWM1A   

       GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;   // Configure GPIO1 as EPWM1B    

       GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;

      EDIS;

}

请各位帮忙找找问题在哪,在GPIO0管脚始终没有PWM脉冲,GPIO1和其他的都没有!我通过延时程序可以在GPIO0处产生PWM波,硬件上应该没有什么问题,不知道是不是哪里设置有问题!

 

10#:

上面建议如果不使能高精度,正常的ePWM能输出吗?有测试过吗?

如果把下面两句话注释掉呢?为什么单独拿出来而未放在ePWM初始化里?有了解高精度周期模式有什么特别注意事项呢?

对比4.2.3.4.1 High-Resolution Period Configuration检查一下看看?

EPwm1Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm1 period  

EPwm2Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm2 period  

如果仍有问题,看看ePWM的计数器是否正常在计数,还有你自己提到的两个库文件可以先删除。

我用TI自带的28069的HRPWM的例程,发现端口没有脉冲产生,我仔细核对了一下TI提供的SPRUH18D(讲诉3HRPWM的技术文档)中给的关于HRPWM的说明与例子,发现对HRPWM的初始化都是相同的,现在一直没找到原因在哪里,求助啊啊?????????????现在把程序贴出来,供各位解读!

#include "F2806x_Device.h"         // F2806x Headerfile

 #include "F2806x_Examples.h"       // F2806x Examples Headerfile

#include "F2806x_EPwm_defines.h"   // useful defines for initialization

void HRPWM1_Config(int);

void HRPWM2_Config(int);

void HRPWM3_Config(int);

void HRPWM4_Config(int);

Uint16 i,j, DutyFine, PeriodFine ,n,update;

Uint32 temp;

void main(void)

 {

      InitSysCtrl();

      InitEPwm1Gpio();   

     InitEPwm2Gpio();   

     InitEPwm3Gpio();   

     InitEPwm4Gpio();

     DINT;

     InitPieCtrl();

     IER = 0x0000;   

     IFR = 0x0000;

    InitPieVectTable();

     update =1;    DutyFine =0;    PeriodFine =0;   

     EALLOW;   

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;   

    EDIS;

    HRPWM1_Config(10);     // ePWM1 target, Period = 10   

    HRPWM2_Config(20);     // ePWM2 target, Period = 20   

    HRPWM3_Config(10);     // ePWM3 target, Period = 10   

    HRPWM4_Config(20);     // ePWM4 target, Period = 20

     EALLOW;   

     EPwm1Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm1 period  

     EPwm2Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm2 period  

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;     //Enable TBCLKSYNC   

      EDIS;  

    while (update ==1)  //测试微调HRPWM的占空比,精度可以达到0.02%

   {

        for(DutyFine =1; DutyFine <256 ;DutyFine ++)          {

        // Example, write to the HRPWM extension of CMPA       

        EPwm1Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits        

       EPwm2Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits

        // Example, 32-bit write to CMPA:CMPAHR      

       EPwm3Regs.CMPA.all = ((Uint32)EPwm3Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);        

       EPwm4Regs.CMPA.all = ((Uint32)EPwm4Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);

       for (i=0;i<10000;i++){}                         // Dummy delay between MEP changes   

       }

 }

void HRPWM1_Config(period)

{

    EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;         // set Immediate load,立即装载TBPRD寄存器的值  

    EPwm1Regs.TBPRD = period-1;                      // PWM frequency = 1 / period  设置周期值  

    EPwm1Regs.CMPA.half.CMPA = period / 2;              // set duty 50% initially,设置占空比    

    EPwm1Regs.CMPA.half.CMPAHR = (1 << 8);              // initialize HRPWM extension  EPwm1Regs.CMPB = period / 2;                     // set duty 50% initially   

    EPwm1Regs.TBPHS.all = 0;  EPwm1Regs.TBCTR = 0;

     EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;   //向上计数方式

     EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;          // EPwm1 is the Master

     EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;  //disable EPWMxSYNCO signal

     EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;   //TBCLK的时钟等于系统时钟 

     EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

      EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;  

      EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

      EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;

      EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;

       EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;               // PWM toggle low/high

       EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

       EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET;

       EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;

       EALLOW;  EPwm1Regs.HRCNFG.all = 0x0;

       EPwm1Regs.HRCNFG.bit.EDGMODE = HR_REP;    //MEP control on Rising edge  

      EPwm1Regs.HRCNFG.bit.CTLMODE = HR_CMP;    //选择CMPAHR寄存器和TBPRDHR寄存器控制 the edge position  

      EPwm1Regs.HRCNFG.bit.HRLOAD  = HR_CTR_ZERO;

       EDIS;

}

其他的HRPWM的配置都是和HRPWM1的配置相同,这里把void InitEPwm1Gpio(void)的代码页贴出来:

void InitEPwm1Gpio(void)

 {   

       EALLOW;

       GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;    // Disable pull-up on GPIO0 (EPWM1A)    

       GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;

       GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;   // Configure GPIO0 as EPWM1A   

       GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;   // Configure GPIO1 as EPWM1B    

       GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;

      EDIS;

}

请各位帮忙找找问题在哪,在GPIO0管脚始终没有PWM脉冲,GPIO1和其他的都没有!我通过延时程序可以在GPIO0处产生PWM波,硬件上应该没有什么问题,不知道是不是哪里设置有问题!

 

rong zou:

回复 10#:

您好!我之前试过了EPWM的功能,EPWM能够正常产生PWM波形!我把

EPwm1Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm1 period 

EPwm2Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm2 period 

这两句注释掉后可以产生HRPWM波形了,但是我不太理解为什么?这个设置是使能高精度时间啊,难道不需要使能吗?有点不解!

我用TI自带的28069的HRPWM的例程,发现端口没有脉冲产生,我仔细核对了一下TI提供的SPRUH18D(讲诉3HRPWM的技术文档)中给的关于HRPWM的说明与例子,发现对HRPWM的初始化都是相同的,现在一直没找到原因在哪里,求助啊啊?????????????现在把程序贴出来,供各位解读!

#include "F2806x_Device.h"         // F2806x Headerfile

 #include "F2806x_Examples.h"       // F2806x Examples Headerfile

#include "F2806x_EPwm_defines.h"   // useful defines for initialization

void HRPWM1_Config(int);

void HRPWM2_Config(int);

void HRPWM3_Config(int);

void HRPWM4_Config(int);

Uint16 i,j, DutyFine, PeriodFine ,n,update;

Uint32 temp;

void main(void)

 {

      InitSysCtrl();

      InitEPwm1Gpio();   

     InitEPwm2Gpio();   

     InitEPwm3Gpio();   

     InitEPwm4Gpio();

     DINT;

     InitPieCtrl();

     IER = 0x0000;   

     IFR = 0x0000;

    InitPieVectTable();

     update =1;    DutyFine =0;    PeriodFine =0;   

     EALLOW;   

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;   

    EDIS;

    HRPWM1_Config(10);     // ePWM1 target, Period = 10   

    HRPWM2_Config(20);     // ePWM2 target, Period = 20   

    HRPWM3_Config(10);     // ePWM3 target, Period = 10   

    HRPWM4_Config(20);     // ePWM4 target, Period = 20

     EALLOW;   

     EPwm1Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm1 period  

     EPwm2Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm2 period  

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;     //Enable TBCLKSYNC   

      EDIS;  

    while (update ==1)  //测试微调HRPWM的占空比,精度可以达到0.02%

   {

        for(DutyFine =1; DutyFine <256 ;DutyFine ++)          {

        // Example, write to the HRPWM extension of CMPA       

        EPwm1Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits        

       EPwm2Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits

        // Example, 32-bit write to CMPA:CMPAHR      

       EPwm3Regs.CMPA.all = ((Uint32)EPwm3Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);        

       EPwm4Regs.CMPA.all = ((Uint32)EPwm4Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);

       for (i=0;i<10000;i++){}                         // Dummy delay between MEP changes   

       }

 }

void HRPWM1_Config(period)

{

    EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;         // set Immediate load,立即装载TBPRD寄存器的值  

    EPwm1Regs.TBPRD = period-1;                      // PWM frequency = 1 / period  设置周期值  

    EPwm1Regs.CMPA.half.CMPA = period / 2;              // set duty 50% initially,设置占空比    

    EPwm1Regs.CMPA.half.CMPAHR = (1 << 8);              // initialize HRPWM extension  EPwm1Regs.CMPB = period / 2;                     // set duty 50% initially   

    EPwm1Regs.TBPHS.all = 0;  EPwm1Regs.TBCTR = 0;

     EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;   //向上计数方式

     EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;          // EPwm1 is the Master

     EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;  //disable EPWMxSYNCO signal

     EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;   //TBCLK的时钟等于系统时钟 

     EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

      EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;  

      EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

      EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;

      EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;

       EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;               // PWM toggle low/high

       EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

       EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET;

       EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;

       EALLOW;  EPwm1Regs.HRCNFG.all = 0x0;

       EPwm1Regs.HRCNFG.bit.EDGMODE = HR_REP;    //MEP control on Rising edge  

      EPwm1Regs.HRCNFG.bit.CTLMODE = HR_CMP;    //选择CMPAHR寄存器和TBPRDHR寄存器控制 the edge position  

      EPwm1Regs.HRCNFG.bit.HRLOAD  = HR_CTR_ZERO;

       EDIS;

}

其他的HRPWM的配置都是和HRPWM1的配置相同,这里把void InitEPwm1Gpio(void)的代码页贴出来:

void InitEPwm1Gpio(void)

 {   

       EALLOW;

       GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;    // Disable pull-up on GPIO0 (EPWM1A)    

       GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;

       GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;   // Configure GPIO0 as EPWM1A   

       GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;   // Configure GPIO1 as EPWM1B    

       GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;

      EDIS;

}

请各位帮忙找找问题在哪,在GPIO0管脚始终没有PWM脉冲,GPIO1和其他的都没有!我通过延时程序可以在GPIO0处产生PWM波,硬件上应该没有什么问题,不知道是不是哪里设置有问题!

 

10#:

回复 10#:

10#

上面建议如果不使能高精度,正常的ePWM能输出吗?有测试过吗?

如果把下面两句话注释掉呢?为什么单独拿出来而未放在ePWM初始化里?有了解高精度周期模式有什么特别注意事项呢?

对比4.2.3.4.1 High-Resolution Period Configuration检查一下看看?

EPwm1Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm1 period  

EPwm2Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm2 period  

如果仍有问题,看看ePWM的计数器是否正常在计数,还有你自己提到的两个库文件可以先删除。

我用TI自带的28069的HRPWM的例程,发现端口没有脉冲产生,我仔细核对了一下TI提供的SPRUH18D(讲诉3HRPWM的技术文档)中给的关于HRPWM的说明与例子,发现对HRPWM的初始化都是相同的,现在一直没找到原因在哪里,求助啊啊?????????????现在把程序贴出来,供各位解读!

#include "F2806x_Device.h"         // F2806x Headerfile

 #include "F2806x_Examples.h"       // F2806x Examples Headerfile

#include "F2806x_EPwm_defines.h"   // useful defines for initialization

void HRPWM1_Config(int);

void HRPWM2_Config(int);

void HRPWM3_Config(int);

void HRPWM4_Config(int);

Uint16 i,j, DutyFine, PeriodFine ,n,update;

Uint32 temp;

void main(void)

 {

      InitSysCtrl();

      InitEPwm1Gpio();   

     InitEPwm2Gpio();   

     InitEPwm3Gpio();   

     InitEPwm4Gpio();

     DINT;

     InitPieCtrl();

     IER = 0x0000;   

     IFR = 0x0000;

    InitPieVectTable();

     update =1;    DutyFine =0;    PeriodFine =0;   

     EALLOW;   

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;   

    EDIS;

    HRPWM1_Config(10);     // ePWM1 target, Period = 10   

    HRPWM2_Config(20);     // ePWM2 target, Period = 20   

    HRPWM3_Config(10);     // ePWM3 target, Period = 10   

    HRPWM4_Config(20);     // ePWM4 target, Period = 20

     EALLOW;   

     EPwm1Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm1 period  

     EPwm2Regs.HRPCTL.bit.HRPE = 1;             //Enable High resolution EPwm2 period  

     SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;     //Enable TBCLKSYNC   

      EDIS;  

    while (update ==1)  //测试微调HRPWM的占空比,精度可以达到0.02%

   {

        for(DutyFine =1; DutyFine <256 ;DutyFine ++)          {

        // Example, write to the HRPWM extension of CMPA       

        EPwm1Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits        

       EPwm2Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits

        // Example, 32-bit write to CMPA:CMPAHR      

       EPwm3Regs.CMPA.all = ((Uint32)EPwm3Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);        

       EPwm4Regs.CMPA.all = ((Uint32)EPwm4Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);

       for (i=0;i<10000;i++){}                         // Dummy delay between MEP changes   

       }

 }

void HRPWM1_Config(period)

{

    EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;         // set Immediate load,立即装载TBPRD寄存器的值  

    EPwm1Regs.TBPRD = period-1;                      // PWM frequency = 1 / period  设置周期值  

    EPwm1Regs.CMPA.half.CMPA = period / 2;              // set duty 50% initially,设置占空比    

    EPwm1Regs.CMPA.half.CMPAHR = (1 << 8);              // initialize HRPWM extension  EPwm1Regs.CMPB = period / 2;                     // set duty 50% initially   

    EPwm1Regs.TBPHS.all = 0;  EPwm1Regs.TBCTR = 0;

     EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;   //向上计数方式

     EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;          // EPwm1 is the Master

     EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;  //disable EPWMxSYNCO signal

     EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;   //TBCLK的时钟等于系统时钟 

     EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

      EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;  

      EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

      EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;

      EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;

       EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;               // PWM toggle low/high

       EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

       EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET;

       EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;

       EALLOW;  EPwm1Regs.HRCNFG.all = 0x0;

       EPwm1Regs.HRCNFG.bit.EDGMODE = HR_REP;    //MEP control on Rising edge  

      EPwm1Regs.HRCNFG.bit.CTLMODE = HR_CMP;    //选择CMPAHR寄存器和TBPRDHR寄存器控制 the edge position  

      EPwm1Regs.HRCNFG.bit.HRLOAD  = HR_CTR_ZERO;

       EDIS;

}

其他的HRPWM的配置都是和HRPWM1的配置相同,这里把void InitEPwm1Gpio(void)的代码页贴出来:

void InitEPwm1Gpio(void)

 {   

       EALLOW;

       GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;    // Disable pull-up on GPIO0 (EPWM1A)    

       GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;

       GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;   // Configure GPIO0 as EPWM1A   

       GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;   // Configure GPIO1 as EPWM1B    

       GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;

      EDIS;

}

请各位帮忙找找问题在哪,在GPIO0管脚始终没有PWM脉冲,GPIO1和其他的都没有!我通过延时程序可以在GPIO0处产生PWM波,硬件上应该没有什么问题,不知道是不是哪里设置有问题!

 

xianhe Zhao:

回复 10#:

您好请问有中文版带有例程的28069手册的说明书么,如果有的话可以发我邮箱么:1060599362@qq.com

赞(0)
未经允许不得转载:TI中文支持网 » TMS320F28069的HRPWM的产生
分享到: 更多 (0)