Filtered PDM (duty-cycle counter mode) is far better than filtered PWM. PWM filters noisily in the mid-level range, worst when set at 50%, therefore it requires an oversized capacitor to compensate. This of course makes the filter response much slower. Whereas PDM has consistence noise at all set levels, allowing for an optimised filter.
Comments
Hi,
Pwm plus a RC Filter does the trick.
Filtered PDM (duty-cycle counter mode) is far better than filtered PWM. PWM filters noisily in the mid-level range, worst when set at 50%, therefore it requires an oversized capacitor to compensate. This of course makes the filter response much slower. Whereas PDM has consistence noise at all set levels, allowing for an optimised filter.
Here's an example using counterB. It's configured for 0 to 10000. If you prefer 16-bit resolution then just delete the scaling line from dacset().
Oops, small bug - DIRA should be OR'd with rather than overwritten.
or clearer still