sam93
Junior Member level 1
- Joined
- Jul 16, 2015
- Messages
- 15
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 241
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 entity tes is port ( CLK_20M : in STD_LOGIC; CLK : in STD_LOGIC; b : out integer range 0 to 19999999; c : out integer range 0 to 19999999 ); end tes; architecture Behavioral of tes is signal cnt_1 : integer range 0 to 19999999 ; begin one:process(CLK) variable counter: integer range 0 to 19999999 ; begin if rising_edge(CLK) then counter := counter + 1; end if; cnt_1 <= counter; b <= cnt_1; end process; two:process(CLK_20M) variable counter_2: integer range 0 to 19999999 ; begin if (cnt_1 < 20000000) then if rising_edge(CLK_20M) then counter_2 := counter_2 + 1; end if; end if; c <= counter_2; end process; end Behavioral;
two:process(CLK_20M)
variable counter_2: integer range 0 to 19999999 ;
begin
if (cnt_1 < 20000000) then
if rising_edge(CLK_20M) then
counter_2 := counter_2 + 1;
end if;
end if;
c <= counter_2;
end process;
end Behavioral;
#psuedo
Whilst within active second
if pulse triggered
count increment
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 combinatorial_Pulse : process (reset, pulse, active_sec) begin if reset = '1' then count <= 0; elsif active_sec = '1' then if rising_edge(pulse) then count <= count + 1; end if; end if; end process; sync_active_sec : process(reset, clock) begin -- manipulate clock such that you generate a 1 second train -- stuff active_sec <= '1'; --- end process;
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 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_unSIGNED.ALL; use ieee.numeric_std.all; entity rez is port ( CLK_20M : in STD_LOGIC; ); end rez; architecture Behavioral of rez is signal a: std_logic_vector(25 downto 0); signal clk_312khz :STD_LOGIC;-- 3.2 us signal cnt_1: integer range 0 to 19999999 :=0 ; signal cnt_2: integer range 0 to 67108863 :=0 ; signal cnt_3: integer range 0 to 67108863 :=0 ; signal enable : STD_LOGIC; begin clk_divider2:process (CLK_20M) variable counter: std_logic_vector(8 downto 0) ; -- divider: 2^9 begin if rising_edge(CLK_20M) then counter:=counter + 1; end if; clk_312khz <= counter(5); end process; --clk_divider1 one:process(CLK_20M) begin if rising_edge(CLK_20M) then cnt_1 <= cnt_1 + 1 ; if (cnt_1 < 20000000) then enable <= '1'; if (cnt_1 = 19999999) then enable <= '0'; end if; end if; end if; end process; two:process(clk_312khz) begin if (enable = '1') then if rising_edge(clk_312khz) then cnt_2 <= cnt_2 + 1; end if; end if; end process; three:process(enable) begin if (enable = '0') then cnt_3 <= cnt_2; a <= std_logic_vector(to_signed(cnt_2,a'length)); end if; end if; end process; end Behavioral;
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_unSIGNED.ALL; use ieee.numeric_std.all; use work.asci_types.all; entity rez is port ( CLK_20M : in STD_LOGIC; SS2_A,SS2_B,SS2_C,SS2_D,SS2_E,SS2_F,SS2_G : out std_logic; SS1_A,SS1_B,SS1_C,SS1_D,SS1_E,SS1_F,SS1_G : out std_logic; LED : out STD_LOGIC_VECTOR (1 downto 0); SW_1 : in std_logic; SW_DIP : in std_logic_vector(4 downto 1) ); end rez; architecture Behavioral of rez is signal a: std_logic_vector(25 downto 0); signal b: std_logic_vector(18 downto 0):="0011000011010100000"; --100,000 signal q: std_logic_vector(7 downto 0); signal clk_312khz :STD_LOGIC;--led(1),,, 3.2 us signal clk_624khz :STD_LOGIC; signal DISP1:std_logic_vector(6 downto 0); signal DISP2:std_logic_vector(6 downto 0); signal cnt_1: integer range 0 to 19999999 :=0 ; signal cnt_2: integer range 0 to 67108863 :=0 ; signal cnt_3: integer range 0 to 67108863 :=0 ; signal enable : STD_LOGIC;-- led(0) begin clk_divider2:process (CLK_20M) variable counter: std_logic_vector(8 downto 0) ; -- divider: 2^9 begin --begin process of clk_divider_for_threstor driver if rising_edge(CLK_20M) then counter:=counter + 1; end if; clk_312khz <= counter(5); clk_624khz <= counter(4); end process; --clk_divider1 one:process(CLK_20M) begin if (SW_DIP > "0000") then if rising_edge(CLK_20M) then cnt_1 <= cnt_1 + 1 ; if (cnt_1 < 20000000) then enable <= '1'; if (cnt_1 = 19999999) then enable <= '0'; end if; end if; end if; end if; end process; two:process(clk_312khz) begin if (enable = '1') then if rising_edge(clk_312khz) then cnt_2 <= cnt_2 + 1; end if; else cnt_2 <=0; end if; end process; three:process(enable) begin if (enable = '0') then cnt_3 <= cnt_2; a <= std_logic_vector(to_signed(cnt_2,a'length)); end if; end process; div_3: Process (clk_312khz,a,b) variable d: std_logic_vector(25 downto 0); Begin if (a(25 downto 7) >= b) then --7 q(7) <= '1'; d:= (( '0' &'0' &'0' &'0' &'0' &'0' &'0' & a(25 downto 7))- ( '0' &'0' &'0' &'0' &'0' &'0' &'0' & b)); d:= d(24 downto 0) & a(6); else q(7) <= '0'; d:= ( '0' &'0' &'0' &'0' &'0' &'0' & a(25 downto 6)); end if; if (d>=('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)) then --6 q(6) <= '1'; d:= (d- ('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)); d:= d(24 downto 0) & a(5); else q(6) <='0'; d:= ( d(24 downto 0) & a(5)); end if; if (d>=('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)) then --5 q(5) <= '1'; d:= (d- ('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)); d:= d(24 downto 0) & a(4); else q(5) <='0'; d:= ( d(24 downto 0) & a(4)); end if; if (d>=('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)) then --4 q(4) <= '1'; d:= (d- ('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)); d:= d(24 downto 0) & a(3); else q(4) <='0'; d:= ( d(24 downto 0) & a(3)); end if; if (d>=('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)) then --3 q(3) <= '1'; d:= (d- ('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)); d:= d(24 downto 0) & a(2); else q(3) <='0'; d:= ( d(24 downto 0) & a(2)); end if; if (d>=('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)) then --2 q(2) <= '1'; d:= (d- ('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)); d:= d(24 downto 0) & a(1); else q(2) <='0'; d:= ( d(24 downto 0) & a(1)); end if; if (d>=('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)) then --1 q(1) <= '1'; d:= (d- ('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)); d:= d(24 downto 0) & a(0); else q(1) <='0'; d:= ( d(24 downto 0) & a(0)); end if; if (d>=('0' & '0' &'0' &'0' &'0' &'0' &'0' & b)) then --0 q(0) <= '1'; else q(0) <='0'; end if; case q(3 downto 0) is when "0000" => DISP1 <= "1111110"; --0 when "0001"=> DISP1 <="0110000";--1 when "0010"=> DISP1 <="1101101";--2 when "0011"=> DISP1 <= "1111001";--3 when "0100"=> DISP1 <="0110011" ;--4 when "0101"=> DISP1 <="1011011";--5 when "0110"=> DISP1 <= "1011111";--6 when "0111"=> DISP1 <="1110000";--7 when "1000"=> DISP1 <="1111111";--8 when "1001"=> DISP1 <="1111011";--9 when "1010"=> DISP1 <="1110111";--A when "1011"=> DISP1 <="0011111";--b when "1100"=> DISP1 <="1001110";--C when "1101"=> DISP1 <="0111101";--d when "1110"=> DISP1 <="1001111";--E when "1111"=> DISP1 <="1000111";--F when others => DISP1 <="1111111"; -- display off end case; SS1_A <= DISP1(6); SS1_B <= DISP1(5); SS1_C <= DISP1(4); SS1_D <= DISP1(3); SS1_E <= DISP1(2); SS1_F <= DISP1(1); SS1_G <= DISP1(0); case q(7 downto 4) is when "0000" => DISP2 <= "1111110"; --0 when "0001"=> DISP2 <="0110000";--1 when "0010"=> DISP2 <="1101101";--2 when "0011"=> DISP2 <= "1111001";--3 when "0100"=> DISP2 <="0110011" ;--4 when "0101"=> DISP2 <="1011011";--5 when "0110"=> DISP2 <= "1011111";--6 when "0111"=> DISP2 <="1110000";--7 when "1000"=> DISP2 <="1111111";--8 when "1001"=> DISP2 <="1111011";--9 when "1010"=> DISP2 <="1110111";--A when "1011"=> DISP2 <="0011111";--b when "1100"=> DISP2 <="1001110";--C when "1101"=> DISP2 <="0111101";--d when "1110"=> DISP2 <="1001111";--E when "1111"=> DISP2 <="1000111";--F when others => DISP2 <="1111111"; -- display off end case; end case; SS2_A <= DISP2(6); SS2_B <= DISP2(5); SS2_C <= DISP2(4); SS2_D <= DISP2(3); SS2_E <= DISP2(2); SS2_F <= DISP2(1); SS2_G <= DISP2(0); end process; LED(0) <= enable; LED(1) <= clk_312khz; end Behavioral;
d:= (( '0' &'0' &'0' &'0' &'0' &'0' &'0' & a(25 downto 7))- ( '0' &'0' &'0' &'0' &'0' &'0' &'0' & b));
d:= d(24 downto 0) & a(6);
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 two:process(clk_312khz) begin if rising_edge(clk_312khz) then -- this should be added if (enable = '1') then -- if rising_edge(clk_312khz) then -- this should be removed. cnt_2 <= cnt_2 + 1; -- end if; else cnt_2 <=0; end if; end process;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 three:process(clk_20M) begin if rising_edge(clk_20M) then if (enable = '0') then cnt_3 <= cnt_2; a <= std_logic_vector(to_signed(cnt_2,a'length)); end if; end if; end process;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?