Hi! I'm new to VHDL and have been trying to learn it for the past 2weeks, i would like to ask for help for my project, which is Development of Universal Asynchronous Receiver Transmitter (UART) using VHDL. I have drawn the board diagram , and the expected wave form for my project, but is facing trouble coding it. I have attached my pictures of 'board diagram and waveform' in the attached files, hope u all can help me out. i have try coding the clock divider, library ieee; use ieee.std_logic_1164.all, ieee.std_logic_unsigned.all; entity divider is port (clk: in std_logic; output_clk, output_clk2: out std_logic); end; architecture sim of divider is signal count: integer range 0 to 250000; signal reg: std_logic; signal count2: integer range 0 to 868056; signal reg2: std_logic; begin output_clk <= reg; output_clk2 <= reg2; process(clk) begin if rising_edge(clk) then if (count < 249999) then count <= count + 1; else count <= 0; end if; if (count < 125000) then reg <= '0'; else reg <= '1'; end if; if (count2 < 868055) then count2 <= count2 + 1; else count2 <= 0; end if; if (count2 < 434028) then reg2 <= '0'; else reg2 <= '1'; end if; end if; end process; end; and also the ring counter, Library IEEE; Use IEEE.std_logic_1164.all; entity ring is port (clk, reset : in std_logic; G1, G2, G3, G4 : out std_logic); end; architecture ring_counter of ring is signal reg1, reg2, reg3, reg4: std_logic; begin G1 <= reg1; G2 <= reg2; G3 <= reg3; G4 <= reg4; process (clk, reset) begin if (reset='0') then reg1 <= '0'; reg2 <= '1'; reg3 <= '1'; reg4 <= '1'; elsif (clk'event and clk='1') then reg4 <= reg1; reg3 <= reg4; reg2 <= reg3; reg1 <= reg2; end if; end process; end; please feel free to guide me on the other blocks, Thanks!
You should not work with "divided" clocks, but with clock enables. That means: you have only 1 clock in the hole design. This is the crystal connected to your fpga. And you only generate clock enables that are valid for one cycle of this "master" clock. So, its like this:
1 | process(clk) |
2 | begin
|
3 | if rising_edge(clk) then |
4 | |
5 | if (count1 = 249999) then |
6 | count1 <= 0; |
7 | ce1 <= '1'; |
8 | else
|
9 | count1 <= count1 + 1; |
10 | ce1 <= '0'; |
11 | end if; |
12 | |
13 | if (count2 = 868055) then |
14 | count2 <= 0; |
15 | ce2 <= '1'; |
16 | else
|
17 | count2 <= count2 + 1; |
18 | ce2 <= '0'; |
19 | end if; |
20 | end if; |
21 | |
22 | end process; |
23 | |
24 | -- using the clock enables:
|
25 | process(clk) |
26 | begin
|
27 | if rising_edge(clk) then |
28 | |
29 | if (ce1 = '1') then |
30 | -- do st once each 250000 cycles
|
31 | end if; |
32 | |
33 | if (ce2 = '1') then |
34 | -- do st once each 868056 cycles
|
35 | end if; |
36 | end if; |
37 | |
38 | end process; |
Your ring is just an ordinary shift-register. I would do it this way:
1 | Library IEEE; |
2 | Use IEEE.std_logic_1164.all; |
3 | |
4 | entity ring is port |
5 | (clk, reset : in std_logic; -- why do you need a reset? |
6 | G1, G2, G3, G4 : out std_logic); -- why not using a vector like G : out std_logic_vector(3 downto 0); |
7 | end; |
8 | |
9 | architecture ring_counter of ring is |
10 | signal sr: std_logic_vector(3 downto 0) := "0111"; -- when you can use default values |
11 | |
12 | begin
|
13 | G1 <= sr(0); |
14 | G2 <= sr(1); |
15 | G3 <= sr(2); |
16 | G4 <= sr(3); |
17 | sr <= sr(0) & sr(3 downto 1) when rising_edge(clk); |
18 | end; |
Debouncing is also a shift register (btw: most of the world is a shift register...:-)
1 | Library IEEE; |
2 | Use IEEE.std_logic_1164.all; |
3 | |
4 | entity debounce is port |
5 | (clk : in std_logic; -- no need for a reset !!! |
6 | ce200hz : in std_logic; -- a clock enable with 200 Hz |
7 | transmit : in std_logic; |
8 | transmit_int : out std_logic); |
9 | end; |
10 | |
11 | architecture behave of debounce is |
12 | signal sr: std_logic_vector(2 downto 0) := "000"; |
13 | begin
|
14 | sr <= sr(1) & sr(0) & when rising_edge(clk); |
15 | process(clk) begin |
16 | if rising_edge(clk) then |
17 | if (ce200Hz = '1') then -- shift in new input level |
18 | sr <= sr(1) & sr(0) & transmit; |
19 | end if; |
20 | if (sr = "110") then -- falling edge |
21 | transmit_int <= '1'; |
22 | else
|
23 | transmit_int <= '0'; |
24 | end if; |
25 | end if; |
26 | end process; |
27 | end behave ; |
BTW: if (count < 249999) then count <= count + 1; else count <= 0; end if; This counts 1 to much: from 0 to 250000 are 250001 clock cycles... :-o
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.