PWM optimised for analogue output

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
kevinjwalters
 
Posts: 1024
Joined: Sun Oct 01, 2017 3:15 pm

PWM optimised for analogue output

Post by kevinjwalters »

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

||
+++++++++
becomes

Code: Select all

|   |
+++++++++
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.

User avatar
adafruit_support_bill
 
Posts: 84980
Joined: Sat Feb 07, 2009 10:11 am

Re: PWM optimised for analogue output

Post by adafruit_support_bill »

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.

User avatar
kevinjwalters
 
Posts: 1024
Joined: Sun Oct 01, 2017 3:15 pm

Re: PWM optimised for analogue output

Post by kevinjwalters »

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

Code: Select all

|  |  |
++++++++
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.

User avatar
adafruit_support_bill
 
Posts: 84980
Joined: Sat Feb 07, 2009 10:11 am

Re: PWM optimised for analogue output

Post by adafruit_support_bill »

[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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”