Path: EDN Asia >> Design Ideas >> IC/Board/Systems Design >> Swapping bits boosts performance of FPGA-PWM counter
IC/Board/Systems Design Share print

Swapping bits boosts performance of FPGA-PWM counter

12 May 2016  | Stefaan Vanheesbeke

Share this page with your friends

When you need some analogue outputs and you have an FPGA in your system, you probably choose to use a PWM module and a simple lowpass filter such as those in the figure. The output of the FPGA is typically a waveform with a fixed-frequency, variable-duty cycle, which a counter and a digital comparator generate (listing 1).

Figure: A simple lowpass filter changes the PWM digital output from an FPGA to an analogue voltage level. The maximum ripple occurs at a 50% duty cycle.

Suppose that Enable is high, the counter counts up every clock cycle, and the frequency of the PWM output is the clock frequency divided by 2 count bits. You can use Enable to lower the output frequency by connecting it to a prescaler. Because the output frequency is fixed, the filter is easy to calculate, because you know that the worst-case ripple happens at a duty cycle of 50%. The combination of the desired maximum ripple and settling time determines the filter type and RC (resistance/capacitance) values.

Listing 1: FPGA output.

With a small change to the code in listing 1, you can improve the performance of the PWM circuit. Whereas in the original system, the maximum ripple currents occur at a duty cycle of 50% and the minimum ripple currents occur at the minimum duty cycle, the improved version shows a maximum ripple equal to the minimum of the standard version. The trick is to generate the highest frequency possible but keep the average duty cycle constant. The higher the frequency of the pulses on the output, the better the filter does its job.

Listing 2: Rewiring modification.

The modification to listing 1 consists of rewiring the binary comparator with all the bits swapped from left to right. The MSB (most significant bit) becomes the LSB (least significant bit), the LSB becomes the MSB, and so on (listing 2). You do only a rewiring requiring no extra registers or logic.

Listing 3: Simulation results.

Listing 3 shows the pulse trains that a 4bit PWM emits. In listing 3, you see that at 50% duty cycle (Value=8, second column), the frequency is maximum and equal to the clock frequency divided by two. At the first point at which some ripple shows up (Value=1, second column), there is exactly the same ripple as in the conventional PWM system—that is, the pulse train is the same.

About the author
Stefaan Vanheesbeke contributed this article.

This article is a Design Idea selected for re-publication by the editors. It was first published on September 13, 2007 in

Want to more of this to be delivered to you for FREE?

Subscribe to EDN Asia alerts and receive the latest design ideas and product news in your inbox.

Got to make sure you're not a robot. Please enter the code displayed on the right.

Time to activate your subscription - it's easy!

We have sent an activate request to your registerd e-email. Simply click on the link to activate your subscription.

We're doing this to protect your privacy and ensure you successfully receive your e-mail alerts.

Add New Comment
Visitor (To avoid code verification, simply login or register with us. It is fast and free!)
*Verify code:
Tech Impact

Regional Roundup
Control this smart glass with the blink of an eye
K-Glass 2 detects users' eye movements to point the cursor to recognise computer icons or objects in the Internet, and uses winks for commands. The researchers call this interface the "i-Mouse."

GlobalFoundries extends grants to Singapore students
ARM, Tencent Games team up to improve mobile gaming

News | Products | Design Features | Regional Roundup | Tech Impact