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.

TMS320F28069M: How to control the motor forward and backward by pressing the key?

Genius 3095 points
Part Number: TMS320F28069M
Other Parts Discussed in Thread: DRV8305

Dear sir:

I use F28069M and DRV8305 based on lab11e to control motor and I want to control the motor forward and reverse rotation by pressing the key. But after I added the below program in lab11e, it doesn't work:

void key_control(void)
{
    key_s1  = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_1);
    key_s2  = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_2);
    key_s3  = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_3);
    if(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x) ==LOW)
    {
        usDelay(50);
        if(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x)==LOW)
        {
            while(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x)==LOW);
            return LOW;
        }
        else
        return HIGH;
    }
    else
        return HIGH;
    while(1)
    {
        if(key_s1==LOW)
            {
             gMotorVars.SpeedRef_krpm = 0.8;
            }
        if(key_s2==LOW)
            {
                gMotorVars.SpeedRef_krpm = -0.8;
            }
        while(1)
        {
            if(key_s3==LOW)
               {
                  gMotorVars.SpeedRef_krpm = 0.8;
                  usDelay(500);
                  gMotorVars.SpeedRef_krpm = -0.8;
                  usDelay(500);
               }
        }
    }
}
1, Is there a problem with the program I wrote? How can I control the motor forward and reverse rotation by pressing the key?
2, Where can I change the reference speed? I had changed it as 0 ramp, But in the expression window it still shows 1800 ramp.
3, gHall_GpioData  = (~HAL_readGpio(halHandle, (GPIO_Number_e)HAL_HallGpio_C) & 0x1) << 2;
What is the result of gHall_GpioData?
  • As we replied in your another post, you may just add your own code to check the input of key without changing anything on the motor control algorithm in the original lab11e. Set the reference speed (gMotorVars.SpeedRef_krpm) to a positive or negative value for forwarding or reversing rotation according to the input signal of the key.

    It seems like you don't consider the noise on the input signal of the key, and the control logic is not correct also. I would recommend some MCU programming books to look though I don't have a specific one in mind. 

  • Dear Yanming

    Thank you for your reply.

    Some MCU programming books may useful for me. Would you give me some lists? Chinese books are better.