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

请问在系统时钟60M使用HRPWM的自动转换模式时,调用sfo()函数后遇到返回值一直是2,导致程序陷入死循环无法正常工作怎么回事啊。具体代码如下

1.添加库函数SFO_TI_Build_V6b.lib到工程

2.添加头文件#include“”SFO_V6.h“”

3.在EPWM.c中首先定义MEP_ScaleFactor (按照说明,此变量仅定义,使能自动转换后此变量自动赋值,并最终赋给HRMSTEP寄存器) 和MEP_Status,然后配置PWM

#include "DSP2803x_Device.h"       // DSP2803x Headerfile Include File
#include "DSP2803x_Examples.h"  // DSP2803x Examples Include File
int MEP_ScaleFactor =0;
int MEP_Status;

void InitEPwm(void)
{
   InitEPwm1Gpio(); //具体配置略
   InitEPwm2Gpio();//具体配置略

   InitEPwm1(); //1路未用HRPWM,正常配置无问题
   InitEPwm2(); //2路里配置了HRPWM,函数在下面
//开时钟
   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
   EDIS;
  
   while (MEP_Status != SFO_COMPLETE)//调试发现MEP_Status 一直是2,导致while出不去,窗口中观察EPWM2中的HRMSTEP寄存器也一直是0并未被赋值
    { MEP_Status = SFO(); }
}

//

void InitEPwm2(void) 
{

EALLOW;
//Setup Time-based module
EPwm2Regs.TBPRD = 300; // Set timer period
EPwm2Regs.TBPHS.half.TBPHS = 0; // Phase is T/4
EPwm2Regs.TBCTR = 0x0000; // Clear counter

// Setup TBCLK
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Enable phase loading
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;

EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;

EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;//CC_CTR_PRD;//CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;//CC_CTR_PRD;//CC_CTR_ZERO;

// Setup compare
EPwm2Regs.CMPA.half.CMPA = 1;
EPwm2Regs.CMPB = 299;

// Set actions
EPwm2Regs.AQSFRC.bit.RLDCSF = 0; //load on equals zero
EPwm2Regs.AQSFRC.bit.ACTSFA = AQ_CLEAR;
EPwm2Regs.AQSFRC.bit.ACTSFB = AQ_SET;

EPwm2Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLA.bit.CAD = AQ_NO_ACTION;
EPwm2Regs.AQCTLA.bit.CBU = AQ_NO_ACTION;
EPwm2Regs.AQCTLA.bit.CBD = AQ_CLEAR;

EPwm2Regs.AQCTLB.bit.CAU = AQ_NO_ACTION;
EPwm2Regs.AQCTLB.bit.CAD = AQ_NO_ACTION;
EPwm2Regs.AQCTLB.bit.CBU = AQ_NO_ACTION;
EPwm2Regs.AQCTLB.bit.CBD = AQ_NO_ACTION;

// Active Low PWMs – Setup Deadband
EPwm2Regs.DBCTL.bit.OUT_MODE = 3;
EPwm2Regs.DBCTL.bit.POLSEL = 2; //2
EPwm2Regs.DBCTL.bit.IN_MODE = 0; //2 A for the rising delay,B for the falling
EPwm2Regs.DBRED = 60;
EPwm2Regs.DBFED = 60; //死区时间1.667us

EDIS;
EALLOW;
EPwm2Regs.HRCNFG.all =0x0;
EPwm2Regs.HRCNFG.bit.AUTOCONV =1;
// EPwm1Regs.HRCNFG.bit.HRLOAD =CC_CTR_ZERO;//Selects the time event that loads the CMPAHR shadow value into the active register
EPwm2Regs.HRCNFG.bit.EDGMODE = 3; //both edge;
EPwm2Regs.HRCNFG.bit.CTLMODE = 1;//0:CMPAHR(8) or TBPRDHR(8) 1:TBPHSHR(8) Register control
EPwm2Regs.HRCNFG.bit.SELOUTB = 0;//pwmb output normal
//
EPwm2Regs.HRPCTL.bit.TBPHSHRLOADE =1;//enable PWM的高分辨率相位同步syncin
EDIS;
}

Seven Han:

不知道您使用的哪颗芯片,建议对照下TI例程 HRPWM example projects中的配置,该例程用到SFO library。

C:\ti\controlSUITE\device_support\F2837xD\v210\F2837xD_examples_Cpu1

1.添加库函数SFO_TI_Build_V6b.lib到工程

2.添加头文件#include“”SFO_V6.h“”

3.在EPWM.c中首先定义MEP_ScaleFactor (按照说明,此变量仅定义,使能自动转换后此变量自动赋值,并最终赋给HRMSTEP寄存器) 和MEP_Status,然后配置PWM

#include "DSP2803x_Device.h"       // DSP2803x Headerfile Include File
#include "DSP2803x_Examples.h"  // DSP2803x Examples Include File
int MEP_ScaleFactor =0;
int MEP_Status;

void InitEPwm(void)
{
   InitEPwm1Gpio(); //具体配置略
   InitEPwm2Gpio();//具体配置略

   InitEPwm1(); //1路未用HRPWM,正常配置无问题
   InitEPwm2(); //2路里配置了HRPWM,函数在下面
//开时钟
   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
   EDIS;
  
   while (MEP_Status != SFO_COMPLETE)//调试发现MEP_Status 一直是2,导致while出不去,窗口中观察EPWM2中的HRMSTEP寄存器也一直是0并未被赋值
    { MEP_Status = SFO(); }
}

//

void InitEPwm2(void) 
{

EALLOW;
//Setup Time-based module
EPwm2Regs.TBPRD = 300; // Set timer period
EPwm2Regs.TBPHS.half.TBPHS = 0; // Phase is T/4
EPwm2Regs.TBCTR = 0x0000; // Clear counter

// Setup TBCLK
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Enable phase loading
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;

EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;

EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;//CC_CTR_PRD;//CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;//CC_CTR_PRD;//CC_CTR_ZERO;

// Setup compare
EPwm2Regs.CMPA.half.CMPA = 1;
EPwm2Regs.CMPB = 299;

// Set actions
EPwm2Regs.AQSFRC.bit.RLDCSF = 0; //load on equals zero
EPwm2Regs.AQSFRC.bit.ACTSFA = AQ_CLEAR;
EPwm2Regs.AQSFRC.bit.ACTSFB = AQ_SET;

EPwm2Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLA.bit.CAD = AQ_NO_ACTION;
EPwm2Regs.AQCTLA.bit.CBU = AQ_NO_ACTION;
EPwm2Regs.AQCTLA.bit.CBD = AQ_CLEAR;

EPwm2Regs.AQCTLB.bit.CAU = AQ_NO_ACTION;
EPwm2Regs.AQCTLB.bit.CAD = AQ_NO_ACTION;
EPwm2Regs.AQCTLB.bit.CBU = AQ_NO_ACTION;
EPwm2Regs.AQCTLB.bit.CBD = AQ_NO_ACTION;

// Active Low PWMs – Setup Deadband
EPwm2Regs.DBCTL.bit.OUT_MODE = 3;
EPwm2Regs.DBCTL.bit.POLSEL = 2; //2
EPwm2Regs.DBCTL.bit.IN_MODE = 0; //2 A for the rising delay,B for the falling
EPwm2Regs.DBRED = 60;
EPwm2Regs.DBFED = 60; //死区时间1.667us

EDIS;
EALLOW;
EPwm2Regs.HRCNFG.all =0x0;
EPwm2Regs.HRCNFG.bit.AUTOCONV =1;
// EPwm1Regs.HRCNFG.bit.HRLOAD =CC_CTR_ZERO;//Selects the time event that loads the CMPAHR shadow value into the active register
EPwm2Regs.HRCNFG.bit.EDGMODE = 3; //both edge;
EPwm2Regs.HRCNFG.bit.CTLMODE = 1;//0:CMPAHR(8) or TBPRDHR(8) 1:TBPHSHR(8) Register control
EPwm2Regs.HRCNFG.bit.SELOUTB = 0;//pwmb output normal
//
EPwm2Regs.HRPCTL.bit.TBPHSHRLOADE =1;//enable PWM的高分辨率相位同步syncin
EDIS;
}

user3518395:

回复 Seven Han:

用的28033,参考了例子返回值还是有问题啊。。

赞(0)
未经允许不得转载:TI中文支持网 » 请问在系统时钟60M使用HRPWM的自动转换模式时,调用sfo()函数后遇到返回值一直是2,导致程序陷入死循环无法正常工作怎么回事啊。具体代码如下
分享到: 更多 (0)