Skip to content
Snippets Groups Projects
Commit 00427189 authored by Pascal Engeler's avatar Pascal Engeler
Browse files

Started work on distance unwrapping module

parent fe173336
No related branches found
No related tags found
1 merge request!2Resolve "Distance wrapping invalidates lock sum"
----------------------------------------------------------------------------------
-- Company: ETH Zurich
-- Engineer: Pascal Engeler <engeler.pascal@gmail.com>
--
-- Create Date: 14:32:01 09/06/2024
-- Design Name:
-- Module Name: DistanceUnwrapper - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.NUMERIC_STD.ALL;
entity DistanceUnwrapper is
Port ( clk100 : in STD_LOGIC;
en : in STD_LOGIC;
dr : in STD_LOGIC;
distance_in : in STD_LOGIC_VECTOR(20 downto 0);
distance_out : out STD_LOGIC_VECTOR(24 downto 0);
dr_out : out STD_LOGIC);
end DistanceUnwrapper;
architecture Behavioral of DistanceUnwrapper is
type STATE_T is (IDLE_S, STATE1, STATE2, STATE3, STATE4, STATE5, STATE6);
signal current_state : STATE_T := IDLE_S;
signal currentDistance : STD_LOGIC_VECTOR(24 downto 0) := (others => '0');
signal prevDistance : STD_LOGIC_VECTOR(24 downto 0) := (others => '0');
signal distanceInWide : STD_LOGIC_VECTOR(24 downto 0) := (others => '0');
signal calcDelta : STD_LOGIC_VECTOR(24 downto 0) := (others => '0');
signal maxDelta : STD_LOGIC_VECTOR(24 downto 0) := "0000100000000000000000000";
signal corrDelta : STD_LOGIC_VECTOR(24 downto 0) := "0001000000000000000000000";
signal corrDeltaN : STD_LOGIC_VECTOR(24 downto 0) := "1111000000000000000000000";
signal currentOffset : STD_LOGIC_VECTOR(24 downto 0) := (others => '0');
signal dr_prev : STD_LOGIC := '0';
begin
distanceInWide(20 downto 0) <= distance_in;
distanceInWide(24 downto 21) <= (others => '0');
dr_update: process(clk100)
begin
if rising_edge(clk100) then
dr_prev <= dr;
end if;
end process;
proc: process(clk100)
begin
if rising_edge(clk100) then
if en = '1' then
case current_state is
when IDLE_S =>
if dr = '1' and dr_prev = '0' then
current_state <= STATE1;
--calculate relevant delta distance here
if prevDistance > distanceInWide then
calcDelta <= prevDistance - distanceInWide;
else
calcDelta <= distanceInWide - prevDistance;
else
end if;
when STATE1 =>
current_state <= STATE2;
--calculate change to offset here
when STATE2 =>
current_state <= STATE3;
--calculate output distance here
when STATE3 =>
current_state <= IDLE_S;
--set output ready here
end case;
else
currentDistance <= (others => '0');
prevDistance <= (others => '0');
end if;
end if;
end process;
signal cmd_received_sig : STD_LOGIC := '0';
signal rxs : STD_LOGIC := '0';
signal rx_delay_line: STD_LOGIC_VECTOR(5 downto 0);
signal serial_data : STD_LOGIC_VECTOR(9 downto 0) := (others => '0');
signal serial_counter : STD_LOGIC_VECTOR (9 downto 0) := (others => '0');
--baud rate: 115200
signal serial_counter_max : STD_LOGIC_VECTOR(9 downto 0) := "1101100011"; --change this for baud rate change
signal serial_counter_offset : STD_LOGIC_VECTOR(9 downto 0) := "0110110001"; --change this for baud rate change
begin
sanitize_input: process(clk100)
begin
if rising_edge(clk100) then
rx_delay_line(5) <= s_data_in;
rx_delay_line(4 downto 0) <= rx_delay_line(5 downto 1);
rxs <= rx_delay_line(0);
end if;
end process;
receive_serial: process(clk100)
begin
if rising_edge(clk100) then
if(rxs = '1') AND (serial_data(0) = '0') then
serial_data <= "1111111111";
cmd_received_sig <= '0';
serial_counter <= serial_counter_offset;
else
if (serial_counter = serial_counter_max) AND (serial_data(0) = '1') then
serial_counter <= (others => '0');
serial_data(8 downto 0) <= serial_data(9 downto 1);
serial_data(9) <= NOT rxs;
cmd_received_sig <= not serial_data(1); --this should maybe be serial_data(0) update: no, i think this is correct.
else
serial_counter <= serial_counter + 1;
cmd_received_sig <= '0';
serial_data <= serial_data;
end if;
end if;
end if;
end process;
data <= serial_data(8 downto 1);
cmd_received <= cmd_received_sig;
end Behavioral;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment