This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
您好!
我想 在 APWM 模式下使用 ECAP4、它可与 TMS320F280049C 的 EXTSYNCIN2同步
我已经 按照 TI 参考手册将 ECAP4设置为与 EXTSYNCIN2同步。
但它不起作用、ECAP4 APWM 输出将在 EXTSYNCIN2输入上漂移。
请检查此代码设置、波形和 CCS 寄存器读取值如下所示。
请参考 C2000_C2000_SDK_4_00_00\solutions\TIDM_02002上的函数定义 Ware_Digital。
请尽快答复我。
非常感谢。
香港特区政府
* 同步 IO 设置
EALLOW;
GPIO_setDirectionMode (25、GPIO_DIR_MODE_IN);
GPIO_setQualificationMode (25、GPIO_QUAL_SYNC);
GPIO_setPinConfig (GPIO_25_GPIO25);
//将 Input-XBAR INPUT6配置为 ExtSynCIn2的 GPIO25
XBAR_setInputPin (XBAR_INPUT6、25);
EDIS;
XBAR_setOutputMuxConfig (XBAR_OUTPUT8、XBAR_OUT_MUX06_ECAP4_OUT);
XBAR_enableOutputMux (XBAR_OUTPUT8、XBAR_MUX06);
GPIO_setPadConfig (17、GPIO_PIN_TYPE_STD);
GPIO_setPinConfig (GPIO_17_OUTPUTXBAR8);
* ECAP4"同步输入/输出设置*****
EALLOW;
//禁用到 SYNCO
HWREGH (ECAP4_BASE + ECAP_O_ECCTL2)|=(0x3U<<ECAP_ECCTL2_SYNCO_SEL_S);
HWREGH (ECAP4_BASE + ECAP_O_ECCTL2)&=~ECAP_ECCTL2_SWSYNC;
EDIS;
SYSCTL_setSyncInputConfig (SYSCTL_SYNC_IN_ECAP4、SYSCTL_SYNC_IN_SRC_EXTSYNCIN2);
EALLOW; //写入 SYNCI_EN
HWREGH (ECAP4_BASE + ECAP_O_ECCTL2)|= ECAP_ECCTL2_SYNCI_EN;
EDIS;
* SysCtl_setSyncInputConfig 函数定义 :
静态内联空
SYSCTL_setSyncInputConfig (Ctl_Sync 输入、Sys45g Ctl_Sync syncSrc)
{
uint32_t clearMask;
//
//将输入同步源选择写入相应的寄存器。
//
EALLOW;
if (syncInput == SYSCTL_SYNC_IN_EPWM1)
{
//
//请注意,EXTSYNCIN1是 ePWM1的唯一有效选项
//
HWREG (SYNCSOC_BASE + SYSCTL_O_SYNCSELECT)&=
~SYSCTL_SYNCSELECT_EPWM1SYNCIN_M;
}
否则
{
clearMask =(uint32_t) SYSCTL_SYNCSELECT_SYNCIN_M <<
(uint32_t) syncInput;
HWREG (SYNCSOC_BASE + SYSCTL_O_SYNCSELECT)=
(HWREG (SYNCSOC_BASE + SYSCTL_O_SYNCSELECT)&~clearMask)|
((uint32_t) syncSrc <<(uint32_t) syncInput);
}
EDIS;
}
* ECAPWM 设定
int32_t ecap_ticks =(int32_t)((float32_t)(pwmSysClk Freq_Hz / Freq_Hz));
ECAP_enableAPWMMode (ECAP4_BASE);
ECAP_setAPWMPeriod (ECAP4_BASE、ECAP_TICK);
ECAP_setAPWMCompare (ECAP4_BASE、100U);
ECAP_setPhaseShiftCount (ECAP4_BASE、0u);
ECAP_enableLoadCounter (ECAP4_BASE);
ECAP_clearInterrupt (ECAP4_BASE、0xFF);
ECAP_clearGlobalInterrupt (ECAP4_BASE);
ECAP_startCounter (ECAP4_BASE);
* CCS 注册观察窗口
尊敬的玉智:
我提供了一个将 eCAP4同步至 EXTSYNCIN2的基本示例。 您提供的代码很难看到可能存在的故障。
我使用了 ePWM ISR 发出了 GPIO 切换信号、即 EXTSYNCIN2、我使用它来同步 eCAP4。
以下示波器屏幕截图显示了以下
黄色:EXTSYNCIN2的 GPIO 切换
蓝色:eCAP4输出
紫色:eCAP2输出(不同步)
附加的文件是测试用例:
C 文件:
// Included Files // #include "driverlib.h" #include "device.h" #include "board.h" // // Main // void main(void) { // // Initialize device clock and peripherals // Device_init(); // // Disable pin locks and enable internal pull ups. // Device_initGPIO(); // // Initialize PIE and clear PIE registers. Disables CPU interrupts. // Interrupt_initModule(); // // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // Interrupt_initVectorTable(); // // Board initialization // Select eCAP1OUT on MUX 0. Make GPIO5 as eCAP1OUT for PWM output // Select eCAP2OUT on MUX 2. Make GPIO6 as eCAP2OUT for PWM output // Configure eCAP1 in APWM mode with defined period and duty values // Polarity as low and configure SYNCOUT at CTR=PRD // EALLOW; Board_init(); EPWM_setInterruptSource(myEPWM0_BASE, EPWM_INT_TBCTR_ZERO); SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC); // // Enable Global Interrupt (INTM) and realtime interrupt (DBGM) // EINT; ERTM; while(1) { } } void INT_myEPWM0_ISR(void){ // Toggle GPIO GPIO_writePin(myGPIO0, 1); // // Clear INT flag for this timer // EPWM_clearEventTriggerInterruptFlag(myEPWM0_BASE); // // Acknowledge interrupt group // Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3); GPIO_writePin(myGPIO0, 0); return; } // // End of File //
SysConfig:
/** * Import the modules used in this configuration. */ const ecap = scripting.addModule("/driverlib/ecap.js", {}, false); const ecap1 = ecap.addInstance(); const ecap2 = ecap.addInstance(); const epwm = scripting.addModule("/driverlib/epwm.js", {}, false); const epwm1 = epwm.addInstance(); const gpio = scripting.addModule("/driverlib/gpio.js", {}, false); const gpio1 = gpio.addInstance(); const inputxbar_input = scripting.addModule("/driverlib/inputxbar_input.js", {}, false); const inputxbar_input1 = inputxbar_input.addInstance(); const outputxbar = scripting.addModule("/driverlib/outputxbar.js", {}, false); const outputxbar1 = outputxbar.addInstance(); const outputxbar2 = outputxbar.addInstance(); const sync = scripting.addModule("/driverlib/sync.js"); /** * Write custom configuration values to the imported modules. */ ecap1.$name = "myECAP0"; ecap1.ecapMode = "APWM"; ecap1.syncOutMode = "ECAP_SYNC_OUT_COUNTER_PRD"; ecap1.apwmPolarity = "ECAP_APWM_ACTIVE_LOW"; ecap1.apwmPeriod = 10000; ecap1.apwmCompare = 5000; ecap2.$name = "myECAP1"; ecap2.ecapMode = "APWM"; ecap2.enableLoadCounter = true; ecap2.apwmPeriod = 10000; ecap2.apwmCompare = 5000; ecap2.loadCounter = true; ecap2.syncOutMode = "ECAP_SYNC_OUT_DISABLED"; ecap2.ecapBase = "ECAP4_BASE"; epwm1.$name = "myEPWM0"; epwm1.epwmTimebase_counterMode = "EPWM_COUNTER_MODE_UP"; epwm1.epwmEventTrigger_enableInterrupt = true; epwm1.epwmEventTrigger_registerInterrupts = true; epwm1.epwmCounterCompare_cmpB = 1; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_ZERO = "EPWM_AQ_OUTPUT_HIGH"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_LOW"; epwm1.epwmCounterCompare_cmpA = 100; epwm1.epwmEventTrigger_interruptSource = "EPWM_INT_TBCTR_ZERO"; epwm1.epwmEventTrigger_interruptEventCount = "15"; epwm1.epwmTimebase_period = 50000; epwm1.epwmTimebase_counterValue = 1; epwm1.epwmInt.enableInterrupt = true; gpio1.$name = "myGPIO0"; gpio1.writeInitialValue = true; gpio1.direction = "GPIO_DIR_MODE_OUT"; gpio1.gpioPin.$assign = "GPIO14"; inputxbar_input1.$name = "myINPUTXBARINPUT0"; inputxbar_input1.inputxbarInput = "XBAR_INPUT6"; inputxbar_input1.inputxbarGpio = "GPIO14"; outputxbar1.$name = "myOUTPUTXBAR0"; outputxbar1.mux0Config = "XBAR_OUT_MUX00_ECAP1_OUT"; outputxbar1.useSourceSelect = true; outputxbar1.sourceSignals = ["ECAP4_OUT"]; outputxbar1.outputxbar.$assign = "OUTPUTXBAR8"; outputxbar1.outputxbar.outputxbarPin.$assign = "GPIO17"; outputxbar2.$name = "myOUTPUTXBAR1"; outputxbar2.mux2Config = "XBAR_OUT_MUX02_ECAP2_OUT"; outputxbar2.useSourceSelect = true; outputxbar2.sourceSignals = ["ECAP1_OUT"]; outputxbar2.outputxbar.$assign = "OUTPUTXBAR4"; outputxbar2.outputxbar.outputxbarPin.$assign = "GPIO15"; sync.ecap1SyncInSource = "SYSCTL_SYNC_IN_SRC_EPWM7SYNCOUT"; sync.ecap4SyncInSource = "SYSCTL_SYNC_IN_SRC_EXTSYNCIN2"; /** * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to * re-solve from scratch. */ epwm1.epwm.$suggestSolution = "EPWM1"; epwm1.epwm.epwm_aPin.$suggestSolution = "GPIO0"; epwm1.epwm.epwm_bPin.$suggestSolution = "GPIO1";