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.

Reading external push button

Other Parts Discussed in Thread: MOTORWARE

I am using InstaSpin motorware lab 5b to run my motor. In the board I have added an external switch connected to GPIO 7 which I want to use to turn on and off the motor. I followed the procedure given in the HAL tutorial document.

In hal.c I have

GPIO_setMode(obj->gpioHandle,GPIO_Number_7,GPIO_7_Mode_GeneralPurpose);

In hal.h I creaded this funciton

static inline bool HAL_readGpio(HAL_Handle handle, const GPIO_Number_e gpioNumber)
{
HAL_Obj *obj = (HAL_Obj*)handle;
return (GPIO_read(obj->gpioHandle, gpioNumber));

}//End of Read GPIO Pin function.

And in project_lab5b.c I added these lines:

bool gOnOff;

.

.

.

for(;;)
{
// enable or disable the system
gOnOff = HAL_readGpio(halHandle, GPIO_Number_7);
if (gOnOff==true)
{
gMotorVars.Flag_enableSys = true;
gMotorVars.Flag_Run_Identify = true;
}
else
{
gMotorVars.Flag_enableSys = false;
gMotorVars.Flag_Run_Identify = false;
}

.

.

.

I did not define the GPIO7 the way  it was done in the pdf, because I felt that it was unnecessarily increasing the complexity. But when I started the debug session, the gOnOff is always zero. I added an LED on my  switch to make sure  that it is indeed working properly. So no problems on hardware side. The system simply does not read anything on the pin.

If I force the two flags to 1 from CCS debug window, the motor that was running before I  added this code doesn't run with this new patch in. I have added a POT to control the speed which seems to be working properly, but with this patch of code in, nothing is happening. 

  • It looks like the code that you have for reading the GPIO is fine.  Is HAL_readGpio(halHandle, GPIO_Number_7) being called more than once?  In lab5b in the for(;;) loop, right away in the code, there is a statement while(!(gMotorVars.Flag_enableSys));.  If this statement is still there, then the code that you added will only be called once until gMotorVars.Flag_enableSys is true.  I would recommend just setting gMotorVars.Flag_enableSys()=true before for(;;) and then use the GPIO read to set or clear gMotorVars.Flag_Run_Identify.

    -Eric

  • Eric,

    I made some changes to the code, but it seems that my  problem is something  very different.

    I changed the project_lab5b.c code to read:

    if(gMotorVars.UserErrorCode != USER_ErrorCode_NoError)

       {

         for(;;)

           {

             gMotorVars.Flag_enableSys = false;

           }

       }

     else  // Added this part so that the flag will be automatically set if there are no errors.

     {

     gMotorVars.Flag_enableSys = true;

     }

    Then at the very beginning of the forever loop, before it even checks if the Flag_enableSys is true or not, I have this portion:

    for (;;)

    {

    // enable or disable the system

                  gOnOff = HAL_readGpio(halHandle, GPIO_Number_7);

                             if (gOnOff==true)

                             {

                             gMotorVars.Flag_Run_Identify = true;

                             }

                             else

                             {

                             gMotorVars.Flag_Run_Identify = false;

                             }

    The rest of the functions are the same. I added similar function to control direction which worked independently on another system.

    I realized that the problem is with user.h. It is completely grayed out. When I tried to access the header files being called from user.h, the compiler is unable to access them even though I can see them in windows explorer so I know that they are physically present. I was able to run the motor couple of days ago by changing parameters in user.h. I know it works because when I put wrong value it did give me an error and ran properly  after I corrected it. I haven't changed anything in those parts. Only addition was the code above. Do you have any  idea what might be going wrong?

  • this user.h problem was moved to a new thread
    e2e.ti.com/.../1588788