Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Algorithm for finding optimal PWM resolution and frequency?

Status
Not open for further replies.

misterT

Well-Known Member
Most Helpful Member
I'm currently working with a digital control problem that requires fast and accurate PWM output. In microcontrollers PWM signal is usually generated with a counter and two register values that define the on-time and the period of the generated signal.

In my case I have a 16 bit counter with 50 Mhz clock (giving me 20ns resolution). Register COMPARE defines the on-time of the pwm signal and TOP defines the period of the signal. With these values it is possible to calculate the frequency and duty of the generated PWM signal:

frequency = (50 Mhz) / TOP
duty = COMPARE / TOP

Now, I'm looking for an (online) algorithm to find the best (TOP, COMPARE) pairs to generate the desired PWM signal within certain frequency (and other) limits (lets say 250 kHz to 500 kHz).

For example, it is easy to see that for 50% duty the best setting is (100, 50) giving frequency of 500 kHz and duty of 50% with no error. I have written a program that creates a lookup table for all the duty cycles, but the table is very large and not flexible (10bit resolution creates a table of 2048 Bytes).

Has anyone heard of such algorithm?
Does anyone have ideas for developing the algorithm?

My specific requirements for the generated PWM signal are:

- 10 bit resolution for the duty-cycle.
- Frequency between 250kHz ... 500kHz.
- Duty-cycle between 0% ... 75%.
- Duty-cycle updated every 100us.
- Duty-cycle can change to any value between [0%, 75%] when it is updated.
- Frequency can change to any value between [250kHz, 500kHz] when duty-cycle is updated.
- On-time should not change more than 10% when duty-cycle is updated.

The last requirement can be omitted, but would be very useful in many control systems.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top