Question: How do I change this code to count only from 0-9999 ignoring hex digits on the 7 segment display? (VHDL) library IEEE; use IEEE.STD_LOGIC_1164.ALL; use
How do I change this code to count only from 0-9999 ignoring hex digits on the 7 segment display? (VHDL)
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.std_logic_unsigned.all;
entity segment_display is -------clock enable with 100Mhz by default ------------------------ Port ( default_clock : in STD_LOGIC; ------------ --------reset----------------------------------------------- RESTART : in STD_LOGIC; ------------ AN0 , AN1, AN2, AN3----------------------------------------- AnodeON : out STD_LOGIC_VECTOR (3 downto 0); -------------- CA, CB, CC, CD, CE, CF, CG --------------------------------------- LEDOUTPUT : out STD_LOGIC_VECTOR (6 downto 0)); end segment_display; architecture Behavioral of segment_display is -----------------counter for generating 1-second clock enable-----------------------------
signal one_second_counter: STD_LOGIC_VECTOR (27 downto 0); signal DELAY: std_logic; signal DISPLAYDIGITE: STD_LOGIC_VECTOR (15 downto 0);
-----------------one second enable for counting numbers------------------------------------------- signal REFRESHCOUNT: STD_LOGIC_VECTOR (19 downto 0); -- creating 10.5ms refresh period -- counting decimal number to be displayed on 4-digit 7-segment display signal LEDCONFIG: STD_LOGIC_VECTOR (3 downto 0); --3-0 signal LED_activating_counter: std_logic_vector(1 downto 0);--1-0 -- the other 2-bit for creating 4 LED-activating signals ---- count 0 -> 1 -> 2 -> 3 ---- activates LED1 LED2 LED3 LED4 ---- and repeat
begin ------------------BCD to 7-segment decoder---------------------------------- ------------------Cathode patterns of the 7-segment LED display --------------- process (LEDCONFIG) begin case LEDCONFIG is when "0000" => LEDOUTPUT <= "0000001"; -- "0" when "0001" => LEDOUTPUT <= "1001111"; -- "1" when "0010" => LEDOUTPUT <= "0010010"; -- "2" when "0011" => LEDOUTPUT <= "0000110"; -- "3" when "0100" => LEDOUTPUT <= "1001100"; -- "4" when "0101" => LEDOUTPUT <= "0100100"; -- "5" when "0110" => LEDOUTPUT <= "0100000"; -- "6" when "0111" => LEDOUTPUT <= "0001111"; -- "7" when "1000" => LEDOUTPUT <= "0000000"; -- "8" when "1001" => LEDOUTPUT <= "0000100"; -- "9" when others => LEDOUTPUT <= "1111111"; -- Off end case; end process;
-- 7-segment display controller -- generate refresh period of 10.5ms process(default_clock,RESTART) begin if(RESTART='1') then REFRESHCOUNT <= (others => '0'); elsif(rising_edge(default_clock)) then REFRESHCOUNT <= REFRESHCOUNT + 1; end if; end process; LED_activating_counter <= REFRESHCOUNT(19 downto 18);
--- 4-to-1 MUX to generate anode activating signals for 4 LEDs process(LED_activating_counter) begin case LED_activating_counter is when "00" => AnodeON <= "0111"; --activate LED1 and Deactivate LED2, LED3, LED4 LEDCONFIG <= DISPLAYDIGITE(15 downto 12); -- the first hex digit of the 16-bit number when "01" => AnodeON <= "1011"; -- activate LED2 and Deactivate LED1, LED3, LED4 LEDCONFIG <= DISPLAYDIGITE(11 downto 8); -- the second hex digit of the 16-bit number when "10" => AnodeON <= "1101"; -- activate LED3 and Deactivate LED2, LED1, LED4 LEDCONFIG <= DISPLAYDIGITE(7 downto 4); -- the third hex digit of the 16-bit number when "11" => AnodeON <= "1110"; -- activate LED4 and Deactivate LED2, LED3, LED1 LEDCONFIG <= DISPLAYDIGITE(3 downto 0); -- the fourth hex digit of the 16-bit number end case; end process;
-- Counting the number to be displayed on 4-digit 7-segment Display -- on Basys 3 FPGA board
process(default_clock,RESTART) begin if(RESTART='1') then one_second_counter <= (others => '0'); elsif(rising_edge(default_clock)) then if(one_second_counter>=x"5F5E0FF") then one_second_counter <= (others => '0'); else one_second_counter <= one_second_counter + "0000001"; end if; end if; end process; DELAY <= '1' when one_second_counter=x"5F5E0FF" else '0'; process(default_clock,RESTART) begin if(RESTART='1') then DISPLAYDIGITE <= (others => '0'); elsif(rising_edge(default_clock)) then if(DELAY='1') then
--new code start for a mod -10 values
if( DISPLAYDIGITE = "0000100") then
DISPLAYDIGITE<="0000001";
else DISPLAYDIGITE <= DISPLAYDIGITE + x"1001111";
end if;
--new code end end if; end if; end process;
end Behavioral;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
