Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This VHDL code measures the distance with HCSR 0 4 . I want to add some values to the amount in specified distances and shows

This VHDL code measures the distance with HCSR04. I want to add some values to the amount in specified distances and shows it on seven segment display. The code that I sent always increases 15 whether sensor dedect in specified distances or not but want to increase 5 when sensor detect between 3-6 and 10 between 9-12.
can you fix it according to this arrangements.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.std_logic_unsigned.all;
use ieee.NUMERIC_STD.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 :=0;
signal number : integer :=0;
signal amount : integer :=0;
signal prev_number : integer :=0; -- To store previous number for comparison
begin
process (clk, reset)
begin
if reset ='1' then
refresh_counter <=(others =>'0');
number <=0;
amount <=0;
prev_number <=0;
elsif rising_edge(clk) then
refresh_counter <= refresh_counter +1;
number <= TO_INTEGER(unsigned(sw));
-- Conditional increment logic
if (number >=3 and number <=6) and not (prev_number >=3 and prev_number <=6) then
amount <= amount +5;
elsif (number >=9 and number <=12) and not (prev_number >=9 and prev_number <=12) then
amount <= amount +10;
end if;
prev_number <= number; -- Update previous number
end if;
end process;
w3<= amount /1000;
w2<=(amount mod 1000)/100;
w1<=(amount mod 100)/10;
w0<=(amount mod 10);
process(clk)
begin
if rising_edge(clk) then
case refresh_counter(19 downto 18) 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;
when others =>
null; -- Do nothing
end case;
end if;
end process;
-- Seven-segment display decoder
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"; -- Default or error case
end case;
end process;
end Behavioral;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

Describe the role of AI in customer service.

Answered: 1 week ago

Question

Identify ways to increase your selfesteem.

Answered: 1 week ago