• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

How Do I Use The MCPWM Module Of The ESP32 Capture Feature To Measure PWM Signals Within The Arduino IDE

Q&A Forum › Category: ESP32 › How Do I Use The MCPWM Module Of The ESP32 Capture Feature To Measure PWM Signals Within The Arduino IDE
0 Vote Up Vote Down
MANUEL MURO asked 6 months ago

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! 🙂

Question Tags: CAPTURE, MCPWM, MEASURE, PWM
3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 months ago

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

0 Vote Up Vote Down
MANUEL MURO answered 6 months ago

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!!! 😀

0 Vote Up Vote Down
Sara Santos Staff answered 6 months ago

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

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Download Build Web Servers with ESP32 and ESP8266 (2nd Edition) February 8, 2021
  • [eBook Released] Build Web Servers with ESP32 and ESP8266 (version 1.0) October 27, 2020

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2021 · RandomNerdTutorials.com · All Rights Reserved