Using I2C causes issues with MCPWM Capture.

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

Using I2C causes issues with MCPWM Capture.

Postby Ravenholem » Fri Jan 26, 2024 1:51 pm

Hello everyone!
So while working on a project I came across something I can't seem to explain.
The Scope of work is as follows:
I retrieve data from a sensor over I2C. (I use this library https://github.com/UncleRus/esp-idf-lib to help make things easier)
Using MCPWM Capture 0, I capture a PWM input signal on Negative Edge and get its period to calculate frequency.
I take that Frequency value and modify it as needed and output it using LEDC at 50% duty.

The strange behavior I am experiencing:
I setup and initialize the MCPWM capture and LEDC.
I setup and internalize I2C using the library.
The MCPWM and LEDC part of the code works perfect. I capture a 5khz frequency and I output expected 5khz frequency.

If I start using the I2C bus to do anything say Read from a sensor. I start seeing random captures of 23khz on my MCPWM Capture.
Looking at the PWM input with a scope and triggering a pin every time a capture happens shows that MCPWM triggers on the Falling Edge of my PWM then again on the next Rising edge. This should NOT be happening. The MCPWM is set up to only trigger on falling edges so that I can calculate the period. If I stop sending any data through I2C this issue goes away and the MCPWM captures as normal.

My input PWM signal has a sloped knee shaped rising edge and a sharp falling edge.

In the attached picture you can see what I am describing.
The "Purple" trace is the PWM signal at the chip pin.
The "Yellow" trace is the MCPWM Capture unit ISR toggling a PIN every time it fires.
As you can see in the picture it will sporadically fire twice and this is the issue causing all my trouble.
Attachments
RigolDS0.png
RigolDS0.png (69.34 KiB) Viewed 754 times

Who is online

Users browsing this forum: MicroController and 110 guests