Shruthi LS
Newbie level 5
HI,
I want to send the 32bit counter through the UART which is of 8-bit in VHDL ...Now I am done with the 8bit counter..but I am finding difficult to send the 32bit counter and receive as a four 8bit packets..could anyone please help me...code is attached..
I want to send the 32bit counter through the UART which is of 8-bit in VHDL ...Now I am done with the 8bit counter..but I am finding difficult to send the 32bit counter and receive as a four 8bit packets..could anyone please help me...code is attached..
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 library IEEE; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity counter_8 is port(PCLK : in std_logic; -- APB Clock CLK_5KHZ : in std_logic; -- slow clock for counter PRESETn : in std_logic; WEN : out std_logic; -- Write enable to APAB fabric interface Register INTR : out std_logic; -- interrupt to the processor when data is ready ( pulse) Q : out std_logic_vector(7 downto 0) --- Data to be stored in the FIB Register ); end counter_8; ------------------------------------------------- architecture archi of counter_8 is signal counter,ldata,markr_data : std_logic_vector(7 downto 0) ; signal dataen_counter,markr_counter : std_logic_vector(3 downto 0) ; signal WEN_sig, WEN_sig0,WEN_sig1 : std_logic; signal INTR_sig0, INTR_sig1 : std_logic; signal dataen,dataen_count_en,WEN_temp0,WEN_temp1,WEN_temp2,WEN_temp3 : std_logic; signal en_data_ctr,en_markr_counter:std_logic; --signal count : integer :=1; begin --------------------------------------------------- ----------------------------------------------- ------------------------------------------------- dataen_ctr_process : process (PRESETn,PCLK) variable last_state : std_logic := '0'; begin if(PRESETn='0') then dataen_counter <= (others => '0'); elsif(PCLK'event and PCLK='1') then if(dataen_count_en = '0') then dataen_counter <= (others => '0'); else dataen_counter <= dataen_counter + 1; end if; end if; end process dataen_ctr_process ; --------------------------------------------- --------------------------------------------- marker_data_en_process : process(PRESETn,PCLK) variable last_state : std_logic := '0'; begin if(PRESETn='0') then dataen <= '0'; dataen_count_en <= '0'; en_markr_counter <= '0'; elsif(PCLK'event and PCLK='1') then if(last_state = '0' and CLK_5KHZ = '1') then dataen <= '1'; dataen_count_en <= '1'; en_markr_counter <= '1'; else null; end if; if(dataen_counter = 1) then dataen <= '0' ; dataen_count_en <= '0'; else null; end if; if(en_data_ctr = '1') then en_markr_counter <= '0'; else null; end if; last_state := CLK_5KHZ; end if; end process marker_data_en_process ; ----------------------------------------- ----------------------------------------- header_data_process : process(PRESETn,CLK_5KHZ) begin if(PRESETn='0') then markr_data <= x"23"; --23 is for # in ASCII markr_counter <= (others => '0'); en_data_ctr <= '0'; ldata <= x"23";--(others => '0'); elsif(CLK_5KHZ'event and CLK_5KHZ='1') then if(en_markr_counter = '1') then markr_counter <= markr_counter + 1; if(markr_counter >= 0 and markr_counter < 3) then -- if(markr_counter < 3) then -- Has one extra # sent out seen in Simulation -- if(markr_counter < 2) then -- To reduce the extra 5th # ldata <= markr_data; end if; if(markr_counter = 3) then en_data_ctr <= '1'; markr_counter <=(others => '0'); else null; end if; end if; if(en_data_ctr = '1') then ldata <= counter; --else --ldata <= ldata; end if; end if; end process header_data_process ; ---------------------------------------------- ---------------------------------------------- data_ctr_process : process(PRESETn,CLK_5KHZ) variable last_state : std_logic := '0'; begin if(PRESETn='0') then counter <= (others => '0'); elsif(CLK_5KHZ'event and CLK_5KHZ='1') then if(en_data_ctr = '1') then counter <= counter + 1; else counter <= counter; end if; end if; end process data_ctr_process; --------------------------------------------------- --- generate the WEN of one clock cycle of PCLK for writing into the FIB register --- dataen is pasees through a 2 level shift register with PCLK clock and the generate a pulse ---- in the output ---------------------------------------------- wen2_process : process(PRESETn,PCLK) variable last_state : std_logic := '0'; begin if (PRESETn='0') then WEN_sig0 <= '0'; WEN_sig1 <= '0'; elsif(PCLK'event and PCLK='1') then WEN_sig0 <= dataen; WEN_sig1 <= WEN_sig0; end if; end process wen2_process; ------------------------------------------------- WEN_sig <= '1' when ( WEN_sig0 ='1' and WEN_sig1 ='0') else '0'; ---------------------------------------------- WEN_reg_process : process(PRESETn,PCLK) begin if (PRESETn='0') then WEN_temp0 <= '0'; WEN_temp1 <= '0'; WEN_temp2 <= '0'; WEN_temp3 <= '0'; elsif(PCLK'event and PCLK='0') then WEN_temp0 <= WEN_sig; WEN_temp1 <= WEN_temp0; WEN_temp2 <= WEN_temp1; WEN_temp3 <= WEN_temp2; -- WEN_temp <= WEN_sig; end if; end process WEN_reg_process; ------------------------------------------------- --- generate the Interrupt similar way as WEN --- INTR should be generated after few clock cycle of WEN for a period one one or two PCLK clock cycle -- ---------------------------------------------- intr_process : process(PRESETn,PCLK) begin if (PRESETn='0') then INTR_sig0 <= '0'; INTR_sig1 <= '0'; elsif(PCLK'event and PCLK='1') then INTR_sig0 <= WEN_sig; INTR_sig1 <= INTR_sig0; end if; end process intr_process; ------------------------------------------------- ------------------- For the HW WEN <= WEN_temp0; INTR <= INTR_sig0 xor INTR_sig1; --- INTR signal is generated of two clock width. Q <= ldata; end archi; ---------------------------------------------
Last edited by a moderator: