While I have been able to use the PWM feature of the EPS32’s MCPWM module, I have been struggling to find a good reference to take advantage of the Capture feature of the MCPWM module that would allow me to measure how long a PWM signal is low as well as how long a PWM signal is high via captures of the 32-bit timer. it is also my understanding that an interrupt routine can be used to capture the timer capture events, so if it is possible to include how to setup the interrupt handling for this Capture Event interrupt that would also be VERY helpful! 🙂
Hi Manuel.
To be honest, I’ve never experimented with that module.
What do you have so far? Have you experimented any code?
Are you following this reference: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/mcpwm.html#capture ?
Regards,
Sara
Hi Sara,
  Yes, I was already familiar with that link, but that is not really a complete answer as I want to be able to access those functions with the Arduino IDE environment, which is where I am currently developing the code. However, to use the information on the link you provide, I will have to switch over to developing my code in the ESPressif development environment. While that is certainly an option, I would prefer to stay in the Arduino IDE environment. Maybe someone at RNTLabs can put together some example code? I am mainly a hardware person and too often tracking down the “*.h” files can be a challenge for me and too often when moving between one IDE and the other the API’s change, both the function names and the API specific defines tend to change. Thanks in advance for any help that you can provide!!! 😀
Hi.
You can use those functions in Arduino IDE:
You just need to include the following:
#include "driver/mcpwm.h"
Then, you can use those functions.
Accordingly to the documentation you have to do something like this:
Init MCPWM in your desired GPIO:
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, GPIO_OUT);
Enable capture:
mcpwm_capture_enable(MCPWM_UNIT_0,MCPWM_SELECT_CAP0, MCPWM_NEG_EDGE, 0);
Get the value:
unsigned int number = mcpwm_capture_signal_get_value(MCPWM_UNIT_0,MCPWM_SELECT_CAP0);
Please see the meaning of each parameter on the documentation.
Regards,
Sara