0

PWM optimised for analogue output
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PWM optimised for analogue output

by kevinjwalters on Mon May 10, 2021 8:46 am

Has anyone looked into optimising PWM for use as an analogue output? I was thinking about reducing ripple by distributing the high periods of the duty cycle, i.e. if resolution is 1/8ths of a cycle and output is 25% duty cycle (16384 in CircuitPython's range), this

Code: Select all | TOGGLE FULL SIZE
||
+++++++++


becomes

Code: Select all | TOGGLE FULL SIZE
|   |
+++++++++


I realise this could be done to some extent with variable_frequency but it would be easier if it was done under the covers particularly if the hardware has features to support this efficiently.

kevinjwalters
 
Posts: 965
Joined: Sun Oct 01, 2017 3:15 pm

Re: PWM optimised for analogue output

by adafruit_support_bill on Mon May 10, 2021 9:09 am

If I understand correctly, what you are describing is equivalent to simply doubling the PWM frequency. The duty-cycle remains the same. The pulses are just half as long.

adafruit_support_bill
 
Posts: 81605
Joined: Sat Feb 07, 2009 10:11 am

Re: PWM optimised for analogue output

by kevinjwalters on Mon May 10, 2021 1:27 pm

In that case, but for pwm.duty_cycle = 24576 I'd expect something like

Code: Select all | TOGGLE FULL SIZE
|  |  |
++++++++


It could be branded as PDM.

BTW, I intended to put this in the Adafruit CircuitPython and MicroPython forum, if you could move it over there that would be great.

kevinjwalters
 
Posts: 965
Joined: Sun Oct 01, 2017 3:15 pm

Re: PWM optimised for analogue output

by adafruit_support_bill on Mon May 10, 2021 1:39 pm

[topic moved]

I don't know of any processors that would have direct hardware support for that. You could implement it in software. Or perhaps even using some DMA magic on processors that support it. But I don't think it would buy you any improvement over just increasing the base frequency and using straight hardware PWM.

adafruit_support_bill
 
Posts: 81605
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.