Clean PWM input capture

I am trying to get the signalcapture function to work to detect a PWM input and decode the duty but the readings are a little noisy. I am using this duty cycle reading to drive an LED with PWM at 20Khz.

I am using a super stable arbitrary waveform generator (SDG1025) to create the PWM input and on the scope this is rock solid. Because of the noise from the function, the LED’s at low brightness flicker.

Has anyone used the signal capture before and or know of some other option to determine PWM duty cycle with a much cleaner input?

This is running on a Cerbuino Bee module.

The STM32 inherently has some effective measurement modes, the part’s “PWM Input” mode pairs two timer channels to provide the period and duty, resetting at each interval, and allowing you to read the CCR1/CCR2 registers without interrupts. The granularity of the counter will be determined by the time base. The F4 on the Cerb Bee has TIM2 that is 32-bit wide clocking at 84-MHz, should provide a lot of range/resolution.

You can get an interrupt or periodically poll.

You’d have to look at which timer you are using, in which mode, and clocking at what time base.

Setup PWM capture using the Register Class. I’ve set it up on a cerb40ii and it’s working. Albeit, it’s a bit funky to setup.

Check out my thread here with some sample code:
https://www.ghielectronics.com/community/forum/topic?id=22874