URL
https://opencores.org/ocsvn/w11/w11/trunk
Subversion Repositories w11
Compare Revisions
- This comparison shows the changes necessary to convert path
/w11/tags/w11a_V0.6/rtl/vlib/genlib
- from Rev 19 to Rev 24
- ↔ Reverse comparison
Rev 19 → Rev 24
/Makefile
0,0 → 1,29
# $Id: Makefile 477 2013-01-27 14:07:10Z mueller $ |
# |
# Revision History: |
# Date Rev Version Comment |
# 2011-08-13 405 1.2 use includes from rtl/make |
# 2007-12-09 100 1.1.1 drop ISE_p definition |
# 2007-06-03 47 1.1 use Makefile.xflow |
# 2007-06-03 45 1.0 Initial version |
# |
VBOM_all = $(wildcard *.vbom) |
NGC_all = $(VBOM_all:.vbom=.ngc) |
# |
# reference board for test synthesis is Spartan-6 based Nexys3 |
include $(RETROBASE)/rtl/make/xflow_default_nexys3.mk |
# |
.PHONY : all clean |
# |
all : $(NGC_all) |
# |
clean : ise_clean |
# |
#---- |
# |
include $(RETROBASE)/rtl/make/generic_xflow.mk |
# |
ifndef DONTINCDEP |
include $(VBOM_all:.vbom=.dep_xst) |
endif |
# |
/genlib.vhd
0,0 → 1,182
-- $Id: genlib.vhd 466 2012-12-30 13:26:55Z mueller $ |
-- |
-- Copyright 2007-2012 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
-- |
-- This program is free software; you may redistribute and/or modify it under |
-- the terms of the GNU General Public License as published by the Free |
-- Software Foundation, either version 2, or at your option any later version. |
-- |
-- This program is distributed in the hope that it will be useful, but |
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
-- for complete details. |
-- |
------------------------------------------------------------------------------ |
-- Package Name: genlib |
-- Description: some general purpose components |
-- |
-- Dependencies: - |
-- Tool versions: xst 8.1, 8.2, 9.1, 9.2, 11.4, 13.3; ghdl 0.18-0.29 |
-- Revision History: |
-- Date Rev Version Comment |
-- 2012-12-29 466 1.0.9 add led_pulse_stretch |
-- 2011-11-09 421 1.0.8 add cdc_pulse |
-- 2010-04-17 277 1.0.7 timer: no default for START,DONE,BUSY; drop STOP |
-- 2010-04-02 273 1.0.6 add timer |
-- 2008-01-20 112 1.0.5 rename clkgen->clkdivce |
-- 2007-12-26 106 1.0.4 added gray_cnt_(4|5|n|gen) and gray2bin_gen |
-- 2007-12-25 105 1.0.3 RESET:='0' defaults |
-- 2007-06-17 58 1.0.2 added debounce_gen |
-- 2007-06-16 57 1.0.1 added cnt_array_dram, cnt_array_regs |
-- 2007-06-03 45 1.0 Initial version |
------------------------------------------------------------------------------ |
|
library ieee; |
use ieee.std_logic_1164.all; |
|
use work.slvtypes.all; |
|
package genlib is |
|
component clkdivce is -- generate usec/msec ce pulses |
generic ( |
CDUWIDTH : positive := 6; -- usec clock divider width |
USECDIV : positive := 50; -- divider ratio for usec pulse |
MSECDIV : positive := 1000); -- divider ratio for msec pulse |
port ( |
CLK : in slbit; -- input clock |
CE_USEC : out slbit; -- usec pulse |
CE_MSEC : out slbit -- msec pulse |
); |
end component; |
|
component cnt_array_dram is -- counter array, dram based |
generic ( |
AWIDTH : positive := 4; -- address width |
DWIDTH : positive := 16); -- data width |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- clear counters |
CE : in slv(2**AWIDTH-1 downto 0); -- count enables |
ADDR : out slv(AWIDTH-1 downto 0); -- counter address |
DATA : out slv(DWIDTH-1 downto 0); -- counter data |
ACT : out slbit -- active (not reseting) |
); |
end component; |
|
component cnt_array_regs is -- counter array, register based |
generic ( |
AWIDTH : positive := 4; -- address width |
DWIDTH : positive := 16); -- data width |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- clear counters |
CE : in slv(2**AWIDTH-1 downto 0); -- count enables |
ADDR : in slv(AWIDTH-1 downto 0); -- address |
DATA : out slv(DWIDTH-1 downto 0) -- counter data |
); |
end component; |
|
component debounce_gen is -- debounce, generic vector |
generic ( |
CWIDTH : positive := 2; -- clock interval counter width |
CEDIV : positive := 3; -- clock interval divider |
DWIDTH : positive := 8); -- data width |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- reset |
CE_INT : in slbit; -- clock interval enable (usec or msec) |
DI : in slv(DWIDTH-1 downto 0); -- data in |
DO : out slv(DWIDTH-1 downto 0) -- data out |
); |
end component; |
|
component gray_cnt_gen is -- gray code counter, generic vector |
generic ( |
DWIDTH : positive := 4); -- data width |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- reset |
CE : in slbit := '1'; -- count enable |
DATA : out slv(DWIDTH-1 downto 0) -- data out |
); |
end component; |
|
component gray_cnt_4 is -- 4 bit gray code counter (ROM based) |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- reset |
CE : in slbit := '1'; -- count enable |
DATA : out slv4 -- data out |
); |
end component; |
|
component gray_cnt_5 is -- 5 bit gray code counter (ROM based) |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- reset |
CE : in slbit := '1'; -- count enable |
DATA : out slv5 -- data out |
); |
end component; |
|
component gray_cnt_n is -- n bit gray code counter |
generic ( |
DWIDTH : positive := 8); -- data width |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- reset |
CE : in slbit := '1'; -- count enable |
DATA : out slv(DWIDTH-1 downto 0) -- data out |
); |
end component; |
|
component gray2bin_gen is -- gray->bin converter, generic vector |
generic ( |
DWIDTH : positive := 4); -- data width |
port ( |
DI : in slv(DWIDTH-1 downto 0); -- gray code input |
DO : out slv(DWIDTH-1 downto 0) -- binary code output |
); |
end component; |
|
component timer is -- retriggerable timer |
generic ( |
TWIDTH : positive := 4; -- timer counter width |
RETRIG : boolean := true); -- re-triggerable true/false |
port ( |
CLK : in slbit; -- clock |
CE : in slbit := '1'; -- clock enable |
DELAY : in slv(TWIDTH-1 downto 0) := (others=>'1'); -- timer delay |
START : in slbit; -- start timer |
STOP : in slbit := '0'; -- stop timer |
DONE : out slbit; -- mark last delay cycle |
BUSY : out slbit -- timer running |
); |
end component; |
|
component cdc_pulse is -- clock domain cross for pulse |
generic ( |
POUT_SINGLE : boolean := false; -- if true: single cycle pout |
BUSY_WACK : boolean := false); -- if true: busy waits for ack |
port ( |
CLKM : in slbit; -- clock master |
RESET : in slbit := '0'; -- M|reset |
CLKS : in slbit; -- clock slave |
PIN : in slbit; -- M|pulse in |
BUSY : out slbit; -- M|busy |
POUT : out slbit -- S|pulse out |
); |
end component; |
|
component led_pulse_stretch is -- pulse stretcher for leds |
port ( |
CLK : in slbit; -- clock |
CE_INT : in slbit; -- pulse time unit clock enable |
RESET : in slbit := '0'; -- reset |
DIN : in slbit; -- data in |
POUT : out slbit -- pulse out |
); |
end component; |
|
end package genlib; |
/led_pulse_stretch.vhd
0,0 → 1,97
-- $Id: led_pulse_stretch.vhd 466 2012-12-30 13:26:55Z mueller $ |
-- |
-- Copyright 2012- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
-- |
-- This program is free software; you may redistribute and/or modify it under |
-- the terms of the GNU General Public License as published by the Free |
-- Software Foundation, either version 2, or at your option any later version. |
-- |
-- This program is distributed in the hope that it will be useful, but |
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
-- for complete details. |
-- |
------------------------------------------------------------------------------ |
-- Module Name: led_pulse_stretch - syn |
-- Description: pulse stretcher for leds |
-- |
-- Dependencies: - |
-- Test bench: - |
-- Target Devices: generic |
-- Tool versions: xst 13.3; ghdl 0.29 |
-- Revision History: |
-- Date Rev Version Comment |
-- 2012-12-29 466 1.0 Initial version |
------------------------------------------------------------------------------ |
|
library ieee; |
use ieee.std_logic_1164.all; |
use ieee.numeric_std.all; |
|
use work.slvtypes.all; |
|
entity led_pulse_stretch is -- pulse stretcher for leds |
port ( |
CLK : in slbit; -- clock |
CE_INT : in slbit; -- pulse time unit clock enable |
RESET : in slbit := '0'; -- reset |
DIN : in slbit; -- data in |
POUT : out slbit -- pulse out |
); |
end entity led_pulse_stretch; |
|
architecture syn of led_pulse_stretch is |
|
type regs_type is record -- state registers |
seen : slbit; -- DIN seen |
busy : slbit; -- POUT busy |
end record regs_type; |
|
constant regs_init : regs_type := ( |
'0', -- seen |
'0' -- busy |
); |
|
signal R_REGS : regs_type := regs_init; -- state registers |
signal N_REGS : regs_type := regs_init; -- next value state regs |
|
begin |
|
proc_regs: process (CLK) |
begin |
|
if rising_edge(CLK) then |
if RESET = '1' then |
R_REGS <= regs_init; |
else |
R_REGS <= N_REGS; |
end if; |
end if; |
|
end process proc_regs; |
|
proc_next: process (R_REGS, CE_INT, DIN) |
variable r : regs_type := regs_init; |
variable n : regs_type := regs_init; |
|
begin |
|
r := R_REGS; |
n := R_REGS; |
|
if CE_INT='1' then |
n.seen := DIN; |
n.busy := r.seen; |
else |
if DIN='1' then |
n.seen := '1'; |
end if; |
end if; |
|
N_REGS <= n; |
|
POUT <= r.busy; |
|
end process proc_next; |
|
end syn; |
/led_pulse_stretch.vbom
0,0 → 1,5
# libs |
../slvtypes.vhd |
# components |
# design |
led_pulse_stretch.vhd |
/gray_cnt_gen.vhd
0,0 → 1,90
-- $Id: gray_cnt_gen.vhd 418 2011-10-23 20:11:40Z mueller $ |
-- |
-- Copyright 2007- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
-- |
-- This program is free software; you may redistribute and/or modify it under |
-- the terms of the GNU General Public License as published by the Free |
-- Software Foundation, either version 2, or at your option any later version. |
-- |
-- This program is distributed in the hope that it will be useful, but |
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
-- for complete details. |
-- |
------------------------------------------------------------------------------ |
-- Module Name: gray_cnt_gen - syn |
-- Description: Generic width Gray code counter |
-- |
-- Dependencies: - |
-- Test bench: - |
-- Target Devices: generic |
-- Tool versions: xst 8.1, 8.2, 9.1, 9.2; ghdl 0.18-0.25 |
-- Revision History: |
-- Date Rev Version Comment |
-- 2007-12-26 106 1.0 Initial version |
------------------------------------------------------------------------------ |
|
library ieee; |
use ieee.std_logic_1164.all; |
|
use work.slvtypes.all; |
use work.genlib.all; |
|
entity gray_cnt_gen is -- gray code counter, generic vector |
generic ( |
DWIDTH : positive := 4); -- data width |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- reset |
CE : in slbit := '1'; -- count enable |
DATA : out slv(DWIDTH-1 downto 0) -- data out |
); |
end entity gray_cnt_gen; |
|
|
architecture syn of gray_cnt_gen is |
|
begin |
|
assert DWIDTH>=4 |
report "assert(DWIDTH>=4): only 4 or more bit width supported" |
severity failure; |
|
|
GRAY_4: if DWIDTH=4 generate |
begin |
CNT : gray_cnt_4 |
port map ( |
CLK => CLK, |
RESET => RESET, |
CE => CE, |
DATA => DATA |
); |
end generate GRAY_4; |
|
GRAY_5: if DWIDTH=5 generate |
begin |
CNT : gray_cnt_5 |
port map ( |
CLK => CLK, |
RESET => RESET, |
CE => CE, |
DATA => DATA |
); |
end generate GRAY_5; |
|
GRAY_N: if DWIDTH>5 generate |
begin |
CNT : gray_cnt_n |
generic map ( |
DWIDTH => DWIDTH) |
port map ( |
CLK => CLK, |
RESET => RESET, |
CE => CE, |
DATA => DATA |
); |
end generate GRAY_N; |
|
end syn; |
|
/gray_cnt_gen.vbom
0,0 → 1,9
# libs |
../slvtypes.vhd |
genlib.vhd |
# components |
gray_cnt_4.vhd |
gray_cnt_5.vhd |
gray_cnt_n.vhd |
# design |
gray_cnt_gen.vhd |
/cdc_pulse.vhd
0,0 → 1,117
-- $Id: cdc_pulse.vhd 426 2011-11-18 18:14:08Z mueller $ |
-- |
-- Copyright 2011- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
-- |
-- This program is free software; you may redistribute and/or modify it under |
-- the terms of the GNU General Public License as published by the Free |
-- Software Foundation, either version 2, or at your option any later version. |
-- |
-- This program is distributed in the hope that it will be useful, but |
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
-- for complete details. |
-- |
------------------------------------------------------------------------------ |
-- Module Name: cdc_pulse - syn |
-- Description: clock domain cross for pulse |
-- |
-- Dependencies: - |
-- Test bench: - |
-- Target Devices: generic |
-- Tool versions: xst 13.1; ghdl 0.29 |
-- Revision History: |
-- Date Rev Version Comment |
-- 2011-11-09 422 1.0 Initial version |
-- |
------------------------------------------------------------------------------ |
|
library ieee; |
use ieee.std_logic_1164.all; |
|
use work.slvtypes.all; |
|
entity cdc_pulse is -- clock domain cross for pulse |
generic ( |
POUT_SINGLE : boolean := false; -- if true: single cycle pout |
BUSY_WACK : boolean := false); -- if true: busy waits for ack |
port ( |
CLKM : in slbit; -- clock master |
RESET : in slbit := '0'; -- M|reset |
CLKS : in slbit; -- clock slave |
PIN : in slbit; -- M|pulse in |
BUSY : out slbit; -- M|busy |
POUT : out slbit -- S|pulse out |
); |
end entity cdc_pulse; |
|
|
architecture syn of cdc_pulse is |
|
signal R_REQ : slbit := '0'; |
signal R_REQ_C : slbit := '0'; |
signal R_ACK : slbit := '0'; |
signal R_ACK_C : slbit := '0'; |
signal R_ACK_S : slbit := '0'; |
|
begin |
|
proc_master: process (CLKM) |
begin |
if rising_edge(CLKM) then |
if RESET = '1' then |
R_REQ <= '0'; |
else |
if PIN = '1' then |
R_REQ <= '1'; |
elsif R_ACK_S = '1' then |
R_REQ <= '0'; |
end if; |
end if; |
R_ACK_C <= R_ACK; |
R_ACK_S <= R_ACK_C; |
end if; |
end process proc_master; |
|
proc_slave: process (CLKS) |
begin |
if rising_edge(CLKS) then |
R_REQ_C <= R_REQ; |
R_ACK <= R_REQ_C; |
end if; |
end process proc_slave; |
|
SINGLE1: if POUT_SINGLE = true generate |
signal R_ACK_1 : slbit := '0'; |
signal R_POUT : slbit := '0'; |
begin |
proc_pout: process (CLKS) |
begin |
if rising_edge(CLKS) then |
R_ACK_1 <= R_ACK; |
if R_ACK='1' and R_ACK_1='0' then |
R_POUT <= '1'; |
else |
R_POUT <= '0'; |
end if; |
end if; |
end process proc_pout; |
POUT <= R_POUT; |
end generate SINGLE1; |
|
SINGLE0: if POUT_SINGLE = false generate |
begin |
POUT <= R_ACK; |
end generate SINGLE0; |
|
BUSY1: if BUSY_WACK = true generate |
begin |
BUSY <= R_REQ or R_ACK_S; |
end generate BUSY1; |
|
BUSY0: if BUSY_WACK = false generate |
begin |
BUSY <= R_REQ; |
end generate BUSY0; |
|
end syn; |
|
/gray_cnt_n.vhd
0,0 → 1,112
-- $Id: gray_cnt_n.vhd 418 2011-10-23 20:11:40Z mueller $ |
-- |
-- Copyright 2007- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
-- |
-- This program is free software; you may redistribute and/or modify it under |
-- the terms of the GNU General Public License as published by the Free |
-- Software Foundation, either version 2, or at your option any later version. |
-- |
-- This program is distributed in the hope that it will be useful, but |
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
-- for complete details. |
-- |
------------------------------------------------------------------------------ |
-- Module Name: gray_cnt_n - syn |
-- Description: Genric width Gray code counter |
-- |
-- Dependencies: - |
-- Test bench: tb/tb_debounce_gen |
-- Target Devices: generic |
-- Tool versions: xst 8.1, 8.2, 9.1, 9.2; ghdl 0.18-0.25 |
-- Revision History: |
-- Date Rev Version Comment |
-- 2007-12-26 106 1.0 Initial version |
-- |
-- Some synthesis results: |
-- - 2007-12-27 ise 8.2.03 for xc3s1000-ft256-4: |
-- DWIDTH LUT Flop clock(xst est.) |
-- 4 6 5 305MHz/ 3.28ns |
-- 5 8 6 286MHz/ 2.85ns |
-- 8 13 9 234MHz/ 4.26ns |
-- 16 56 17 149MHz/ 6.67ns |
-- 32 95 33 161MHz/ 6.19ns |
-- 64 188 68 126MHz/ 7.90ns |
------------------------------------------------------------------------------ |
|
library ieee; |
use ieee.std_logic_1164.all; |
|
use work.slvtypes.all; |
use work.genlib.all; |
|
entity gray_cnt_n is -- n bit gray code counter |
generic ( |
DWIDTH : positive := 8); -- data width |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- reset |
CE : in slbit := '1'; -- count enable |
DATA : out slv(DWIDTH-1 downto 0) -- data out |
); |
end entity gray_cnt_n; |
|
|
architecture syn of gray_cnt_n is |
|
signal R_AUX : slbit := '1'; |
signal R_DATA : slv(DWIDTH-1 downto 0) := (others=>'0'); |
signal N_DATA : slv(DWIDTH-1 downto 0) := (others=>'0'); |
|
begin |
|
assert DWIDTH>=3 |
report "assert(DWIDTH>=3): only 3 bit or larger supported" |
severity failure; |
|
proc_regs: process (CLK) |
begin |
|
if rising_edge(CLK) then |
if RESET = '1' then |
R_AUX <= '1'; |
R_DATA <= (others=>'0'); |
elsif CE = '1' then |
R_AUX <= not R_AUX; |
R_DATA <= N_DATA; |
end if; |
end if; |
end process proc_regs; |
|
proc_next: process (R_AUX, R_DATA) |
variable r : slv(DWIDTH-1 downto 0) := (others=>'0'); |
variable n : slv(DWIDTH-1 downto 0) := (others=>'0'); |
variable s : slbit := '0'; |
begin |
|
r := R_DATA; |
n := R_DATA; |
s := '1'; |
|
if R_AUX = '1' then |
n(0) := not r(0); |
else |
for i in 1 to DWIDTH-2 loop |
if s='1' and r(i-1)='1' then |
n(i) := not r(i); |
end if; |
s := s and not r(i-1); |
end loop; |
if s = '1' then |
n(DWIDTH-1) := r(DWIDTH-2); |
end if; |
end if; |
|
N_DATA <= n; |
|
end process proc_next; |
|
DATA <= R_DATA; |
|
end syn; |
|
/cdc_pulse.vbom
0,0 → 1,4
# libs |
../slvtypes.vhd |
# design |
cdc_pulse.vhd |
/gray2bin_gen.vhd
0,0 → 1,64
-- $Id: gray2bin_gen.vhd 418 2011-10-23 20:11:40Z mueller $ |
-- |
-- Copyright 2007- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
-- |
-- This program is free software; you may redistribute and/or modify it under |
-- the terms of the GNU General Public License as published by the Free |
-- Software Foundation, either version 2, or at your option any later version. |
-- |
-- This program is distributed in the hope that it will be useful, but |
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
-- for complete details. |
-- |
------------------------------------------------------------------------------ |
-- Module Name: gray2bin_gen - syn |
-- Description: Gray code to binary converter |
-- |
-- Dependencies: - |
-- Test bench: tb/tb_debounce_gen |
-- Target Devices: generic |
-- Tool versions: xst 8.1, 8.2, 9.1, 9.2; ghdl 0.18-0.25 |
-- Revision History: |
-- Date Rev Version Comment |
-- 2007-12-26 106 1.0 Initial version |
------------------------------------------------------------------------------ |
|
library ieee; |
use ieee.std_logic_1164.all; |
|
use work.slvtypes.all; |
|
entity gray2bin_gen is -- gray->bin converter, generic vector |
generic ( |
DWIDTH : positive := 4); -- data width |
port ( |
DI : in slv(DWIDTH-1 downto 0); -- gray code input |
DO : out slv(DWIDTH-1 downto 0) -- binary code output |
); |
end entity gray2bin_gen; |
|
|
architecture syn of gray2bin_gen is |
|
begin |
|
proc_comb: process (DI) |
|
variable ido : slv(DWIDTH-1 downto 0); |
|
begin |
|
ido := (others=>'0'); |
|
ido(DWIDTH-1) := DI(DWIDTH-1); |
for i in DWIDTH-2 downto 0 loop |
ido(i) := ido(i+1) xor DI(i); |
end loop; |
|
DO <= ido; |
|
end process proc_comb; |
|
end syn; |
|
/gray2bin_gen.vbom
0,0 → 1,4
# libs |
../slvtypes.vhd |
# design |
gray2bin_gen.vhd |
/gray_cnt_4.vhd
0,0 → 1,103
-- $Id: gray_cnt_4.vhd 418 2011-10-23 20:11:40Z mueller $ |
-- |
-- Copyright 2007- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
-- |
-- This program is free software; you may redistribute and/or modify it under |
-- the terms of the GNU General Public License as published by the Free |
-- Software Foundation, either version 2, or at your option any later version. |
-- |
-- This program is distributed in the hope that it will be useful, but |
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
-- for complete details. |
-- |
------------------------------------------------------------------------------ |
-- Module Name: gray_cnt_4 - syn |
-- Description: 4 bit Gray code counter (ROM based) |
-- |
-- Dependencies: - |
-- Test bench: - |
-- Target Devices: generic |
-- Tool versions: xst 8.1, 8.2, 9.1, 9.2; ghdl 0.18-0.25 |
-- Revision History: |
-- Date Rev Version Comment |
-- 2007-12-26 106 1.0 Initial version |
-- |
-- Some synthesis results: |
-- - 2007-12-27 ise 8.2.03 for xc3s1000-ft256-4: |
-- LUT Flop clock(xst est.) |
-- 4 4 365MHz/ 2.76ns |
------------------------------------------------------------------------------ |
|
library ieee; |
use ieee.std_logic_1164.all; |
|
use work.slvtypes.all; |
|
entity gray_cnt_4 is -- 4 bit gray code counter (ROM based) |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- reset |
CE : in slbit := '1'; -- count enable |
DATA : out slv4 -- data out |
); |
end entity gray_cnt_4; |
|
|
architecture syn of gray_cnt_4 is |
|
signal R_DATA : slv4 := (others=>'0'); |
signal N_DATA : slv4 := (others=>'0'); |
|
-- Note: in xst 8.2.03 fsm_extract="no" is needed. Otherwise an fsm is |
-- inferred. For 4 bit the coding was 'Gray', but see remarks in |
-- gray_cnt_5. To be save, disallow fsm inferal, enforce reg+rom. |
|
attribute fsm_extract : string; |
attribute fsm_extract of R_DATA : signal is "no"; |
attribute rom_style : string; |
attribute rom_style of N_DATA : signal is "distributed"; |
|
begin |
|
proc_regs: process (CLK) |
begin |
|
if rising_edge(CLK) then |
if RESET = '1' then |
R_DATA <= (others=>'0'); |
elsif CE = '1' then |
R_DATA <= N_DATA; |
end if; |
end if; |
end process proc_regs; |
|
proc_next: process (R_DATA) |
begin |
|
N_DATA <= (others=>'0'); |
case R_DATA is |
when "0000" => N_DATA <= "0001"; -- 0 |
when "0001" => N_DATA <= "0011"; -- 1 |
when "0011" => N_DATA <= "0010"; -- 2 |
when "0010" => N_DATA <= "0110"; -- 3 |
when "0110" => N_DATA <= "0111"; -- 4 |
when "0111" => N_DATA <= "0101"; -- 5 |
when "0101" => N_DATA <= "0100"; -- 6 |
when "0100" => N_DATA <= "1100"; -- 7 |
when "1100" => N_DATA <= "1101"; -- 8 |
when "1101" => N_DATA <= "1111"; -- 9 |
when "1111" => N_DATA <= "1110"; -- 10 |
when "1110" => N_DATA <= "1010"; -- 11 |
when "1010" => N_DATA <= "1011"; -- 12 |
when "1011" => N_DATA <= "1001"; -- 13 |
when "1001" => N_DATA <= "1000"; -- 14 |
when "1000" => N_DATA <= "0000"; -- 15 |
when others => null; |
end case; |
end process proc_next; |
|
DATA <= R_DATA; |
|
end syn; |
|
/gray_cnt_5.vhd
0,0 → 1,121
-- $Id: gray_cnt_5.vhd 418 2011-10-23 20:11:40Z mueller $ |
-- |
-- Copyright 2007- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
-- |
-- This program is free software; you may redistribute and/or modify it under |
-- the terms of the GNU General Public License as published by the Free |
-- Software Foundation, either version 2, or at your option any later version. |
-- |
-- This program is distributed in the hope that it will be useful, but |
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
-- for complete details. |
-- |
------------------------------------------------------------------------------ |
-- Module Name: gray_cnt_5 - syn |
-- Description: 5 bit Gray code counter (ROM based) |
-- |
-- Dependencies: - |
-- Test bench: - |
-- Target Devices: generic |
-- Tool versions: xst 8.1, 8.2, 9.1, 9.2; ghdl 0.18-0.25 |
-- Revision History: |
-- Date Rev Version Comment |
-- 2007-12-26 106 1.0 Initial version |
-- |
-- Some synthesis results: |
-- - 2007-12-27 ise 8.2.03 for xc3s1000-ft256-4: |
-- LUT Flop clock(xst est.) |
-- 9 5 302MHz/ 3.31ns |
------------------------------------------------------------------------------ |
|
library ieee; |
use ieee.std_logic_1164.all; |
|
use work.slvtypes.all; |
|
entity gray_cnt_5 is -- 5 bit gray code counter (ROM based) |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- reset |
CE : in slbit := '1'; -- count enable |
DATA : out slv5 -- data out |
); |
end entity gray_cnt_5; |
|
|
architecture syn of gray_cnt_5 is |
|
signal R_DATA : slv5 := (others=>'0'); |
signal N_DATA : slv5 := (others=>'0'); |
|
-- Note: in xst 8.2.03 fsm_extract="no" is needed. Otherwise an fsm |
-- is inferred, using 'Johnson' encoding. DATA will be deduced |
-- in a combinatorial logic, and will thus have very likely some |
-- glitches at the clock transitions, rendering the whole Gray |
-- coding useless. |
|
attribute fsm_extract : string; |
attribute fsm_extract of R_DATA : signal is "no"; |
attribute rom_style : string; |
attribute rom_style of N_DATA : signal is "distributed"; |
|
begin |
|
proc_regs: process (CLK) |
begin |
|
if rising_edge(CLK) then |
if RESET = '1' then |
R_DATA <= (others=>'0'); |
elsif CE = '1' then |
R_DATA <= N_DATA; |
end if; |
end if; |
end process proc_regs; |
|
proc_next: process (R_DATA) |
begin |
|
N_DATA <= (others=>'0'); |
case R_DATA is |
when "00000" => N_DATA <= "00001"; -- 0 |
when "00001" => N_DATA <= "00011"; -- 1 |
when "00011" => N_DATA <= "00010"; -- 2 |
when "00010" => N_DATA <= "00110"; -- 3 |
when "00110" => N_DATA <= "00111"; -- 4 |
when "00111" => N_DATA <= "00101"; -- 5 |
when "00101" => N_DATA <= "00100"; -- 6 |
when "00100" => N_DATA <= "01100"; -- 7 |
when "01100" => N_DATA <= "01101"; -- 8 |
when "01101" => N_DATA <= "01111"; -- 9 |
when "01111" => N_DATA <= "01110"; -- 10 |
when "01110" => N_DATA <= "01010"; -- 11 |
when "01010" => N_DATA <= "01011"; -- 12 |
when "01011" => N_DATA <= "01001"; -- 13 |
when "01001" => N_DATA <= "01000"; -- 14 |
when "01000" => N_DATA <= "11000"; -- 15 |
when "11000" => N_DATA <= "11001"; -- 16 |
when "11001" => N_DATA <= "11011"; -- 17 |
when "11011" => N_DATA <= "11010"; -- 18 |
when "11010" => N_DATA <= "11110"; -- 19 |
when "11110" => N_DATA <= "11111"; -- 20 |
when "11111" => N_DATA <= "11101"; -- 21 |
when "11101" => N_DATA <= "11100"; -- 22 |
when "11100" => N_DATA <= "10100"; -- 23 |
when "10100" => N_DATA <= "10101"; -- 24 |
when "10101" => N_DATA <= "10111"; -- 25 |
when "10111" => N_DATA <= "10110"; -- 26 |
when "10110" => N_DATA <= "10010"; -- 27 |
when "10010" => N_DATA <= "10011"; -- 28 |
when "10011" => N_DATA <= "10001"; -- 29 |
when "10001" => N_DATA <= "10000"; -- 30 |
when "10000" => N_DATA <= "00000"; -- 31 |
when others => null; |
end case; |
end process proc_next; |
|
DATA <= R_DATA; |
|
end syn; |
|
/clkdivce.vhd
0,0 → 1,115
-- $Id: clkdivce.vhd 418 2011-10-23 20:11:40Z mueller $ |
-- |
-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
-- |
-- This program is free software; you may redistribute and/or modify it under |
-- the terms of the GNU General Public License as published by the Free |
-- Software Foundation, either version 2, or at your option any later version. |
-- |
-- This program is distributed in the hope that it will be useful, but |
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
-- for complete details. |
-- |
------------------------------------------------------------------------------ |
-- Module Name: clkgen - syn |
-- Description: Generate usec and msec enable signals |
-- |
-- Dependencies: - |
-- Test bench: - |
-- Target Devices: generic |
-- Tool versions: xst 8.2, 9.1, 9.2, 12.1, 13.1; ghdl 0.18-0.29 |
-- Revision History: |
-- Date Rev Version Comment |
-- 2011-10-22 418 1.0.3 now numeric_std clean |
-- 2008-01-20 112 1.0.2 rename clkgen->clkdivce; remove SYS_CLK port |
-- 2007-10-12 88 1.0.1 avoid ieee.std_logic_unsigned, use cast to unsigned |
-- 2007-06-30 62 1.0 Initial version |
------------------------------------------------------------------------------ |
|
library ieee; |
use ieee.std_logic_1164.all; |
use ieee.numeric_std.all; |
|
use work.slvtypes.all; |
|
entity clkdivce is -- generate usec/msec ce pulses |
generic ( |
CDUWIDTH : positive := 6; -- usec clock divider width |
USECDIV : positive := 50; -- divider ratio for usec pulse |
MSECDIV : positive := 1000); -- divider ratio for msec pulse |
port ( |
CLK : in slbit; -- input clock |
CE_USEC : out slbit; -- usec pulse |
CE_MSEC : out slbit -- msec pulse |
); |
end clkdivce; |
|
|
architecture syn of clkdivce is |
|
type regs_type is record |
ucnt : slv(CDUWIDTH-1 downto 0); -- usec clock divider counter |
mcnt : slv10; -- msec clock divider counter |
usec : slbit; -- usec pulse |
msec : slbit; -- msec pulse |
end record regs_type; |
|
constant regs_init : regs_type := ( |
slv(to_unsigned(USECDIV-1,CDUWIDTH)), |
slv(to_unsigned(MSECDIV-1,10)), |
'0','0' |
); |
|
signal R_REGS : regs_type := regs_init; -- state registers |
signal N_REGS : regs_type := regs_init; -- next value state regs |
|
begin |
|
assert USECDIV <= 2**CDUWIDTH and MSECDIV <= 1024 |
report "assert(USECDIV <= 2**CDUWIDTH and MSECDIV <= 1024): " & |
"USECDIV too large for given CDUWIDTH or MSECDIV>1024" |
severity FAILURE; |
|
proc_regs: process (CLK) |
begin |
|
if rising_edge(CLK) then |
R_REGS <= N_REGS; |
end if; |
|
end process proc_regs; |
|
proc_next: process (R_REGS) |
|
variable r : regs_type := regs_init; |
variable n : regs_type := regs_init; |
|
begin |
|
r := R_REGS; |
n := R_REGS; |
|
n.usec := '0'; |
n.msec := '0'; |
|
n.ucnt := slv(unsigned(r.ucnt) - 1); |
if unsigned(r.ucnt) = 0 then |
n.usec := '1'; |
n.ucnt := slv(to_unsigned(USECDIV-1,CDUWIDTH)); |
n.mcnt := slv(unsigned(r.mcnt) - 1); |
if unsigned(r.mcnt) = 0 then |
n.msec := '1'; |
n.mcnt := slv(to_unsigned(MSECDIV-1,10)); |
end if; |
end if; |
|
N_REGS <= n; |
|
CE_USEC <= r.usec; |
CE_MSEC <= r.msec; |
|
end process proc_next; |
|
|
end syn; |
/debounce_gen.vhd
0,0 → 1,133
-- $Id: debounce_gen.vhd 418 2011-10-23 20:11:40Z mueller $ |
-- |
-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
-- |
-- This program is free software; you may redistribute and/or modify it under |
-- the terms of the GNU General Public License as published by the Free |
-- Software Foundation, either version 2, or at your option any later version. |
-- |
-- This program is distributed in the hope that it will be useful, but |
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
-- for complete details. |
-- |
------------------------------------------------------------------------------ |
-- Module Name: debounce_gen - syn |
-- Description: Generic signal debouncer |
-- |
-- Dependencies: - |
-- Test bench: tb/tb_debounce_gen |
-- Target Devices: generic |
-- Tool versions: xst 8.2, 9.1, 9.2, 13.1; ghdl 0.18-0.29 |
-- Revision History: |
-- Date Rev Version Comment |
-- 2011-10-22 418 1.0.3 now numeric_std clean |
-- 2007-12-26 105 1.0.2 add default for RESET |
-- 2007-10-12 88 1.0.1 avoid ieee.std_logic_unsigned, use cast to unsigned |
-- 2007-06-29 61 1.0 Initial version |
------------------------------------------------------------------------------ |
|
library ieee; |
use ieee.std_logic_1164.all; |
use ieee.numeric_std.all; |
|
use work.slvtypes.all; |
|
entity debounce_gen is -- debounce, generic vector |
generic ( |
CWIDTH : positive := 2; -- clock interval counter width |
CEDIV : positive := 3; -- clock interval divider |
DWIDTH : positive := 8); -- data width |
port ( |
CLK : in slbit; -- clock |
RESET : in slbit := '0'; -- reset |
CE_INT : in slbit; -- clock interval enable (usec or msec) |
DI : in slv(DWIDTH-1 downto 0); -- data in |
DO : out slv(DWIDTH-1 downto 0) -- data out |
); |
end entity debounce_gen; |
|
|
architecture syn of debounce_gen is |
|
constant cntzero : slv(CWIDTH-1 downto 0) := (others=>'0'); |
constant datazero : slv(dWIDTH-1 downto 0) := (others=>'0'); |
|
type regs_type is record |
cecnt : slv(CWIDTH-1 downto 0); -- clock interval counter |
dref : slv(DWIDTH-1 downto 0); -- data reference |
dchange : slv(DWIDTH-1 downto 0); -- data change flag |
dout : slv(DWIDTH-1 downto 0); -- data output |
end record regs_type; |
|
constant regs_init : regs_type := ( |
cntzero, |
datazero, |
datazero, |
datazero |
); |
|
signal R_REGS : regs_type := regs_init; -- state registers |
signal N_REGS : regs_type := regs_init; -- next value state regs |
|
begin |
|
assert CEDIV<=2**CWIDTH report "assert(CEDIV<=2**CWIDTH)" severity failure; |
|
proc_regs: process (CLK) |
begin |
|
if rising_edge(CLK) then |
if RESET = '1' then |
R_REGS.cecnt <= cntzero; |
R_REGS.dref <= DI; |
R_REGS.dchange <= datazero; |
R_REGS.dout <= DI; |
else |
R_REGS <= N_REGS; |
end if; |
end if; |
|
end process proc_regs; |
|
proc_next: process (R_REGS, CE_INT, DI) |
|
variable r : regs_type := regs_init; |
variable n : regs_type := regs_init; |
|
begin |
|
r := R_REGS; |
n := R_REGS; |
|
for i in DI'range loop |
if DI(i) /= r.dref(i) then |
n.dchange(i) := '1'; |
end if; |
end loop; |
|
if CE_INT = '1' then |
if unsigned(r.cecnt) = 0 then |
n.cecnt := slv(to_unsigned(CEDIV-1,CWIDTH)); |
n.dref := DI; |
n.dchange := datazero; |
for i in DI'range loop |
if r.dchange(i) = '0' then |
n.dout(i) := r.dref(i); |
end if; |
end loop; |
|
else |
n.cecnt := slv(unsigned(r.cecnt) - 1); |
end if; |
end if; |
|
N_REGS <= n; |
|
DO <= r.dout; |
|
end process proc_next; |
|
|
end syn; |
|
/debounce_gen.vbom
0,0 → 1,4
# libs |
../slvtypes.vhd |
# design |
debounce_gen.vhd |
/clkdivce.vbom
0,0 → 1,4
# libs |
../slvtypes.vhd |
# design |
clkdivce.vhd |
.
Property changes :
Added: svn:ignore
## -0,0 +1,32 ##
+*.dep_ghdl
+*.dep_isim
+*.dep_xst
+work-obj93.cf
+*.vcd
+*.ghw
+*.sav
+*.tmp
+*.exe
+ise
+xflow.his
+*.ngc
+*.ncd
+*.pcf
+*.bit
+*.msk
+isim
+isim.log
+isim.wdb
+fuse.log
+*_[sft]sim.vhd
+*_tsim.sdf
+*_xst.log
+*_tra.log
+*_twr.log
+*_map.log
+*_par.log
+*_pad.log
+*_bgn.log
+*_svn.log
+*_sum.log
+*_[dsft]sim.log