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.

[参考译文] TMS320F28027F:TMS320F28027、使用 DRV8301运行 BLDC 电机

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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1451566/tms320f28027f-tms320f28027with-drv8301-to-run-bldc-motor

器件型号:TMS320F28027F
主题中讨论的其他器件:MOTORWARE

工具与软件:

你(们)好

"我已经开始使用 UART 命令来运行电机。 我将在 MotorWare 中使用 Lab11、并已在 HAL 教程的第6.7节中添加了 SCI/UART。 我的问题是、如何编写电机启动和停止功能的逻辑? "怎么会这样?

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

    这可能是一个详细的工程问题。 在示例实验中、您可能只需要将命令从 UART 转换为控制变量、如 gMotorVars。 用于启动/停止电机 gMotorVars 的 Flag_Run_Identify。 SpeedRef_krpm 来设置目标运行速度。

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

    嗨、Yanming Luo

    "我已经在 main.h 文件中写入了 handleMotorCommands。 如果需要任何修改、请告诉我。"

    In main.h file void handleMotorCommands(void)
    {
        // Start/Stop the motor based on isMotorOn flag
        if (isMotorOn)
        {
            gMotorVars.Flag_Run_Identify = true;
            printf("Motor is ON\n"); // Debug: Print motor state
        }
        else
        {
            gMotorVars.Flag_Run_Identify = false;
            printf("Motor is OFF\n"); // Debug: Print motor state
        }
    
        // Set the target running speed
        gMotorVars.SpeedRef_krpm = targetSpeed;
        printf("Target speed set to %ld krpm\n", gMotorVars.SpeedRef_krpm); // Debug: Print target speed
    }

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

    看起来不错。 如果您有任何其他问题、敬请告知。

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

    嗨、Yanming Luo

    "我已写入 main.c 文件。 如果需要任何修改、请告诉我。"

    In main.c file
    
    // UART Rx ISR
    interrupt void sciARxISR(void)
    {
        HAL_Obj *obj = (HAL_Obj *)halHandle;
    
        while (SCI_rxDataReady(obj->sciAHandle))
        {
            char c = SCI_read(obj->sciAHandle);
    
            if (counter < BUF_SIZE - 1) // -1 to leave space for null terminator
            {
                buf[counter++] = c;
    
                if (c == '>') // End of command
                {
                    buf[counter] = '\0'; // Null-terminate the command string
                    processCommand(buf);
                    counter = 0; // Reset buffer index
                }
            }
            else
            {
                // Buffer overflow, reset counter
                counter = 0;
            }
        }
    
        // Clear SCI interrupt flag
        PIE_clearInt(obj->pieHandle, PIE_GroupNumber_9);
    }
    
    // Process received command
    void processCommand(char *command)
    
    {
        if (strcmp(command, CMD_RX_ON) == 0)
        {
            isMotorOn = true;
            sendResponse("Motor ON");
        }
        else if (strcmp(command, CMD_RX_OFF) == 0)
        {
            isMotorOn = false;
            sendResponse("Motor OFF");
        }
        else
        {
            sendResponse("Unknown Command");
        }
    }
    
    // Send response to UART
    void sendResponse(const char *message)
    {
        int length = strlen(message);
        returnBuf[0] = '<';
        strncpy(&returnBuf[1], message, length);
        returnBuf[length + 1] = '>';
        serialWrite(returnBuf, length + 2);
    }
    
    // Write data to UART
    void serialWrite(const char *sendData, int length)
    {
        int i = 0;
        GPIO_setHigh(halHandle->gpioHandle, GPIO_Number_12);
        while (i < length)
        {
            if (SCI_txReady(halHandle->sciAHandle))
            {
                SCI_write(halHandle->sciAHandle, sendData[i]);
                i++;
            }
        }
        isWaitingTxFifoEmpty = true;
    }
    

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

    如果 您在添加 SCI 方面有任何疑问、可以查看如下所示 MotorWare 文件夹中的 HAL 用户指南、并参阅"6.7"章节。 通过 Motorware 中的 InstaSPIN 向项目添加 SCI/UART 功能。

    motorware_hal_tutorial.pdf、位于"\ti\motorware\motorware_1_01_00_18\docs\tutorware\hal_tutorial.pdf"