cover photo

BLOG · 19/1/2025

Resource article using Markdown

Mohith Monnappa T A
Mohith Monnappa T A
OP
Resource article using Markdown
This Article is yet to be approved by a Coordinator.

Pulse Width Modulation using Verilog

Pulse Width Modulation (PWM) is a technique used to control the speed or power of devices like DC motors in a simple yet effective way.

It works by rapidly turning the device on and off while varying the duration of the "on" state, represented as a percentage of the total cycle time. This percentage, known as the duty cycle, determines the average power delivered to the device.

PWM is crucial because it offers a simple and efficient way to control the power delivered to devices. Unlike traditional methods that use resistors to reduce voltage (which can waste energy as heat), PWM reduces power by switching the device on and off. This makes it highly energy-efficient and suitable for battery-powered devices.

PWM

Let's say we have a DC motor, and we want to make it spin at a variable speed. By applying PWM, we control how long the motor is powered on during each cycle.

For instance, with a 50% duty cycle, the motor is on for half the time, resulting in roughly half the speed. If we increase the duty cycle to 75%, the motor runs at 75% of its maximum speed.

By adjusting the duty cycle, we can smoothly vary the motor's speed, making it a versatile tool for applications like robotics, fan speed control, and even dimming lights.

Implementation in Verilog using Xilinx Vivado

Using the Concept of Counter

Using a counter to create a PWM (Pulse Width Modulation) signal is a straightforward and commonly used method. Here's how we can implement it.

  1. Counter Setup: First, we need a counter that counts up from 0 to a maximum value, typically referred to as the "period" or "cycle" value. The period value determines the time it takes for one complete cycle of the PWM signal. For example, if we want a PWM signal with a period of 16 clock cycles, our counter should count from 0 to 15.

  2. Duty Cycle Control: To control the duty cycle, we need another signal, often referred to as the duty_cycle value. This value is compared to the counter value. When the counter value is less than the duty_cycle value, the PWM output is high (on), and when it's equal to or greater than the duty_cycle value, the PWM output is low (off).

  3. PWM Output: The output of the PWM signal is taken from the comparison result. When the counter is less than the duty cycle value, the output is high (logical '1'), and when the counter is greater or equal to the duty_cycle value, the output is low (logical '0').

Verilog Code

Here,

  • 1 Mhz frequency is scaled to 500 Hz using the counter value given by,

countervalue= actual Frequency / desired Frequency

Example: 10,00,000 / (2 * 500) = 1000

  • 500 Hz is divided into 20 clock pulses for PWM generation.
  • pulse_width: A 4-bit input that specifies the duty cycle of the PWM signal. It can take values from 0 to 15.
Pulse_widthDuty cycle
00%
425%
1050%
1575%

UVCE,
K. R Circle,
Bengaluru 01