Does anyone have a good solution for measuring a continues PWM signal?

Ravenholem
Posts: 20
Joined: Wed Nov 10, 2021 7:13 pm

Does anyone have a good solution for measuring a continues PWM signal?

Postby Ravenholem » Tue Aug 08, 2023 12:18 pm

Hello,
I have been trying to come up with a good clean way to measure PWM input to my device. I need both Frequency and Pulse width.
On the normal ESP32 I was able to use MCPWM but on the C3 and S2 the MCPWM does not exist. I have tried to experiment with RMT and it hasn't went as well as I expected.

I input a PWM signal into my device that never stops. It will vary in frequency and pulse width and that is it.
I have a frequency and Pulse with range that is accepted as normal and anything above or below that needs to be flagged as error so that user can be notified that the input is out of specs.

I have done some digging around trying to find a way to do this with a peripheral so I could avoid the old, Edge Detection Timer tick combo that will be firing interrupt all the time.

Any help would be appreciated, I know someone has found a good solution.

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Does anyone have a good solution for measuring a continues PWM signal?

Postby ESP_igrr » Tue Aug 08, 2023 1:19 pm

I haven't tried with PWM, but I did use RMT peripheral on the ESP32 to receive a multi-channel PPM signal from an RC receiver. I guess with PWM it should be even easier. Can you describe the issues you ran to when trying to use RMT to receive PWM?

Ravenholem
Posts: 20
Joined: Wed Nov 10, 2021 7:13 pm

Re: Does anyone have a good solution for measuring a continues PWM signal?

Postby Ravenholem » Sat Aug 12, 2023 9:08 pm

ESP_igrr wrote:
Tue Aug 08, 2023 1:19 pm
I haven't tried with PWM, but I did use RMT peripheral on the ESP32 to receive a multi-channel PPM signal from an RC receiver. I guess with PWM it should be even easier. Can you describe the issues you ran to when trying to use RMT to receive PWM?
Thank you for taking time to respond.
I have gotten things working to the point that I can get Pulse Width and calculate Frequency based on period and these are accurate enough.

I have been playing with what is offered in the ESP32s2 RMT peripheral to attempt to get a solid PWM capture unit.

I have came across something that I can't seem to figure out the answer to, here is the scenario
If I have RMT in Receive State and its receiving PWM once the memory is full the FSM State changes to Wait. Once in Wait state I reset the memory index using rmt_rx_memory_reset(RMT_CHANNEL_0) when I check the RMT_CHnSTATUS_REG and I can see that the flag for Memory full is gone.
Though the FSM is still in the Wait state. I can't find anyway to get it out of the wait state. If I change the PWM signal being fed into the device to something that triggers the RMT_CH0_RX_END_INT_ST ISR I can see the FSM in RMT_CHnSTATUS_REG change from Wait to Idle state.

Hope this make sense.
My Orginal idea was to have RMT just running and when I wanted a sample I would just reset the memory index and read from the first Item from the memory on the next time through my Loop. I'm doing about 10 samples per second and averaging.

UPDATE:
Hey ESP_igrr this is the exact same thing I am dealing with
viewtopic.php?t=5168
They had issues with the RX buffer being full causing the RMT to go into Wait state and will not come out.

ESP_morris
Posts: 290
Joined: Wed Sep 05, 2018 6:23 am

Re: Does anyone have a good solution for measuring a continues PWM signal?

Postby ESP_morris » Mon Aug 14, 2023 4:15 am

rmt_rx_memory_reset(RMT_CHANNEL_0) will reset the whole RMT FIFO memory. It should only be called for once in the initialization stage.

Not sure what esp chips you're working with, ESP32S2? ESP32C3? But please note, ESP32-S2's RMT RX channel doesn't support ping-pong receive. The maximum RMT symbols you can receive for once is 4*64 words. And when it receives more data, I think an error interrupt will be raised. Reseting the pointer is not sufficient, you also need to clear the interrupt.

Check the driver code here: https://github.com/espressif/esp-idf/bl ... #L518-L529

Who is online

Users browsing this forum: Orange_Murker, slaboure and 85 guests