📄 pwm_m8.vhd
字号:
-----------------------------------------------------------------------
-- PWM_M8.vhd
-- --------------------------------------------------------------------
-- >>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<
-- --------------------------------------------------------------------
-- Copyright (c) 2005 by Lattice Semiconductor Corporation
-- --------------------------------------------------------------------
--
-- Permission:
--
-- Lattice Semiconductor grants permission to use this code for use
-- in synthesis for any Lattice programmable logic product. Other
-- use of this code, including the selling or duplication of any
-- portion is strictly prohibited.
--
-- Disclaimer:
--
-- This VHDL or Verilog source code is intended as a design reference
-- which illustrates how these types of functions can be implemented.
-- It is the user's responsibility to verify their design for
-- consistency and functionality through the use of formal
-- verification methods. Lattice Semiconductor provides no warranty
-- regarding the use or functionality of this code.
--
-- --------------------------------------------------------------------
--
-- Lattice Semiconductor Corporation
-- 5555 NE Moore Court
-- Hillsboro, OR 97214
-- U.S.A
--
-- TEL: 1-800-Lattice (USA and Canada)
-- 408-826-6000 (other locations)
--
-- web: http://www.latticesemi.com/
-- email: techsupport@latticesemi.com
--
-- --------------------------------------------------------------------
--
-- This is a Mico8 peripheral that controls a 8-bit PWM
-- Address map:
-- 00001000: PWM duty cycle register
-- --------------------------------------------------------------------
--
-- Revision History :
-- --------------------------------------------------------------------
-- Ver :| Author :| Mod. Date :| Changes Made:
-- V1.1 :| G.M. :| 13/03/08 :| Release
-- --------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity pwm_M8 is
port (
Clk : in std_logic;
Reset : in std_logic;
WR : in std_logic;
Addr: in std_logic_vector(7 downto 0);
Mico8_Data : in std_logic_vector (7 downto 0);
PWM_Out : out std_logic
);
end pwm_M8;
architecture behave of pwm_M8 is
signal duty, counter : std_logic_vector (15 downto 0);
signal pwm_on, zWR : std_logic;
constant div : std_logic_vector (15 downto 0) := "1111111111111111";
constant pwmaddress: std_logic_vector (7 downto 0) := "00001000";
attribute pgroup : string;
attribute pgroup of behave : architecture is "PWM";
begin
write: process (clk, reset, WR)
begin
if reset = '1' then
duty <= (others => '0');
zWR <= WR;
elsif clk'event and clk = '1' then
zWR <= WR;
if (zWR /= WR) and (WR = '0') then
if Addr = pwmaddress then
duty (7 downto 0) <= Mico8_Data(7 downto 0);
else
duty (15 downto 0) <= duty (15 downto 0);
end if;
end if;
end if;
end process;
divider: process (clk, reset)
begin
if reset = '1' then
counter <= (others => '0');
elsif clk'event and clk = '1' then
if counter >= 255 then
counter <= (others => '0');
else
counter <= counter + '1';
end if;
end if;
end process;
duty_cyle: process (clk, reset)
begin
if reset = '1' then
pwm_on <= '1';
elsif clk'event and clk = '1' then
if counter >= conv_integer (duty) then
pwm_on <= '0';
elsif counter = "0000000000000000" then
pwm_on <= '1';
else
pwm_on <= pwm_on;
end if;
end if;
end process;
pwm_out <= pwm_on;
end behave;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -