VHDL PWM generator

$ 0

This VHDL module generates a pulse-width modulation (PWM) signal with generic counter length and run-time configurable frequency.

Category: Tags: ,

Description

The pwm.vhd module uses pulse-width modulation (PWM) to exert precise control of the average current flowing through an analog device.

Example use cases for the module are audio modulation (speakers), light intensity control (lamps or LEDs), and induction motors. The latter includes servo motors, computer fans, pumps, brushless DC motors for electric cars.

In addition to the testbench, the Zip contains an example implementation for the Lattice iCEstick FPGA board. The demo design controls the illumination intensity of an onboard LED on the iCEstick. The LED will illuminate gradually and turn off abruptly before the sawtooth pattern repeats itself.

Entity

entity pwm is
  generic (
    -- PWM and duty cycle counter bit length
    pwm_bits : integer;
 
    -- Clock divider max count
    -- Set to 1 to disable clock divider logic
    -- pwm_hz = clk_hz / (2**pwm_bits - 1) / clk_cnt_len
    clk_cnt_len : positive := 1
  );
  port (
    clk : in std_logic;
    rst : in std_logic;
    duty_cycle : in unsigned(pwm_bits - 1 downto 0);
    pwm_out : out std_logic
  );
end pwm;

Main article

Click here to read more about how I created this module:
How to create a PWM controller in VHDL

Download request form

Need the ModelSim/Questa project files?

Let me send you a Zip with everything you need to get started in 30 seconds

How does it work?

Tested on Windows and Linux Loading Gif.. How it works

    Unsubscribe at any time

    License agreement

    MIT License

    Copyright (c) 2022 Jonas Julian Jensen

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    Reviews

    There are no reviews yet.

    Be the first to review “VHDL PWM generator”

    Your email address will not be published.