Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The VHDL code I sent measures the distance using HCSR 0 4 and displays it on the BASYS 3 screen. I want this code to

The VHDL code I sent measures the distance using HCSR04 and displays it on the BASYS3 screen. I want this code to add certain numbers between certain distances and display them on the seven segment display. For example, between 3 and 6 cm, add 5 to the amount, and between 9 and 12 cm, add 10. so when it detects between 3 and 6 cm for 3 times total amount should be 15. In the following code, sw represents the distance which attendet to number.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.std_logic_unsigned.all;
use ieee.NUMERIC_STD.all;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity decimal is
Port ( sw : in std_logic_vector(15 downto 0);
reset : in std_logic;
clk : in std_logic;
an : out std_logic_vector(3 downto 0);
led : out std_logic_vector(6 downto 0));
end decimal;
architecture Behavioral of decimal is
signal LED_BCD : integer;
signal refresh_counter : std_logic_vector(19 downto 0);
signal LED_activating_counter : std_logic_vector(1 downto 0);
signal w0,w1,w2,w3 : integer;
signal number : integer;
signal amount : integer;
begin
process (number)
begin
number <= TO_INTEGER(unsigned(sw));
amount <=0;
if number >=3 and number <=5 then
amount <= amount +20;
--
elsif number >=8 and number <=10 then
amount <= amount +50;
else
amount <= amount;
end if;
end process;
w3<= amount /1000;
w2<=(amount mod 1000)/100;
w1<=(amount mod 100)/10;
w0<=(amount mod 10);
process(LED_BCD)
begin
case LED_BCD is
when 0=> led <="0000001"; --"0"
when 1=> led <="1001111"; --"1"
when 2=> led <="0010010"; --"2"
when 3=> led <="0000110"; --"3"
when 4=> led <="1001100"; --"4"
when 5=> led <="0100100"; --"5"
when 6=> led <="0100000"; --"6"
when 7=> led <="0001111"; --"7"
when 8=> led <="0000000"; --"8"
when 9=> led <="0000100"; --"9"
when others => led <="0000001";
end case;
end process;
process(clk,reset)
begin
if reset='1' then
refresh_counter <=(others =>'0');
elsif rising_edge(clk) then
refresh_counter <= refresh_counter +1;
end if;
end process;
LED_activating_counter <= refresh_counter(19 downto 18);
process(LED_activating_counter)
begin
case LED_activating_counter is
when "00"=>
an <="0111";
LED_BCD <= w3;
when "01"=>
an <="1011";
LED_BCD <= w2;
when "10"=>
an <="1101";
LED_BCD <= w1;
when "11"=>
an <="1110";
LED_BCD <= w0;
end case;
end process;
end Behavioral;
The code is not working properly, can you fix it.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions