MCPWM - how to get the output state of PWMxA or PWMxB

rob_bits
Posts: 16
Joined: Wed Jun 13, 2018 5:15 am

MCPWM - how to get the output state of PWMxA or PWMxB

Postby rob_bits » Mon Dec 19, 2022 11:00 am

I have unique measurement device where an ESP32-Wrover is used to control and acquire signals in the application. I am using the MCPWM peripheral to configure a PWM signal for a LED diode. And I have photodiodes connected to an SPI ADC. The driving of the diodes and the acquisition must be synchronized. And there is configurable phase shift between the excitation of the LED and the sampling of the signal. A phase shift is implemented with a second channel of the MCPWM module (PWM0A is used to drive LED and PWM0B has a phase shift for evaluation algorithm). The SPI acquisition is going with a predefined period, at the end of transaction an interrupt is triggered and at this point I would like to sample the PWM0B signal. For SPI interface I wrote my low level driver by configuring the SPI interface on register level (based on the code of spi_ll.h).

My question, how can I get the status of the PWM0B signal?

I know I can easily read the GPIO state of the signal, but if I do not route out the PWM0B signal to any GPIO, then how can I access the state of the signal?

My application is complex, regarding the timing of the measurement and synchronization of PWM signals, so I do not look other solutions. I would just like to know if I can read any register to get the state of the PWM0A or PWM0B signals. I started to read the TIMER0 register, so I can get the state of the timer, but I have to apply a software logic, based on the configuration of MCPWM module, to decide if the PWM0B was on high level or low level during sampling of the TIMER0 register.

Any advice would be welcomed.

Thanks!

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: MCPWM - how to get the output state of PWMxA or PWMxB

Postby ESP_Sprite » Tue Dec 20, 2022 3:20 am

You could use an unused GPIO. If you're not using a ESP32-Pico-xx SoC, GPIO20 is a GPIO that is internal-only and you can use it for that.

rob_bits
Posts: 16
Joined: Wed Jun 13, 2018 5:15 am

Re: MCPWM - how to get the output state of PWMxA or PWMxB

Postby rob_bits » Tue Dec 20, 2022 8:33 am

Hey,

thanks for the response. I am using the ESP32-WROVER-IE-N16R8 with ethernet connection and all digital output pins are used. The SENSOR_VN and SENSOR_VP does not have any connection in the design.

The wrover does not have GPIO20, can I use it still? Or is there any internal-used GPIO for this purpose?
Like, GPIO1, GPIO3, GPIO6, GPIO7 ...etc?

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: MCPWM - how to get the output state of PWMxA or PWMxB

Postby ESP_Sprite » Tue Dec 20, 2022 9:00 am

rob_bits wrote:
Tue Dec 20, 2022 8:33 am
The wrover does not have GPIO20, can I use it still? Or is there any internal-used GPIO for this purpose?
Yes, you can. It's an internal GPIO and (unless you use an ESP32-Pico SoC, which you are not) it's not used elsewhere to my knowledge.
Like, GPIO1, GPIO3, GPIO6, GPIO7 ...etc?
Actually entirely *un*like those GPIOs, as those that you mentioned are used for other things (GPIO1 = U0TXD, GPIO3 = U0RXD, GPIO6/7 connect to flash memory etc). GPIO20 is not even available as a pin on the ESP32 chip in that model so you can freely use it for 'loopback', unlike the other pins you mention (if you use those you either crash the ESP because it can't talk to its flash, or you won't get proper serial communication anymore)

rob_bits
Posts: 16
Joined: Wed Jun 13, 2018 5:15 am

Re: MCPWM - how to get the output state of PWMxA or PWMxB

Postby rob_bits » Tue Dec 20, 2022 10:44 am

Cool, great. This simplifies a lot. Thanks.

Btw, is there any other "loopback" GPIO? And is there any documentation about this GPIO20?

Thanks!

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: MCPWM - how to get the output state of PWMxA or PWMxB

Postby ESP_Sprite » Wed Dec 21, 2022 1:51 am

No, sorry. And there's not really any documentation on GPIO20 as it's a GPIO like any other; it just happens to not be bonded out to anything on non-Pico ESP chips. It's the only GPIO of this type, to my knowledge.

Who is online

Users browsing this forum: fengcai and 83 guests