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.

[参考译文] TMS320F28379D:使用 SCI 外设更改 ePWM 的占空比

Guru**** 2555630 points
Other Parts Discussed in Thread: SYSCONFIG

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1304108/tms320f28379d-changing-duty-cycle-of-epwm-using-sci-periphera

器件型号:TMS320F28379D
主题中讨论的其他器件:SysConfig

此代码 包括用于通过 SCI 模块接收用户占空比输入、根据输入的占空比计算新的比较值以及相应地更新 EPWM 占空比的必要逻辑。 我在 SysConfig 工具中配置了 SCIA、epwm0和 ECAP 模块。 但我在控制台中没有获得预期的输出。

请参阅随附的代码和屏幕快照、请告诉我如何实现该逻辑以及我需要在代码中进行哪些更改  

//
// Included Files
//
#include "driverlib.h"
#include "device.h"
#include "board.h"

uint32_t ePwm_TimeBase;
uint32_t ePwm_MinDuty;
uint32_t ePwm_MaxDuty;
uint32_t ePwm_curDuty;
uint32_t eCapPwmDuty;            // Percent = (eCapPwmDuty/eCapPwmPeriod)*100.
uint32_t eCapPwmPeriod;          // Frequency = DEVICE_SYSCLK_FREQ/eCapPwmPeriod.
uint16_t newDutyCycle;

__interrupt void INT_myECAP0_ISR(void);



void main(void)
{
    Device_init();
    Interrupt_initModule();
    Interrupt_initVectorTable();

    // Configure GPIO pins
   //
    Device_initGPIO();

   //
   // Initialize the SCI and Timer Modules
   //
    Board_init();

    // Initialize variables for ePWM Duty Cycle
    ePwm_TimeBase = EPWM_getTimeBasePeriod(myEPWM0_BASE);
    ePwm_MinDuty = (uint32_t)(0.95f * (float)ePwm_TimeBase);
    ePwm_MaxDuty = (uint32_t)(0.05f * (float)ePwm_TimeBase);
    ePwm_curDuty = EPWM_getCounterCompareValue(myEPWM0_BASE, EPWM_COUNTER_COMPARE_A);
    EINT;
    ERTM;

    //
    // Define local variables for SCI
    //
    char* msg;                // Message sent through the terminal window
    char receivedChar;        // Variable used to track input from the terminal window
    uint16_t rxStatus = 0U;   // Variable used to store the status of the SCI RX Register


    for (;;)
        {

        msg = "\r\nEnter Duty cycle 0-100: \0";
        SCI_writeCharArray(mySCIA_BASE, (uint16_t*)msg, 30);


        //
        // Read a character from the FIFO.
        //
        receivedChar = SCI_readCharBlockingFIFO(mySCIA_BASE);
        SCI_writeCharBlockingFIFO(mySCIA_BASE, receivedChar);
        DEVICE_DELAY_US(1000000);


        // Convert character to digit
        newDutyCycle = receivedChar - '0';



        // Ensure duty cycle is within the valid range
        if (newDutyCycle <= 100)
        {
                   // Calculate new compare value based on duty cycle
                   uint32_t newCompareValue = (newDutyCycle * (ePwm_MaxDuty - ePwm_MinDuty) / 100) + ePwm_MinDuty;

                   // Update ePWM duty cycle
                   EPWM_setCounterCompareValue(myEPWM0_BASE, EPWM_COUNTER_COMPARE_A, (uint16_t)newCompareValue);
        }

        rxStatus = SCI_getRxStatus(mySCIA_BASE);
        if ((rxStatus & SCI_RXSTATUS_ERROR) != 0)
        {

            //
            // If Execution stops here there is some error
            // Analyze SCI_getRxStatus() API return value
            //
            ESTOP0;
        }

        //
        // Echo back the character.
        //
        msg = "  Duty cycle set successfully! \0";
        SCI_writeCharArray(mySCIA_BASE, (uint16_t*)msg, 31);
    }
}

__interrupt void INT_myECAP0_ISR(void)
{
    Interrupt_clearACKGroup(INT_myECAP0_INTERRUPT_ACK_GROUP);
    ECAP_clearGlobalInterrupt(myECAP0_BASE);
    ECAP_clearInterrupt(myECAP0_BASE, ECAP_ISR_SOURCE_CAPTURE_EVENT_3);
    eCapPwmDuty = (int32_t)ECAP_getEventTimeStamp(myECAP0_BASE, ECAP_EVENT_2) -
                  (int32_t)ECAP_getEventTimeStamp(myECAP0_BASE, ECAP_EVENT_1);
    eCapPwmPeriod = (int32_t)ECAP_getEventTimeStamp(myECAP0_BASE, ECAP_EVENT_3) -
                    (int32_t)ECAP_getEventTimeStamp(myECAP0_BASE, ECAP_EVENT_1);
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    我在终端窗口中看到的是我相信的 SCI 接收代码。 SCI 功能未按预期运行。 消息字符'\r'、'\n'被视为单个字符。 您能否相应地更改消息字符?

    此外、您是否碰巧在您的器件上尝试了独立 SCI 回显示例、以确保所有其他硬件要求都按顺序排列?

    谢谢。
    阿迪亚