1 |
2 |
jsauermann |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
2 |
|
|
"http://www.w3.org/TR/html4/strict.dtd">
|
3 |
|
|
<HTML>
|
4 |
|
|
<HEAD>
|
5 |
|
|
<TITLE>html/Listing_of_baudgen.vhd</TITLE>
|
6 |
|
|
<META NAME="generator" CONTENT="HTML::TextToHTML v2.46">
|
7 |
|
|
<LINK REL="stylesheet" TYPE="text/css" HREF="lecture.css">
|
8 |
|
|
</HEAD>
|
9 |
|
|
<BODY>
|
10 |
|
|
<P><table class="ttop"><th class="tpre"><a href="11_Listing_of_avr_fpga.vhd.html">Previous Lesson</a></th><th class="ttop"><a href="toc.html">Table of Content</a></th><th class="tnxt"><a href="13_Listing_of_common.vhd.html">Next Lesson</a></th></table>
|
11 |
|
|
<hr>
|
12 |
|
|
|
13 |
|
|
<H1><A NAME="section_1">12 LISTING OF baudgen.vhd</A></H1>
|
14 |
|
|
|
15 |
|
|
<pre class="vhdl">
|
16 |
|
|
|
17 |
|
|
1 -------------------------------------------------------------------------------
|
18 |
|
|
2 --
|
19 |
|
|
3 -- Copyright (C) 2009, 2010 Dr. Juergen Sauermann
|
20 |
|
|
4 --
|
21 |
|
|
5 -- This code is free software: you can redistribute it and/or modify
|
22 |
|
|
6 -- it under the terms of the GNU General Public License as published by
|
23 |
|
|
7 -- the Free Software Foundation, either version 3 of the License, or
|
24 |
|
|
8 -- (at your option) any later version.
|
25 |
|
|
9 --
|
26 |
|
|
10 -- This code is distributed in the hope that it will be useful,
|
27 |
|
|
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
28 |
|
|
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
29 |
|
|
13 -- GNU General Public License for more details.
|
30 |
|
|
14 --
|
31 |
|
|
15 -- You should have received a copy of the GNU General Public License
|
32 |
|
|
16 -- along with this code (see the file named COPYING).
|
33 |
|
|
17 -- If not, see http://www.gnu.org/licenses/.
|
34 |
|
|
18 --
|
35 |
|
|
19 -------------------------------------------------------------------------------
|
36 |
|
|
20 -------------------------------------------------------------------------------
|
37 |
|
|
21 --
|
38 |
|
|
22 -- Module Name: baudgen - Behavioral
|
39 |
|
|
23 -- Create Date: 13:51:24 11/07/2009
|
40 |
|
|
24 -- Description: fixed baud rate generator
|
41 |
|
|
25 --
|
42 |
|
|
26 -------------------------------------------------------------------------------
|
43 |
|
|
27 --
|
44 |
|
|
28 library IEEE;
|
45 |
|
|
29 use IEEE.STD_LOGIC_1164.ALL;
|
46 |
|
|
30 use IEEE.STD_LOGIC_ARITH.ALL;
|
47 |
|
|
31 use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
48 |
|
|
32
|
49 |
|
|
33 entity baudgen is
|
50 |
|
|
34 generic(clock_freq : std_logic_vector(31 downto 0);
|
51 |
|
|
35 baud_rate : std_logic_vector(27 downto 0));
|
52 |
|
|
36 port( I_CLK : in std_logic;
|
53 |
|
|
37
|
54 |
|
|
38 I_CLR : in std_logic;
|
55 |
|
|
39 Q_CE_1 : out std_logic; -- baud x 1 clock enable
|
56 |
|
|
40 Q_CE_16 : out std_logic); -- baud x 16 clock enable
|
57 |
|
|
41 end baudgen;
|
58 |
|
|
42
|
59 |
|
|
43
|
60 |
|
|
44 architecture Behavioral of baudgen is
|
61 |
|
|
45
|
62 |
|
|
46 constant BAUD_16 : std_logic_vector(31 downto 0) := baud_rate & "0000";
|
63 |
|
|
47 constant LIMIT : std_logic_vector(31 downto 0) := clock_freq - BAUD_16;
|
64 |
|
|
48
|
65 |
|
|
49 signal L_CE_16 : std_logic;
|
66 |
|
|
50 signal L_CNT_16 : std_logic_vector( 3 downto 0);
|
67 |
|
|
51 signal L_COUNTER : std_logic_vector(31 downto 0);
|
68 |
|
|
52
|
69 |
|
|
53 begin
|
70 |
|
|
54
|
71 |
|
|
55 baud16: process(I_CLK)
|
72 |
|
|
56 begin
|
73 |
|
|
57 if (rising_edge(I_CLK)) then
|
74 |
|
|
58 if (I_CLR = '1') then
|
75 |
|
|
59 L_COUNTER <= X"00000000";
|
76 |
|
|
60 elsif (L_COUNTER >= LIMIT) then
|
77 |
|
|
61 L_COUNTER <= L_COUNTER - LIMIT;
|
78 |
|
|
62 else
|
79 |
|
|
63 L_COUNTER <= L_COUNTER + BAUD_16;
|
80 |
|
|
64 end if;
|
81 |
|
|
65 end if;
|
82 |
|
|
66 end process;
|
83 |
|
|
67
|
84 |
|
|
68 baud1: process(I_CLK)
|
85 |
|
|
69 begin
|
86 |
|
|
70 if (rising_edge(I_CLK)) then
|
87 |
|
|
71 if (I_CLR = '1') then
|
88 |
|
|
72 L_CNT_16 <= "0000";
|
89 |
|
|
73 elsif (L_CE_16 = '1') then
|
90 |
|
|
74 L_CNT_16 <= L_CNT_16 + "0001";
|
91 |
|
|
75 end if;
|
92 |
|
|
76 end if;
|
93 |
|
|
77 end process;
|
94 |
|
|
78
|
95 |
|
|
79 L_CE_16 <= '1' when (L_COUNTER >= LIMIT) else '0';
|
96 |
|
|
80 Q_CE_16 <= L_CE_16;
|
97 |
|
|
81 Q_CE_1 <= L_CE_16 when L_CNT_16 = "1111" else '0';
|
98 |
|
|
82
|
99 |
|
|
83 end behavioral;
|
100 |
|
|
84
|
101 |
|
|
<pre class="filename">
|
102 |
|
|
src/baudgen.vhd
|
103 |
|
|
</pre></pre>
|
104 |
|
|
<P>
|
105 |
|
|
|
106 |
|
|
<P><hr><BR>
|
107 |
|
|
<table class="ttop"><th class="tpre"><a href="11_Listing_of_avr_fpga.vhd.html">Previous Lesson</a></th><th class="ttop"><a href="toc.html">Table of Content</a></th><th class="tnxt"><a href="13_Listing_of_common.vhd.html">Next Lesson</a></th></table>
|
108 |
|
|
</BODY>
|
109 |
|
|
</HTML>
|