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.

MOTORWARE: Bug in driver code

Part Number: MOTORWARE
Other Parts Discussed in Thread: DRV8301,

I came across a bug in drv8301.c. (file from C:\ti\motorware\motorware_1_01_00_18\sw\drivers\drvic\drv8301\src\32b\f28x\f2806x)

For an instance the following code snippet doesn't work as expected, the return value will always be default enum/0.

DRV8301_ShuntAmpGain_e DRV8301_getShuntAmpGain(DRV8301_Handle handle)
{
 uint16_t data;

 // read data
 data = DRV8301_readSpi(handle,DRV8301_RegName_Control_2);

 // clear the bits
 data &= (~DRV8301_CTRL2_GAIN_BITS);

 return((DRV8301_ShuntAmpGain_e)data);
}



-->  data &= (~DRV8301_.............);


The above line makes the "data" contain value excluding the interested bit field(s) and on return, the data will be '0'.

Similar such bug can be pointed out in various other functions within the file.
Regards,
Madhan.
  • Are you working on the TI EVM board or your own board? 

    You might set gDrvSpi8301Vars.RcvCmd to 1 in the watch window and check the values in the gDrvSpi8301Vars object. 

  • Hi Yanming Luo,

    Thank you for the response.

    I'm using BoostXL DRV8301 REV B. EVM in my work.

    I agree, that setting gDrvSpi8301Vars.RcvCmd to 1 in the watch window, will return the actual value of the internal register as the function implementation is correct. But on the other hand, the same file has the wrong implementation of extracting the interested bit fields.

    If I need to know only one data from the corresponding register and modify the same on the go within a constrained time frame like a PWM period, reading all registers and variables isn't good. Also, this is something so basic in bitwise operation.

    Regards,

    Madhan.

      

  • You are right. There are some bugs, you might remove the "~" in all of the "DRV8301_get" functions like below in DRV8301_getShuntAmpGain();

    Change

    data &= (~DRV8301_CTRL2_GAIN_BITS);

    to

    data &= DRV8301_CTRL2_GAIN_BITS;