Input capture on GTIOxA and GTIOxB

I have a application where I need to read the frequency on both pins. How can I switch at runtime the selected Input?

The Input is configured: 

Reading lastCaptureGet() works fine

I tried 

gpt_input_capture_extend_t * pFan12Extend;

pFan12Extend = g_inputFan12.p_cfg->p_extend;

if(pFan12Extend->signal == GPT_INPUT_CAPTURE_SIGNAL_PIN_GTIOCA) {

// switch to other pin

result += g_inputFan12.p_api->close(g_inputFan12.p_ctrl);



result += g_inputFan12.p_api->open(g_inputFan12.p_ctrl, g_inputFan12.p_cfg);

} else {

// read speed

result = g_inputFan12.p_api->lastCaptureGet(g_inputFan12.p_ctrl, &speedFan2);

// switch to other pin

result += g_inputFan12.p_api->close(g_inputFan12.p_ctrl);


result += g_inputFan12.p_api->open(g_inputFan12.p_ctrl, g_inputFan12.p_cfg);


But that is not working...

Parents Reply Children
  • Hello Andreas, I hope you're doing well. 

    First of all, we need to investigate how SSP code generator configures the input capture module. I've repeated your steps and configured the program as you did. As you know, we're dealing with two major structure instances, 'g_inputFan12.p_ctrl' and 'g_inputFan12.p_cfg,' containing all the configuration and parameters the input capture module deals with. These instances are initialized by the code generator, and you can find the related code in 'new_thread0.c' file (The thread configuration file, which the module stack resides). 

    You already know that 'g_inputFan12_extend' contains the exact parameters needed to change the GPIOCA/GPIOCB pin and is embedded in the 'g_inputFan12_cfg' structure instance. We use the 'open()' API function to initiate a GPT channel, passing p_cfg and p_ctrl parameters to the function. The 'close()' function eliminates it and makes it ready for reconfiguration. Within the 'open()' function, the 'gpt_input_capture_hardware_initialize()' function sets up the GPT hardware based on our configuration (You might like to take a look at it).

    The issue with your code is that you're modifying the 'g_inputFan12.p_cfg->p_extend' structure by making a pointer to it (pFan12Extend). Unfortunately, the 'g_inputFan12.p_cfg->p_extend' instance is 'static const' type, and all its objects are stored in the ROM area, making them read-only. Since we cannot edit the auto-generated codes and we're not going to mess up with Input Capture driver codes, my suggestion is to make a clone instance of the code shown in the figure above and bring it to your application, modify its '.signal' value to 'GPT_INPUT_CAPTURE_SIGNAL_PIN_GTIOCB/A,' and then reconfigure the driver with that new struct instance each time you want to change the GPIOCA to GPIOCB.

    It's recommended to check for the operation of changing the signal pin in a simpler manner first, then elaborate on your code and utilize it in a real application. I hope you find this helpful. Don't hesitate to ask questions if needed.

    Best regards, Hossein.