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: TMS320F28027with DRV8301 to run bldc motor

Part Number: TMS320F28027F
Other Parts Discussed in Thread: MOTORWARE

Tool/software:

Hi

"I have started working on UART commands to run the motor. I am using Lab11 in MotorWare and have added the SCI/UART from section 6.7 in the HAL tutorial. My question is, how do I write the logic for motor start and stop functions? Can someone guide me?"

  • That could be an detailed engineering question. You may just need to convert the command from UART to the control variables in example lab, like gMotorVars.Flag_Run_Identify to start/stop the motor, gMotorVars.SpeedRef_krpm to set the target running speed.

  • Hi Yanming Luo

    "I have written handleMotorCommands in the main.h file. If any modifications are needed, please let me know."

    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
    }

  • Looks good. Please let's know if you have any further questions.

  • Hi Yanming Luo

    "I have written in the main.c file. If any modifications are needed, please let me know."

    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;
    }
    

  • If have any further questions about adding SCI,  you may have a look at the HAL user's guide at the folder of the motorWare as below, and refer to chapter "6.7. Adding SCI/UART functionality to a project with InstaSPIN in Motorware.

    motorware_hal_tutorial.pdf at "\ti\motorware\motorware_1_01_00_18\docs\tutorials\motorware_hal_tutorial.pdf"