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.
您好!
我正在尝试 完成与此处所述内容类似的内容: 将 PWM 与外部信号同步- TI Hercules 微控制器 (请查看 此 链接的视频以了解其功能)。
这篇文章背后的主要思想是 将 PWM 与外部信号同步 在这里、每次控制信号有一个上升沿时、PWM 信号被复位。 该实施是通过另一个 TI 微控制器完成的、因此我想它也可以通过 F28004x C2000微控制器系列实现。 在本例中、 我将随 TMDSHSECDOCK 一起使用 TMS320F280049C 控制卡。
TMS320F28004x 实时微控制器技术参考手册 解释了 ePWM 可以与 EXTSYNCINx 同步、因此外部 SYNC 信号应通过 INPUTXBAR5和/或 INPUTXBAR6直接路由、以提供与 ePWM 和 eCAP 同步链的同步。
为了测试这一概念、我采用了 CCS 参考 示例 epwm_ex3_synchronization.projectspec (位于 C2000Ware_5_00_00_00\driverlib\f28004x\examples\EPWM)并进行了一些修改、使测试非常简单。 因此、我考虑了以下简单场景:
输入 GPIO39 * > INPUTXBAR5 > EXTSYNCIN1 > ePWM1 > GPIO0 (PWM1A)和 GPIO1 (PWM1B)输出
* 向 GPIO39施加外部方波信号(2V 振幅、50%占空比和100Hz)
最后的.c 代码在下面分享、在这里、我唯一的贡献是评论与 ePWM2、3和4相关的行、我不打算使用这些行。 下面对.syscfg 代码也进行了小幅修改、其中我将 XBAR 输入5更改为 GPIO39并删除了 myINPUTXBARINPUT1 (XBAR_INPUT6)、下面的屏幕截图 显示了最终配置。 此外、我删除了 myEPWM2、3和4、以下屏幕截图 显示了最终配置。 不会对原始示例应用进一步的更改。
//############################################################################# // // FILE: epwm_ex3_synchronization.c // // TITLE: ePWM Using The Synch Chain and Phase Shift. // //! \addtogroup driver_example_list //! <h1>ePWM Synchronization</h1> //! //! This example configures ePWM1, ePWM2, ePWM3 and ePWM4 as follows //! - ePWM1 without phase shift as sync source //! - ePWM2 with phase shift of 300 TBCLKs //! - ePWM3 with phase shift of 600 TBCLKs //! - ePWM4 with phase shift of 900 TBCLKs //! //! \b External \b Connections \n //! - GPIO0 EPWM1A //! - GPIO1 EPWM1B //! - GPIO2 EPWM2A //! - GPIO3 EPWM2B //! - GPIO4 EPWM3A //! - GPIO5 EPWM3B //! - GPIO6 EPWM4A //! - GPIO7 EPWM4B //! //! \b Watch \b Variables \n //! - None. // //############################################################################# // // // $Copyright: // Copyright (C) 2023 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //############################################################################# // // Included Files // #include "driverlib.h" #include "device.h" #include "board.h" __interrupt void epwm1ISR(void); __interrupt void epwm2ISR(void); __interrupt void epwm3ISR(void); __interrupt void epwm4ISR(void); // // 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(); // // Assign the interrupt service routines to ePWM interrupts // Interrupt_register(INT_EPWM1, &epwm1ISR); //Interrupt_register(INT_EPWM2, &epwm2ISR); //Interrupt_register(INT_EPWM3, &epwm3ISR); //Interrupt_register(INT_EPWM4, &epwm4ISR); // Disable sync(Freeze clock to PWM as well). GTBCLKSYNC is applicable // only for multiple core devices. Uncomment the below statement if // applicable. // // SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_GTBCLKSYNC); SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC); // // Configure GPIO0/1 , GPIO2/3 and GPIO4/5 and GPIO6/7 as // ePWM1A/1B, ePWM2A/2B, ePWM3A/3B, ePWM4A/4B pins respectively // Configure EPWM Modules // Board_init(); // // Enable sync and clock to PWM // SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC); // // Enable ePWM interrupts // Interrupt_enable(INT_EPWM1); //Interrupt_enable(INT_EPWM2); //Interrupt_enable(INT_EPWM3); //Interrupt_enable(INT_EPWM4); // // Enable Global Interrupt (INTM) and realtime interrupt (DBGM) // EINT; ERTM; // // IDLE loop. Just sit and loop forever (optional): // for(;;) { } } // // epwm1ISR - ePWM 1 ISR // __interrupt void epwm1ISR(void) { // // Clear INT flag for this timer // EPWM_clearEventTriggerInterruptFlag(myEPWM1_BASE); // // Acknowledge interrupt group // Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3); } // // epwm2ISR - ePWM 2 ISR // /*__interrupt void epwm2ISR(void) { // // Clear INT flag for this timer // EPWM_clearEventTriggerInterruptFlag(myEPWM2_BASE); // // Acknowledge interrupt group // Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3); } // // epwm3ISR - ePWM 3 ISR // __interrupt void epwm3ISR(void) { // // Clear INT flag for this timer // EPWM_clearEventTriggerInterruptFlag(myEPWM3_BASE); // // Acknowledge interrupt group // Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3); } // // epwm4ISR - ePWM 4 ISR // __interrupt void epwm4ISR(void) { // // Clear INT flag for this timer // EPWM_clearEventTriggerInterruptFlag(myEPWM4_BASE); // // Acknowledge interrupt group // Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3); }*/
/** * These arguments were used when this file was generated. They will be automatically applied on subsequent loads * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments. * @cliArgs --device "F28004x" --package "F28004x_100PZ" --part "F28004x_100PZ" --context "system" --product "C2000WARE@5.00.00.00" * @versions {"tool":"1.18.0+3266"} */ /** * Import the modules used in this configuration. */ const epwm = scripting.addModule("/driverlib/epwm.js", {}, false); const epwm1 = epwm.addInstance(); const inputxbar = scripting.addModule("/driverlib/inputxbar.js", {}, false); const inputxbar1 = inputxbar.addInstance(); const inputxbar_input = scripting.addModule("/driverlib/inputxbar_input.js"); const inputxbar_input1 = inputxbar_input.addInstance(); const sync = scripting.addModule("/driverlib/sync.js"); /** * Write custom configuration values to the imported modules. */ epwm1.$name = "myEPWM1"; epwm1.epwmTimebase_period = 2000; epwm1.epwmCounterCompare_cmpA = 1000; epwm1.epwmCounterCompare_cmpB = 500; epwm1.epwmTimebase_counterMode = "EPWM_COUNTER_MODE_UP"; epwm1.epwmTimebase_clockDiv = "EPWM_CLOCK_DIVIDER_8"; epwm1.epwmTimebase_hsClockDiv = "EPWM_HSCLOCK_DIVIDER_1"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_ZERO = "EPWM_AQ_OUTPUT_HIGH"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO = "EPWM_AQ_OUTPUT_HIGH"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_LOW"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPB = "EPWM_AQ_OUTPUT_LOW"; epwm1.epwmEventTrigger_enableInterrupt = true; epwm1.epwmEventTrigger_interruptEventCount = "1"; epwm1.epwmTimebase_syncOutPulseMode = "EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO"; epwm1.epwm.$assign = "EPWM1"; epwm1.epwm.epwm_aPin.$assign = "GPIO0"; epwm1.epwm.epwm_bPin.$assign = "GPIO1"; inputxbar1.$name = "myINPUTXBAR5"; inputxbar_input1.$name = "myINPUTXBARINPUT0"; inputxbar_input1.inputxbarInput = "XBAR_INPUT5"; inputxbar_input1.inputxbarGpio = "GPIO39";
加载代码后、我无法在 GPIO39输入的上升沿看到任何同步。 在帖子的底部 、我附加了一个.ZIP 格式的视频进行测试、您可以 从示波器上看到配置和结果。 黄色显示 GPIO39外部控制信号、蓝色和粉色显示 GPIO0 (PWM1A)和 GPIO1 (PWM1B)
在该示例中、使 PWM 同步可能缺少什么? 为什么 PWM1A 和 PWM1B 不互补?
等待您的答案。
此致、
D·奥维西延科
此处的视频- e2e.ti.com/.../VideoTest.zip
Luke、您好!
感谢您的回答!
这一事实是否 在 TMS320F28004x 实时微控制器技术参考手册中的任何部分提及? 我发现 EPWM1SYNCIN 寄存器默认设置为 EXTSYNCIN1 (见下图)、因此我认为不应该再配置其他任何设置。
我已经尝试了你的建议。 我 已经检查了 EPWM 时基部分中的"启用相移加载"选项、并且尝试了 POST 中描述的相同测试。 有配置和新的.syscfg 代码的屏幕截图。
/** * These arguments were used when this file was generated. They will be automatically applied on subsequent loads * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments. * @cliArgs --device "F28004x" --package "F28004x_100PZ" --part "F28004x_100PZ" --context "system" --product "C2000WARE@5.00.00.00" * @versions {"tool":"1.18.0+3266"} */ /** * Import the modules used in this configuration. */ const epwm = scripting.addModule("/driverlib/epwm.js", {}, false); const epwm1 = epwm.addInstance(); const inputxbar = scripting.addModule("/driverlib/inputxbar.js", {}, false); const inputxbar1 = inputxbar.addInstance(); const inputxbar_input = scripting.addModule("/driverlib/inputxbar_input.js"); const inputxbar_input1 = inputxbar_input.addInstance(); const sync = scripting.addModule("/driverlib/sync.js"); /** * Write custom configuration values to the imported modules. */ const mux1 = system.clockTree["CANABCLKSEL"]; mux1.inputSelect = "XTAL"; const mux2 = system.clockTree["OSCCLKSRCSEL"]; mux2.inputSelect = "INTOSC1"; epwm1.$name = "myEPWM1"; epwm1.epwmTimebase_period = 2000; epwm1.epwmCounterCompare_cmpA = 1000; epwm1.epwmCounterCompare_cmpB = 500; epwm1.epwmTimebase_counterMode = "EPWM_COUNTER_MODE_UP"; epwm1.epwmTimebase_clockDiv = "EPWM_CLOCK_DIVIDER_8"; epwm1.epwmTimebase_hsClockDiv = "EPWM_HSCLOCK_DIVIDER_1"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_ZERO = "EPWM_AQ_OUTPUT_HIGH"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO = "EPWM_AQ_OUTPUT_HIGH"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_LOW"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPB = "EPWM_AQ_OUTPUT_LOW"; epwm1.epwmEventTrigger_enableInterrupt = true; epwm1.epwmEventTrigger_interruptEventCount = "1"; epwm1.epwmTimebase_syncOutPulseMode = "EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO"; epwm1.epwmTimebase_phaseEnable = true; epwm1.epwm.$assign = "EPWM1"; epwm1.epwm.epwm_aPin.$assign = "GPIO0"; epwm1.epwm.epwm_bPin.$assign = "GPIO1"; scripting.suppress("Clearing the phase shift value will cause the EPWM module to ignore the synchronization input pulse, if any\\.", epwm1, "epwmTimebase_phaseShift"); inputxbar1.$name = "myINPUTXBAR5"; inputxbar_input1.$name = "myINPUTXBARINPUT0"; inputxbar_input1.inputxbarInput = "XBAR_INPUT5"; inputxbar_input1.inputxbarGpio = "GPIO39";
但是、没有任何变化、 PWM 输出仍不与我的 GPIO39输入信号同步! 结果与我在视频中展示的结果相同。
尊敬的 Denys:
您是否还可以尝试在 SysConfig 中将 GPIO39配置为输入? 我已修改.syscfg 文件以添加该文件、如下所示:
/** * These arguments were used when this file was generated. They will be automatically applied on subsequent loads * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments. * @cliArgs --device "F28004x" --package "F28004x_100PZ" --part "F28004x_100PZ" --context "system" --product "C2000WARE@5.00.00.00" * @versions {"tool":"1.0.0+dev"} */ /** * Import the modules used in this configuration. */ 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 = scripting.addModule("/driverlib/inputxbar.js", {}, false); const inputxbar1 = inputxbar.addInstance(); const inputxbar_input = scripting.addModule("/driverlib/inputxbar_input.js"); const inputxbar_input1 = inputxbar_input.addInstance(); const sync = scripting.addModule("/driverlib/sync.js"); /** * Write custom configuration values to the imported modules. */ epwm1.$name = "myEPWM1"; epwm1.epwmTimebase_period = 2000; epwm1.epwmCounterCompare_cmpA = 1000; epwm1.epwmCounterCompare_cmpB = 500; epwm1.epwmTimebase_counterMode = "EPWM_COUNTER_MODE_UP"; epwm1.epwmTimebase_clockDiv = "EPWM_CLOCK_DIVIDER_8"; epwm1.epwmTimebase_hsClockDiv = "EPWM_HSCLOCK_DIVIDER_1"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_ZERO = "EPWM_AQ_OUTPUT_HIGH"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO = "EPWM_AQ_OUTPUT_HIGH"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_LOW"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPB = "EPWM_AQ_OUTPUT_LOW"; epwm1.epwmEventTrigger_enableInterrupt = true; epwm1.epwmEventTrigger_interruptEventCount = "1"; epwm1.epwmTimebase_syncOutPulseMode = "EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO"; epwm1.epwm.$assign = "EPWM1"; epwm1.epwm.epwm_aPin.$assign = "GPIO0"; epwm1.epwm.epwm_bPin.$assign = "GPIO1"; gpio1.$name = "myGPIO0"; gpio1.gpioPin.$assign = "GPIO39"; inputxbar1.$name = "myINPUTXBAR5"; inputxbar_input1.$name = "myINPUTXBARINPUT0"; inputxbar_input1.inputxbarInput = "XBAR_INPUT5"; inputxbar_input1.inputxbarGpio = "GPIO39";
尊敬的 Denys:
抱歉、我似乎不小心修改了我发送给您的先前的.syscfg 文件、并禁用了相移加载。
我为 F2837xD launchpad 创建了一个新的测试用例、它与 F28004x 具有相同的同步方案。 我使用 GPIO3作为 SYNC 输入、并在 GPIO2上使用输出条来监控 INPUTXBAR5、以便在同一逻辑分析仪上查看 SYNC 信号和 PWM 输出。
//############################################################################# // // FILE: epwm_ex3_synchronization.c // // TITLE: ePWM Using The Synch Chain and Phase Shift. // //! \addtogroup driver_example_list //! <h1>ePWM Synchronization</h1> //! //! This example configures ePWM1, ePWM2, ePWM3 and ePWM4 as follows //! - ePWM1 without phase shift as sync source //! - ePWM2 with phase shift of 300 TBCLKs //! - ePWM3 with phase shift of 600 TBCLKs //! - ePWM4 with phase shift of 900 TBCLKs //! //! \b External \b Connections \n //! - GPIO0 EPWM1A //! - GPIO1 EPWM1B //! - GPIO2 EPWM2A //! - GPIO3 EPWM2B //! - GPIO4 EPWM3A //! - GPIO5 EPWM3B //! - GPIO6 EPWM4A //! - GPIO7 EPWM4B //! //! \b Watch \b Variables \n //! - None. // //############################################################################# // // // $Copyright: // Copyright (C) 2023 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //############################################################################# // // Included Files // #include "driverlib.h" #include "device.h" #include "board.h" __interrupt void epwm1ISR(void); __interrupt void epwm2ISR(void); __interrupt void epwm3ISR(void); __interrupt void epwm4ISR(void); // // 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(); // // Assign the interrupt service routines to ePWM interrupts // Interrupt_register(INT_EPWM1, &epwm1ISR); //Interrupt_register(INT_EPWM2, &epwm2ISR); //Interrupt_register(INT_EPWM3, &epwm3ISR); //Interrupt_register(INT_EPWM4, &epwm4ISR); // Disable sync(Freeze clock to PWM as well). GTBCLKSYNC is applicable // only for multiple core devices. Uncomment the below statement if // applicable. // // SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_GTBCLKSYNC); SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC); // // Configure GPIO0/1 , GPIO2/3 and GPIO4/5 and GPIO6/7 as // ePWM1A/1B, ePWM2A/2B, ePWM3A/3B, ePWM4A/4B pins respectively // Configure EPWM Modules // Board_init(); // // Enable sync and clock to PWM // SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC); // // Enable ePWM interrupts // Interrupt_enable(INT_EPWM1); //Interrupt_enable(INT_EPWM2); //Interrupt_enable(INT_EPWM3); //Interrupt_enable(INT_EPWM4); // // Enable Global Interrupt (INTM) and realtime interrupt (DBGM) // EINT; ERTM; // // IDLE loop. Just sit and loop forever (optional): // for(;;) { } } // // epwm1ISR - ePWM 1 ISR // __interrupt void epwm1ISR(void) { // // Clear INT flag for this timer // EPWM_clearEventTriggerInterruptFlag(myEPWM1_BASE); // // Acknowledge interrupt group // Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3); } // // epwm2ISR - ePWM 2 ISR // /*__interrupt void epwm2ISR(void) { // // Clear INT flag for this timer // EPWM_clearEventTriggerInterruptFlag(myEPWM2_BASE); // // Acknowledge interrupt group // Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3); } // // epwm3ISR - ePWM 3 ISR // __interrupt void epwm3ISR(void) { // // Clear INT flag for this timer // EPWM_clearEventTriggerInterruptFlag(myEPWM3_BASE); // // Acknowledge interrupt group // Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3); } // // epwm4ISR - ePWM 4 ISR // __interrupt void epwm4ISR(void) { // // Clear INT flag for this timer // EPWM_clearEventTriggerInterruptFlag(myEPWM4_BASE); // // Acknowledge interrupt group // Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3); }*/
/** * Import the modules used in this configuration. */ 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 = scripting.addModule("/driverlib/inputxbar.js", {}, false); const inputxbar1 = inputxbar.addInstance(); const inputxbar_input = scripting.addModule("/driverlib/inputxbar_input.js"); const inputxbar_input1 = inputxbar_input.addInstance(); const outputxbar = scripting.addModule("/driverlib/outputxbar.js", {}, false); const outputxbar1 = outputxbar.addInstance(); const sync = scripting.addModule("/driverlib/sync.js"); /** * Write custom configuration values to the imported modules. */ epwm1.$name = "myEPWM1"; epwm1.epwmTimebase_period = 2000; epwm1.epwmCounterCompare_cmpA = 1000; epwm1.epwmCounterCompare_cmpB = 500; epwm1.epwmTimebase_counterMode = "EPWM_COUNTER_MODE_UP"; epwm1.epwmTimebase_clockDiv = "EPWM_CLOCK_DIVIDER_8"; epwm1.epwmTimebase_hsClockDiv = "EPWM_HSCLOCK_DIVIDER_1"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_ZERO = "EPWM_AQ_OUTPUT_HIGH"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO = "EPWM_AQ_OUTPUT_HIGH"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_LOW"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPB = "EPWM_AQ_OUTPUT_LOW"; epwm1.epwmEventTrigger_enableInterrupt = true; epwm1.epwmEventTrigger_interruptEventCount = "1"; epwm1.epwmTimebase_syncOutPulseMode = "EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO"; epwm1.epwmTimebase_phaseEnable = true; epwm1.epwm.$assign = "EPWM1"; epwm1.epwm.epwm_aPin.$assign = "GPIO0"; epwm1.epwm.epwm_bPin.$assign = "GPIO1"; gpio1.$name = "myGPIO0"; gpio1.gpioPin.$assign = "GPIO3"; inputxbar1.$name = "myINPUTXBAR5"; inputxbar_input1.$name = "myINPUTXBARINPUT0"; inputxbar_input1.inputxbarInput = "XBAR_INPUT5"; inputxbar_input1.inputxbarGpio = "GPIO3"; outputxbar1.$name = "myOUTPUTXBAR0"; outputxbar1.useSourceSelect = true; outputxbar1.sourceSignals = ["INPUTXBAR5"]; /** * 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. */ outputxbar1.outputxbar.$suggestSolution = "OUTPUTXBAR1"; outputxbar1.outputxbar.outputxbarPin.$suggestSolution = "GPIO2";
请让我知道您是否能够在 F28004x 上重新创建这个。
谢谢!
卢克
Luke、您好!
我已经在 TMS320F280049C 控制卡和 TMDSHSECDOCK 以及 LAUNCHXL-F280049C 上试用了您建议的代码来仔细检查。 但是、对其中任何一个都不起作用。
我在此处附上了另一段测试结果视频、您可以在其中看到 没有发生与外部信号的同步。 该视频显示了示波器 、其中黄色与 GPIO3 (外部信号输入)相关、粉色与 GPIO2 (OUTPUTXBAR)相关、浅 蓝色和深蓝色 对应于 GPIO0和 GPIO1 (PWM1A 和 PWM1B)。
如果启用了相移负载、那么还有什么问题呢? 您是否能够在 F28004x 上测试您的代码?
等待您的回答!
此致、
Denys
尊敬的 Denys:
您尝试同步 ePWM1仅正确吗? 您是否设置了 TBPHS 非零? 您能否在 EXTSYNCOUT 的上升沿为触发器设置单个捕捉并查看应用 EXTSYNCOUT 时的波形变化?
设置非零 TBPHS 值时应发生什么情况、此时波形应发生变化并设置 TBCTR = TBPHS。 如果您将信号保持在高电平、同步将不会持续发生、因为它的上升沿已激活。
PWM1A 和 PWM1B 无法同步、因为您只能在 ePWM1和 ePWM2等子模块之间同步。 ePWM1模块有一个计数器、此计数器被用于 ePWM1A 和 EPWM1B 输出。
如果您的 TBPHS = 0。 就不会有任何相移。 为了查看相移、TBPHS 应该为非零值。 请注意、当从控制模块到目标模块同步时、在 TBCLK = EPWMCLK 下运行时有2个 ePWM 时钟周期延迟。
此致!
马瑞安
您好、Ryan、
感谢您的答复! 下面我将回答您的问题:
您正尝试同步 ePWM1,但只能正确吗?
是的、我希望 ePWM1与通过 INPUTXBAR5的外部信号的上升沿同步。
您是否将 TBPHS 设置为非零?
我认为、以下 SysConfig ePWM 配置 (见下图)设置 TBCTL[PHSEN]= 1以允许同步。 此外、我不需要 SYNC 输入和 ePWM1之间存在相移、因此 TBPHS=0。
您能否在 EXTSYNCOUT 的上升沿设置触发信号的单一捕获并查看应用 EXTSYNCOUT 时的波形变化?
我这里不是在寻找 EXTSYNCOUT。 我希望 ePWM1与通过 INPUTXBAR5输入的 EXTSYNCIN1同步。 该输入信号为方 波(2V 振幅、50%占空比和100Hz) 请查看 主要问题中的两个图。
只是再次强调这个帖子的目的: S 将 PWM 与外部信号同步 其中、每次控制信号(INPUTXBAR5)具有上升沿时、PWM (ePWM1)信号都会复位。 我对 ePWM 之间的相移不感兴趣、我需要的是50%占空比 ePWM1A 和互补 ePWM1B 输出、而是与输入信号上升沿同步。
如果您能分享具有 F28004x 上述功能的工作代码、我将不胜感激。 您的同事 Luke 分享了在 F2837xD 中实现和测试的.c 和.syscfg、但它 在我的代码中不起作用。
此致!
Denys
尊敬的 Denys:
此问题的根本原因是 SysConfig 中存在错误。 我已经去了,并提交了一个 TT 来解决这个问题。 感谢您的关注!
在您从 Board_init ()对 PWM 进行初始化后, SysConfig 应该已经生成了将 ePWM1的 SYNCIN 设置为 EXTSYNCIN1的代码,但是它似乎没有生成这个代码,因此您的 PWM 从未使用 SYNCIN。 SyncSockRegs.EPWM1SYNCIN 的默认值为7h。 因此、ePWM1的 SYNCIN 始终未正确设置、因此没有出现相移。
下面是一个在 F28004x 器件上尝试使用的测试案例。 以及示波器屏幕截图。 最后、请验证此操作是否有效、对于任何混淆深表歉意!
另外需要说明的是、设置 TBPHS=0不会导致 SYNCIN 被忽略。 这是测试用例。 您可以将相移更改为您喜欢的任何值
//############################################################################# // // FILE: main.c // // TITLE: Universal Empty Project // // Universal Empty Project Example // // This example is an empty project setup for Driverlib development. // //############################################################################# // // // $Copyright: $ //############################################################################# // // Included Files // #include "driverlib.h" #include "device.h" #include "board.h" #include "c2000ware_libraries.h" void INT_myEPWM0_ISR(void); void INT_myEPWM0_ISR(void){ GPIO_writePin(myGPIO0, 1); // // Clear INT flag for this timer // EPWM_clearEventTriggerInterruptFlag(myEPWM0_BASE); // // Acknowledge this interrupt to receive more interrupts from group 3 // Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3); GPIO_writePin(myGPIO0, 0); return; } // // 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(); // // PinMux and Peripheral Initialization // Board_init(); SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC); EPWM_setTimeBaseCounter(myEPWM0_BASE, 0); SysCtl_setSyncInputConfig(SYSCTL_SYNC_IN_EPWM1, SYSCTL_SYNC_IN_SRC_EXTSYNCIN1); SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC); // // C2000Ware Library initialization // C2000Ware_libraries_init(); // // Enable Global Interrupt (INTM) and real time interrupt (DBGM) // EINT; ERTM; while(1) { } } // // End of File //
/** * These arguments were used when this file was generated. They will be automatically applied on subsequent loads * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments. * @cliArgs --board "/boards/LAUNCHXL_F280049C" --context "system" --product "C2000WARE@5.02.00.00" * @versions {"tool":"1.17.0+3128"} */ /** * Import the modules used in this configuration. */ const device_support = scripting.addModule("/driverlib/device_support.js"); 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 memcfg = scripting.addModule("/driverlib/memcfg.js"); const outputxbar = scripting.addModule("/driverlib/outputxbar.js", {}, false); const outputxbar1 = outputxbar.addInstance(); const sync = scripting.addModule("/driverlib/sync.js"); const sysctl = scripting.addModule("/driverlib/sysctl.js"); const CMD = scripting.addModule("/utilities/cmd_tool/cmd_syscfg/source/CMD"); const CMD1 = CMD.addInstance(); const CMD2 = CMD.addInstance(); /** * Write custom configuration values to the imported modules. */ epwm1.$name = "myEPWM0"; epwm1.epwmTimebase_phaseEnable = true; epwm1.$hardware = system.deviceData.board.components.BP_SITE_2.subComponents.PWM_LOC1; epwm1.epwmTimebase_period = 1000; epwm1.epwmTimebase_counterMode = "EPWM_COUNTER_MODE_UP"; 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.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO = "EPWM_AQ_OUTPUT_LOW"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_HIGH"; epwm1.epwmCounterCompare_cmpA = 500; epwm1.epwmCounterCompare_cmpB = 500; epwm1.epwmCounterCompare_cmpC = 700; epwm1.epwmEventTrigger_enableInterrupt = true; epwm1.epwmEventTrigger_interruptSource = "EPWM_INT_TBCTR_U_CMPC"; epwm1.epwmEventTrigger_registerInterrupts = true; epwm1.epwmEventTrigger_interruptEventCount = "2"; epwm1.epwmTimebase_phaseShift = 499; epwm1.epwmTimebase_syncOutPulseMode = "EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN"; epwm1.epwmInt.enableInterrupt = true; gpio1.$name = "myGPIO0"; gpio1.direction = "GPIO_DIR_MODE_OUT"; gpio1.writeInitialValue = true; gpio1.gpioPin.$assign = "boosterpack1.13"; inputxbar_input1.$name = "myINPUTXBARINPUT0"; inputxbar_input1.inputxbarInput = "XBAR_INPUT5"; inputxbar_input1.inputxbarGpio = "GPIO39"; outputxbar1.$name = "myOUTPUTXBAR0"; outputxbar1.useSourceSelect = true; outputxbar1.sourceSignals = ["EXTSYNCOUT"]; outputxbar1.outputxbar.outputxbarPin.$assign = "boosterpack2.75"; scripting.suppress("Connected to hardware,@@@.+?@@@ is connected to EPWM2 BP on the LaunchPad F280049C\\. Consider selecting it in 'use hardware' above\\. @@@.+?@@@", outputxbar1.outputxbar, "outputxbarPin"); CMD1.$name = "generic_ram_lnk"; CMD1.sectionMemory_bss = ["RAMLS5"]; CMD1.sectionMemory_data = ["RAMLS5"]; CMD1.sectionMemory_ramfunc = ["RAMM0"]; CMD1.sectionMemory_cinit = ["RAMM0"]; CMD1.sectionMemory_stack = ["RAMM1"]; CMD1.sectionMemory_init_array = ["RAMM0"]; CMD1.sectionMemory_switch = ["RAMM0"]; CMD1.sectionMemory_const = ["RAMLS5"]; CMD1.sectionMemory_sysmem = ["RAMLS5"]; CMD1.sectionMemory_text = ["RAMGS0","RAMGS1","RAMLS0","RAMLS1","RAMLS2","RAMLS3","RAMLS4","RAMLS5","RAMLS6","RAMLS7","RAMM0","RAMM1"]; CMD2.$name = "generic_flash_lnk"; CMD2.sectionAlignEnable_ramfunc = true; CMD2.sectionAlignEnable_text = true; CMD2.sectionAlignEnable_binit = true; CMD2.sectionAlignEnable_cinit = true; CMD2.sectionAlignEnable_switch = true; CMD2.sectionAlignEnable_init_array = true; CMD2.sectionAlignEnable_const = true; CMD2.sectionAlignEnable_ovly = true; CMD2.sectionMemory_codestart = "0x080000"; CMD2.sectionMemory_stack = ["RAMM1"]; CMD2.sectionMemory_bss = ["RAMLS5"]; CMD2.sectionMemory_data = ["RAMLS5"]; CMD2.sectionMemory_sysmem = ["RAMLS5"]; CMD2.sectionRunFromDifferentAddr_ramfunc = true; CMD2.sectionRun_ramfunc = ["RAMLS0"]; CMD2.sectionBinit_ramfunc = false; CMD2.sectionMemory_ramfunc = ["FLASH_BANK0_SEC1"]; CMD2.sectionMemory_text = ["FLASH_BANK0_SEC2","FLASH_BANK0_SEC3","FLASH_BANK0_SEC5"]; CMD2.sectionMemory_binit = ["FLASH_BANK0_SEC1"]; CMD2.sectionMemory_cinit = ["FLASH_BANK0_SEC1"]; CMD2.sectionMemory_switch = ["FLASH_BANK0_SEC1"]; CMD2.sectionMemory_init_array = ["FLASH_BANK0_SEC1"]; CMD2.sectionMemory_const = ["FLASH_BANK0_SEC4"]; CMD2.sectionMemory_ovly = ["FLASH_BANK0_SEC1"]; /** * 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 = "boosterpack2.80"; epwm1.epwm.epwm_bPin.$suggestSolution = "boosterpack2.79"; outputxbar1.outputxbar.$suggestSolution = "OUTPUTXBAR2";
黄色:PWM1A
蓝色:PWM1B
粉色:GPIO39
绿色:EXTSYNCOUT (通过 ePWM1)
使用我们的 F28004x Launchpad 对此进行了测试。 在第2个事件之后、使用事件触发子模块生成 ISR、在该模块中、我切换 GPIO 以发送同步脉冲。
您好、Ryan、
感谢您的回答。
我正在尝试测试 您的代码、但在构建项目时收到错误、我不确定它们是什么(请参阅下图)
我的程序如下:
以 epwm_ex3_synchronization.projectspec 为例(位于 C2000Ware_5_00_00_00\driverlib\f28004x\examples\EPWM)
2. 根据您的需要修改 epwm_ex3_synchronization.c 代码
3. 按您自己的方式修改 epwm_ex3_synchronization.syscfg 代码。
请举手示意一下、以便我可以执行测试。
此致、
Denys
尊敬的 Denys:
从我提供的.syscfg 中复制内容后、是否可以在 CCS 中打开 syscfg?
此致!
马瑞安
您好、Ryan、
不、我不能。 屏幕上出现以下错误:
此致、
D·奥维西延科
您好 Denys、您可以尝试将此文件复制过来吗?
/** * These arguments were used when this file was generated. They will be automatically applied on subsequent loads * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments. * @cliArgs --device "F28004x" --package "F28004x_100PZ" --part "F28004x_100PZ" --context "system" --product "C2000WARE@5.00.00.00" * @versions {"tool":"1.18.0+3267"} */ /** * Import the modules used in this configuration. */ 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 memcfg = scripting.addModule("/driverlib/memcfg.js"); const outputxbar = scripting.addModule("/driverlib/outputxbar.js", {}, false); const outputxbar1 = outputxbar.addInstance(); const sync = scripting.addModule("/driverlib/sync.js"); const sysctl = scripting.addModule("/driverlib/sysctl.js"); /** * Write custom configuration values to the imported modules. */ epwm1.$name = "myEPWM0"; epwm1.epwmTimebase_phaseEnable = true; epwm1.epwmTimebase_period = 1000; epwm1.epwmTimebase_counterMode = "EPWM_COUNTER_MODE_UP"; 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.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO = "EPWM_AQ_OUTPUT_LOW"; epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_HIGH"; epwm1.epwmCounterCompare_cmpA = 500; epwm1.epwmCounterCompare_cmpB = 500; epwm1.epwmCounterCompare_cmpC = 700; epwm1.epwmEventTrigger_enableInterrupt = true; epwm1.epwmEventTrigger_interruptSource = "EPWM_INT_TBCTR_U_CMPC"; epwm1.epwmEventTrigger_registerInterrupts = true; epwm1.epwmEventTrigger_interruptEventCount = "2"; epwm1.epwmTimebase_phaseShift = 499; epwm1.epwmTimebase_syncOutPulseMode = "EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN"; epwm1.epwm.$assign = "EPWM1"; epwm1.epwmInt.enableInterrupt = true; gpio1.$name = "myGPIO0"; gpio1.direction = "GPIO_DIR_MODE_OUT"; gpio1.writeInitialValue = true; gpio1.gpioPin.$assign = "GPIO39"; inputxbar_input1.$name = "myINPUTXBARINPUT0"; inputxbar_input1.inputxbarInput = "XBAR_INPUT5"; inputxbar_input1.inputxbarGpio = "GPIO39"; outputxbar1.$name = "myOUTPUTXBAR0"; outputxbar1.useSourceSelect = true; outputxbar1.sourceSignals = ["EXTSYNCOUT"]; outputxbar1.outputxbar.outputxbarPin.$assign = "GPIO3"; /** * 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.epwm_aPin.$suggestSolution = "GPIO0"; epwm1.epwm.epwm_bPin.$suggestSolution = "GPIO1"; outputxbar1.outputxbar.$suggestSolution = "OUTPUTXBAR2";
此致!
马瑞安
您好、Ryan、
它适用于您共享的最后一个.syscfg。 但这仍然不是我所期望的。
您的实现会产生中断、但不会与任何外部信号同步。 请再次查看此站点上的视频(我之前发布过)以完全了解我的预期。 此处的视频- 将 PWM 与外部信号同步- TI Hercules 微控制器
想法很简单。 GPIO39 (INPUTXBAR5)应接收由外部电路(例如函数发生器)提供的方波信号、ePWM1应与该外部电路同步。 同步必须发生在 GPIO39输入信号的上升沿。
我希望这次 我解释得好。
等待您的答案。
此致、
Denys
尊敬的 Denys:
请看一下代码和示波器屏幕截图。 我将同步到充当函数发生器的 GPIO 信号。 我将 GPIO39信号路由至输入 x-bar5、其中 PWM1模块启用了相移。 为了验证同步信号是否会到达 ePWM1、我将 ePWMSYNCOUT 路由到另一个 GPIO、以便我知道同步信号已到达 PWM 模块。
您还可以验证当同步到 ePWM 时、占空比宽度是否更长、因为计数器已设置为 TBPHS 等于的任何值。
在上面的测试用例中、您可以将 GPIO 更改为输入、使其与外部电路连接、并且行为是相同的。
此致!
马瑞安