1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-22 08:06:04 +01:00
cdf2018-principal/fpga/Principal.vhd

288 lines
9.8 KiB
VHDL
Raw Normal View History

2018-02-07 17:57:01 +01:00
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
2018-02-07 17:57:01 +01:00
entity Principal is
2018-02-27 19:33:58 +01:00
Generic(
fFpga : INTEGER := 50_000_000;
2018-05-01 15:13:24 +02:00
fBaud : INTEGER := 115200
2018-02-27 19:33:58 +01:00
);
Port (
CLK : in std_logic;
BTN: in std_logic;
RX: in std_logic;
TX: out std_logic;
LEFTCHA: in std_logic;
LEFTCHB: in std_logic;
RIGHTCHA: in std_logic;
RIGHTCHB: in std_logic;
FRONTTRIGGER: out std_logic;
FRONTECHO: in std_logic;
BACKTRIGGER: out std_logic;
2018-05-01 08:45:02 +02:00
BACKECHO: in std_logic;
2018-05-09 01:00:40 +02:00
ENAREF: out std_logic;
2018-05-01 08:45:02 +02:00
ENA: out std_logic;
IN1ENC: out std_logic;
IN2: out std_logic;
2018-05-09 01:00:40 +02:00
ENBREF: out std_logic;
2018-05-01 08:45:02 +02:00
ENB: out std_logic;
IN3END: out std_logic;
IN4: out std_logic
2018-02-27 19:33:58 +01:00
);
2018-02-07 17:57:01 +01:00
end Principal;
architecture Behavioral of Principal is
-- General
signal reset : std_logic := '0';
-- Encoder
signal left : integer;
signal right : integer;
2018-02-27 10:41:33 +01:00
signal zerocoder : std_logic;
component hedm is
Port (
clk : in STD_LOGIC;
chA : in STD_LOGIC;
chB : in STD_LOGIC;
reset : in STD_LOGIC;
zero : in STD_LOGIC;
counts : out integer
);
end component;
2018-02-28 12:06:11 +01:00
-- Distance sensors
2018-02-27 10:41:33 +01:00
signal front : integer := 0;
2018-02-28 12:06:11 +01:00
signal frontRaw : integer := 0;
signal frontFinished : std_logic;
2018-02-27 10:41:33 +01:00
signal back : integer := 0;
2018-02-28 12:06:11 +01:00
signal backRaw : integer := 0;
signal backFinished : std_logic;
2018-02-27 19:33:58 +01:00
component hcsr04 IS
generic(
fFpga : INTEGER := fFpga
);
port(
clk : IN STD_LOGIC;
reset : IN STD_LOGIC;
echo : IN STD_LOGIC;
distance : OUT INTEGER;
trigger : OUT STD_LOGIC;
start : IN STD_LOGIC;
finished : OUT STD_LOGIC
);
end component;
2018-02-28 12:06:11 +01:00
component fir is
Port (
clock : in STD_LOGIC;
reset : in STD_LOGIC;
signalIn : in INTEGER;
signalOut : out INTEGER;
start : in STD_LOGIC;
done : out STD_LOGIC
);
end component;
2018-05-02 05:50:33 +02:00
-- PWM clock
signal pwmClk : std_logic := '0';
signal pwmCounter : integer := 0;
2018-05-06 12:50:03 +02:00
constant PWM_DIVIDER : integer := 4096;
2018-05-02 05:50:33 +02:00
2018-05-01 08:45:02 +02:00
-- Motor controller
signal enAd : std_logic_vector(7 downto 0);
signal in1enCd : std_logic_vector(7 downto 0);
signal in2d : std_logic;
signal enBd : std_logic_vector(7 downto 0);
signal in3enDd : std_logic_vector(7 downto 0);
signal in4d : std_logic;
component PWM is
port (
clk : in std_logic;
data : in std_logic_vector (7 downto 0);
pulse : out std_logic
);
end component;
-- CF
component uart is
generic (
2018-02-27 19:33:58 +01:00
baud : positive := fBaud;
clock_frequency : positive := fFpga
);
port (
clock : in std_logic;
reset : in std_logic;
data_stream_in : in std_logic_vector(7 downto 0);
data_stream_in_stb : in std_logic;
data_stream_in_ack : out std_logic;
data_stream_out : out std_logic_vector(7 downto 0);
data_stream_out_stb : out std_logic;
tx : out std_logic;
rx : in std_logic
);
end component;
signal txData : std_logic_vector(7 downto 0);
signal txStb : std_logic := '0';
signal txAck : std_logic := '0';
signal rxData : std_logic_vector(7 downto 0);
signal rxStb : std_logic := '0';
-- Handling
component communication is
Port (
clock : in std_logic;
reset : in std_logic;
left : in integer;
right : in integer;
2018-02-27 10:41:33 +01:00
zerocoder : out std_logic;
front : in integer;
back : in integer;
txData : out std_logic_vector(7 downto 0);
txStb : out std_logic;
txAck : in std_logic;
rxData : in std_logic_vector(7 downto 0);
2018-05-01 08:45:02 +02:00
rxStb : in std_logic;
enA : out std_logic_vector(7 downto 0);
in1enC : out std_logic_vector(7 downto 0);
in2 : out std_logic;
enB : out std_logic_vector(7 downto 0);
in3enD : out std_logic_vector(7 downto 0);
in4 : out std_logic
);
end component;
2018-02-07 17:57:01 +01:00
begin
reset <= BTN;
2018-05-02 05:50:33 +02:00
pwmClkGenerator: process (clk) begin
if rising_edge(clk) then
if (pwmCounter >= PWM_DIVIDER) then
pwmClk <= not pwmClk;
pwmCounter <= 0;
else
pwmCounter <= pwmCounter + 1;
end if;
end if;
end process;
2018-02-27 10:41:33 +01:00
leftCoder: hedm port map (
2018-02-27 19:33:58 +01:00
clk => CLK,
chA => LEFTCHA,
chB => LEFTCHB,
reset => reset,
zero => zerocoder,
counts => left
);
2018-02-27 10:41:33 +01:00
rightCoder: hedm port map (
2018-02-27 19:33:58 +01:00
clk => CLK,
chA => RIGHTCHA,
chB => RIGHTCHB,
reset => reset,
zero => zerocoder,
counts => right
);
2018-02-28 12:06:11 +01:00
2018-02-27 19:33:58 +01:00
frontCapt: hcsr04 port map (
clk => CLK,
reset => reset,
echo => FRONTECHO,
2018-02-28 12:06:11 +01:00
distance => frontRaw,
2018-02-27 19:33:58 +01:00
trigger => FRONTTRIGGER,
2018-02-28 12:06:11 +01:00
start => '1',
finished => frontFinished
);
frontFilter : FIR port map (
clock => CLK,
reset => reset,
signalIn => frontRaw,
signalOut => front,
start => frontFinished
-- done => done
2018-02-27 19:33:58 +01:00
);
backCapt: hcsr04 port map (
clk => CLK,
reset => reset,
echo => BACKECHO,
2018-02-28 12:06:11 +01:00
distance => backRaw,
2018-02-27 19:33:58 +01:00
trigger => BACKTRIGGER,
2018-02-28 12:06:11 +01:00
start => '1',
finished => backFinished
);
backFilter : FIR port map (
clock => CLK,
reset => reset,
signalIn => backRaw,
signalOut => back,
start => backFinished
2018-05-01 08:45:02 +02:00
-- done => done
2018-02-27 19:33:58 +01:00
);
2018-05-01 08:45:02 +02:00
enAp : PWM port map (
2018-05-02 05:50:33 +02:00
clk => pwmClk,
2018-05-01 08:45:02 +02:00
data => enAd,
pulse => ENA
);
2018-05-09 01:00:40 +02:00
ENAREF <= '1';
2018-05-01 08:45:02 +02:00
in1enCp : PWM port map (
2018-05-02 05:50:33 +02:00
clk => pwmClk,
2018-05-01 08:45:02 +02:00
data => in1enCd,
pulse => IN1ENC
);
IN2 <= in2d;
enBp : PWM port map (
2018-05-02 05:50:33 +02:00
clk => pwmClk,
2018-05-01 08:45:02 +02:00
data => enBd,
pulse => ENB
);
2018-05-09 01:00:40 +02:00
ENBREF <= '1';
2018-02-27 10:41:33 +01:00
2018-05-01 08:45:02 +02:00
in3enDp : PWM port map (
2018-05-02 05:50:33 +02:00
clk => pwmClk,
2018-05-01 08:45:02 +02:00
data => in3enDd,
pulse => IN3END
);
IN4 <= in4d;
2018-02-28 12:06:11 +01:00
FA: uart port map(
clock => CLK,
reset => reset,
data_stream_in => txData,
data_stream_in_stb => txStb,
data_stream_in_ack => txAck,
data_stream_out => rxData,
data_stream_out_stb => rxStb,
2018-02-27 19:33:58 +01:00
tx => TX,
rx => RX
);
com: communication port map(
clock => CLK,
reset => reset,
left => left,
right => right,
2018-02-27 10:41:33 +01:00
zerocoder => zerocoder,
front => front,
back => back,
txData => txData,
txStb => txStb,
txAck => txAck,
rxData => rxData,
2018-05-01 08:45:02 +02:00
rxStb => rxStb,
enA => enAd,
in1enC => in1enCd,
in2 => in2d,
enB => enBd,
in3enD => in3enDd,
in4 => in4d
);
2018-02-07 17:57:01 +01:00
end Behavioral;