1 |
d93979b7
|
Arnaud Dieumegard
|
-------------------------------------------------------------------------------------------------
|
2 |
|
|
-- Company : CNES
|
3 |
|
|
-- Author : Mickael Carl (CNES)
|
4 |
|
|
-- Copyright : Copyright (c) CNES.
|
5 |
|
|
-- Licensing : GNU GPLv3
|
6 |
|
|
-------------------------------------------------------------------------------------------------
|
7 |
|
|
-- Version : V1
|
8 |
|
|
-- Version history :
|
9 |
|
|
-- V1 : 2015-04-10 : Mickael Carl (CNES): Creation
|
10 |
|
|
-------------------------------------------------------------------------------------------------
|
11 |
|
|
-- File name : STD_05900_good.vhd
|
12 |
|
|
-- File Creation date : 2015-04-10
|
13 |
|
|
-- Project name : VHDL Handbook CNES Edition
|
14 |
|
|
-------------------------------------------------------------------------------------------------
|
15 |
|
|
-- Softwares : Microsoft Windows (Windows 7) - Editor (Eclipse + VEditor)
|
16 |
|
|
-------------------------------------------------------------------------------------------------
|
17 |
|
|
-- Description : Handbook example: Range for integers: good example
|
18 |
|
|
--
|
19 |
|
|
-- Limitations : This file is an example of the VHDL handbook made by CNES. It is a stub aimed at
|
20 |
|
|
-- demonstrating good practices in VHDL and as such, its design is minimalistic.
|
21 |
|
|
-- It is provided as is, without any warranty.
|
22 |
|
|
-- This example is compliant with the Handbook version 1.
|
23 |
|
|
--
|
24 |
|
|
-------------------------------------------------------------------------------------------------
|
25 |
|
|
-- Naming conventions:
|
26 |
|
|
--
|
27 |
|
|
-- i_Port: Input entity port
|
28 |
|
|
-- o_Port: Output entity port
|
29 |
|
|
-- b_Port: Bidirectional entity port
|
30 |
|
|
-- g_My_Generic: Generic entity port
|
31 |
|
|
--
|
32 |
|
|
-- c_My_Constant: Constant definition
|
33 |
|
|
-- t_My_Type: Custom type definition
|
34 |
|
|
--
|
35 |
|
|
-- My_Signal_n: Active low signal
|
36 |
|
|
-- v_My_Variable: Variable
|
37 |
|
|
-- sm_My_Signal: FSM signal
|
38 |
|
|
-- pkg_Param: Element Param coming from a package
|
39 |
|
|
--
|
40 |
|
|
-- My_Signal_re: Rising edge detection of My_Signal
|
41 |
|
|
-- My_Signal_fe: Falling edge detection of My_Signal
|
42 |
|
|
-- My_Signal_rX: X times registered My_Signal signal
|
43 |
|
|
--
|
44 |
|
|
-- P_Process_Name: Process
|
45 |
|
|
--
|
46 |
|
|
-------------------------------------------------------------------------------------------------
|
47 |
|
|
|
48 |
|
|
library IEEE;
|
49 |
|
|
use IEEE.std_logic_1164.all;
|
50 |
|
|
use IEEE.numeric_std.all;
|
51 |
|
|
--CODE
|
52 |
|
|
entity STD_05900_good is
|
53 |
|
|
port (
|
54 |
|
|
i_Clock : in std_logic; -- Main clock signal
|
55 |
|
|
i_Reset_n : in std_logic; -- Main reset signal
|
56 |
|
|
i_Enable : in std_logic; -- Enables the counter
|
57 |
|
|
i_Length : in std_logic_vector(7 downto 0); -- Unsigned Value for Counter Period
|
58 |
|
|
o_Count : out std_logic_vector(7 downto 0) -- Counter (unsigned value)
|
59 |
|
|
);
|
60 |
|
|
end STD_05900_good;
|
61 |
|
|
|
62 |
|
|
architecture Behavioral of STD_05900_good is
|
63 |
|
|
signal Count : integer range 0 to 255; -- Counter output signal
|
64 |
|
|
signal Count_Length : integer range 0 to 255; -- Length input signal
|
65 |
|
|
begin
|
66 |
|
|
--CODE
|
67 |
|
|
Count_Length <= to_integer(unsigned(i_Length));
|
68 |
|
|
|
69 |
|
|
-- Will count undefinitely from 0 to i_Length while i_Enable is asserted
|
70 |
|
|
P_Count : process(i_Reset_n, i_Clock)
|
71 |
|
|
begin
|
72 |
|
|
if (i_Reset_n = '0') then
|
73 |
|
|
Count <= 0;
|
74 |
|
|
elsif (rising_edge(i_Clock)) then
|
75 |
|
|
if (Count >= Count_Length) then -- Counter restarts from 0
|
76 |
|
|
Count <= 0;
|
77 |
|
|
elsif (i_Enable = '1') then -- Increment counter value
|
78 |
|
|
Count <= Count + 1;
|
79 |
|
|
end if;
|
80 |
|
|
end if;
|
81 |
|
|
end process;
|
82 |
|
|
|
83 |
|
|
o_Count <= std_logic_vector(to_unsigned(Count, o_Count'length));
|
84 |
|
|
|
85 |
|
|
end Behavioral;
|