Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec-tests / vhdl_json / vhdl_files / 2-exportOK / cnes_guidelines / rule / data / STD_03900_bad.vhd @ 2051e520

History | View | Annotate | Download (4.72 KB)

1
-------------------------------------------------------------------------------------------------
2
-- Company   : CNES
3
-- Author    : Mickael Carl (CNES)
4
-- Copyright : Copyright (c) CNES.
5
-- Licensing : GNU GPLv3
6
-------------------------------------------------------------------------------------------------
7
-- Version         : V1.1
8
-- Version history :
9
--    V1   : 2015-04-13 : Mickael Carl (CNES): Creation
10
--    V1.1 : 2016-05-03 : F.Manni (CNES) : add initialization trough reset for Raz, enable and Count_Length
11
-------------------------------------------------------------------------------------------------
12
-- File name          : STD_03900_bad.vhd
13
-- File Creation date : 2015-04-13
14
-- Project name       : VHDL Handbook CNES Edition
15
-------------------------------------------------------------------------------------------------
16
-- Softwares             :  Microsoft Windows (Windows 7) - Editor (Eclipse + VEditor)
17
-------------------------------------------------------------------------------------------------
18
-- Description : Handbook example: State machine type definition: bad example
19
--
20
-- Limitations : This file is an example of the VHDL handbook made by CNES. It is a stub aimed at
21
--               demonstrating good practices in VHDL and as such, its design is minimalistic.
22
--               It is provided as is, without any warranty.
23
--               This example is compliant with the Handbook version 1.
24
--
25
-------------------------------------------------------------------------------------------------
26
-- Naming conventions:
27
--
28
-- i_Port: Input entity port
29
-- o_Port: Output entity port
30
-- b_Port: Bidirectional entity port
31
-- g_My_Generic: Generic entity port
32
--
33
-- c_My_Constant: Constant definition
34
-- t_My_Type: Custom type definition
35
--
36
-- My_Signal_n: Active low signal
37
-- v_My_Variable: Variable
38
-- sm_My_Signal: FSM signal
39
-- pkg_Param: Element Param coming from a package
40
--
41
-- My_Signal_re: Rising edge detection of My_Signal
42
-- My_Signal_fe: Falling edge detection of My_Signal
43
-- My_Signal_rX: X times registered My_Signal signal
44
--
45
-- P_Process_Name: Process
46
--
47
-------------------------------------------------------------------------------------------------
48

    
49
library IEEE;
50
use IEEE.std_logic_1164.all;
51
use IEEE.numeric_std.all;
52

    
53
entity STD_03900_bad is
54
   port (
55
      i_Clock   : in std_logic;         -- Clock input
56
      i_Reset_n : in std_logic;         -- Reset input
57
      i_Start   : in std_logic;         -- Start counters signal
58
      i_Stop    : in std_logic          -- Stop counters signal
59
      );
60
end STD_03900_bad;
61

    
62
--CODE
63
architecture Behavioral of STD_03900_bad is
64
   constant c_Length : std_logic_vector(3 downto 0) := (others => '1');  -- How long we should count
65
   signal sm_State   : std_logic_vector(3 downto 0);  -- State signal
66
   signal Raz        : std_logic;  -- Load the length value and initialize the counter
67
   signal Enable     : std_logic;       -- Counter enable signal
68
   signal Length     : std_logic_vector(3 downto 0);  -- Counter length for counting
69
   signal End_Count  : std_logic;       -- End signal of counter
70
begin
71
   -- A simple counter with loading length and enable signal
72
   Counter : Counter
73
      port map (
74
         i_Clock   => i_Clock,
75
         i_Reset_n => i_Reset_n,
76
         i_Raz     => Raz,
77
         i_Enable  => Enable,
78
         i_Length  => Length,
79
         o_Done    => End_Count
80
         );
81

    
82
   -- FSM process controlling the counter. Start or stop it in function of the input (i_Start & i_Stop),
83
   -- load the length value, and wait for it to finish
84
   P_FSM : process(i_Reset_n, i_Clock)
85
   begin
86
      if (i_Reset_n = '0') then
87
         sm_State <= "0001";
88
         Raz      <= '0';
89
         Enable   <= '0';
90
         Count_Length <= (others=>'0');
91
      elsif (rising_edge(i_Clock)) then
92
            case sm_State is
93
               when "0001" =>
94
                  -- Set the length value
95
                  Length   <= c_Length;
96
                  sm_State <= "0010";
97
               when "0010" =>
98
                  -- Load the counter and initialize it
99
                  Raz      <= '1';
100
                  sm_State <= "0100";
101
               when "0100" =>
102
                  -- Start or stop counting depending on inputs until it finishes
103
                  Raz <= '0';
104
                  if (End_Count = '0') then
105
                     -- The counter has not finished, wait
106
                     Enable   <= i_Start xor not i_Stop;
107
                     sm_State <= "0100";
108
                  else
109
                     -- The counter has finished, nothing else to do
110
                     Enable   <= '0';
111
                     sm_State <= "1000";
112
                  end if;
113
               when others =>
114
                  sm_State <= "0001";
115
            end case;
116
      end if;
117
   end process;
118
end Behavioral;
119
--CODE