정팅정팅!!
ㅎㅅㅎ·2007. 12. 8. PM 8:02:00·조회 199
대화방이 되네요.. 또 저번처럼 됬다가 다시 들어가면 안될지도 모르지만... ㄲㄲ
덤으로...
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 18:48:48 11/23/2007
-- Design Name:
-- Module Name: ex1123_1 - 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_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ex1123_1 is
Port ( CLK : in STD_LOGIC;
RESET : in STD_LOGIC;
sen_in : in STD_LOGIC_VECTOR (0 to 6);
sen_out : out STD_LOGIC_VECTOR (0 to 6);
MOTOR1 : out STD_LOGIC_VECTOR(3 downto 0);
MOTOR2 : out STD_LOGIC_VECTOR(3 downto 0)
);
end ex1123_1;
architecture Behavioral of ex1123_1 is
--light
signal k : integer range 0 to 10000 := 0;
signal s_out : std_logic_vector(0 to 6):= (others => '0');
--count의 최고값
signal max : integer range 0 to 100000 := 20000;
signal min : integer range 0 to 100000 := 4000;
signal L : integer range 0 to 100000 := 10000;
signal R : integer range 0 to 100000 := 10000;
--처음, 끝, 교차로를 알리는 변수
signal S : integer range 0 to 2 := 0;
signal step_cnt : integer range 0 to 1000 := 50;
signal step_reset1 : std_logic := '0';
signal step_reset2 : std_logic := '0';
signal count1 : integer range 0 to 100000 := 0;
signal count2 : integer range 0 to 100000 := 0;
signal motor_clk1 : std_logic := '0';
signal motor_clk2 : std_logic := '0';
signal s_motor1 : std_logic_vector(3 downto 0) := (others => '0');
signal s_motor2 : std_logic_vector(3 downto 0) := (others => '0');
begin
MOTOR1 <= s_motor1;
MOTOR2 <= s_motor2;
SEN_OUT <= s_out;
process (CLK, RESET)
begin
if RESET = '0' then
s_out <= (others => '0');
k <= 0;
elsif rising_edge(CLK) then
if k = 200 then
k <= 0;
s_out <= not s_out;
else
k <= k + 1;
end if;
end if;
end process;
--왼쪽
process(RESET,CLK, sen_in)
begin
if RESET = '0' then
count1 <= 0;
motor_clk1 <= '0';
L <= 10000;
elsif rising_edge(CLK) then
--도착
if S = 2 then
if count1 = L then
if L < MAX then
L <= L + 20;
else
L <= 0;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
else
case sen_in is
--직진
when "0001000" =>
if count1 = L then
if L > MIN then
L <= L - 20;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
when "0001100" =>
if count1 = L then
if L > MIN then
L <= L - 20;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
when "0011000" =>
if count1 = L then
if L > MIN then
L <= L - 17;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
--회전1
when "0000100" =>
if count1 = L then
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
when "0010000" =>
if count1 = L then
if L < MAX then
L <= L + 5;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
--회전2
when "0000110" =>
if count1 = L then
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
when "0110000" =>
if count1 = L then
if L < MAX then
L <= L + 10;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
--회전3
when "0000010" =>
if count1 = L then
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
when "0100000" =>
if count1 = L then
if L < MAX then
L <= L + 15;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
--시작선, 도착선, 교차로, 탈선.;;;
when others =>
if count1 = L then
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
end case;
end if;
end if;
end process;
--오른쪽
process(RESET,CLK, sen_in)
begin
if RESET = '0' then
count2 <= 0;
motor_clk2 <= '0';
R <= 10000;
elsif rising_edge(CLK) then
--도착
if S = 2 then
if count2 = R then
if R < MAX then
R <= R + 20;
else
R <= 0;
end if;
motor_clk2 <= '1';
count2 <= 0;
else
motor_clk2 <= '0';
count2 <= count2 + 1;
end if;
else
case sen_in is
--직진
when "0001000" =>
if count2 = R then
R <= L;
motor_clk2 <= '1';
count2 <= 0;
else
motor_clk2 <= '0';
count2 <= count2 + 1;
end if;
when "0001100" =>
if count2 = R then
R <= R - 17;
motor_clk2 <= '1';
count2 <= 0;
else
motor_clk2 <= '0';
count2 <= count2 + 1;
end if;
when "0011000" =>
if count2 = R then
R <= R - 20;
motor_clk2 <= '1';
count2 <= 0;
else
motor_clk2 <= '0';
count2 <= count2 + 1;
end if;
.......................... 대충 이렇게 나가는 건데... 400라인이 넘는건데..
너무 길어서 이것 밖에 안나오내요. ㅠ
이번 논리회로실험 프로젝트 - 라인 트레이서의 소프트웨어 부분이랄까. ;
VHDL이라는 프로그래밍 언어이구요.
이걸 하드웨어에 처 넣고 작동시키면..
까만바닥위의 하얀선을 따라서 하드웨어가 쫘악 달려갑니다.
출발선을 지나서 직선코스, 곡선코스, 교차로를 지나 도착선에 도착하면 다시 출발선을 지나기 전에 멈추게 됩니다.
요즘 이것때문에 속이 좀 탑니다. ㄲㄲ
너무 세세하게 짜다보니 작동은 안하고 코드길이만 늘어나고. ㅠ
달리고 싶어하는 우리 붕붕이의 욕구를 어서 충족시켜줘야 할텐데요. ㅋ
덤으로...
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 18:48:48 11/23/2007
-- Design Name:
-- Module Name: ex1123_1 - 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_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ex1123_1 is
Port ( CLK : in STD_LOGIC;
RESET : in STD_LOGIC;
sen_in : in STD_LOGIC_VECTOR (0 to 6);
sen_out : out STD_LOGIC_VECTOR (0 to 6);
MOTOR1 : out STD_LOGIC_VECTOR(3 downto 0);
MOTOR2 : out STD_LOGIC_VECTOR(3 downto 0)
);
end ex1123_1;
architecture Behavioral of ex1123_1 is
--light
signal k : integer range 0 to 10000 := 0;
signal s_out : std_logic_vector(0 to 6):= (others => '0');
--count의 최고값
signal max : integer range 0 to 100000 := 20000;
signal min : integer range 0 to 100000 := 4000;
signal L : integer range 0 to 100000 := 10000;
signal R : integer range 0 to 100000 := 10000;
--처음, 끝, 교차로를 알리는 변수
signal S : integer range 0 to 2 := 0;
signal step_cnt : integer range 0 to 1000 := 50;
signal step_reset1 : std_logic := '0';
signal step_reset2 : std_logic := '0';
signal count1 : integer range 0 to 100000 := 0;
signal count2 : integer range 0 to 100000 := 0;
signal motor_clk1 : std_logic := '0';
signal motor_clk2 : std_logic := '0';
signal s_motor1 : std_logic_vector(3 downto 0) := (others => '0');
signal s_motor2 : std_logic_vector(3 downto 0) := (others => '0');
begin
MOTOR1 <= s_motor1;
MOTOR2 <= s_motor2;
SEN_OUT <= s_out;
process (CLK, RESET)
begin
if RESET = '0' then
s_out <= (others => '0');
k <= 0;
elsif rising_edge(CLK) then
if k = 200 then
k <= 0;
s_out <= not s_out;
else
k <= k + 1;
end if;
end if;
end process;
--왼쪽
process(RESET,CLK, sen_in)
begin
if RESET = '0' then
count1 <= 0;
motor_clk1 <= '0';
L <= 10000;
elsif rising_edge(CLK) then
--도착
if S = 2 then
if count1 = L then
if L < MAX then
L <= L + 20;
else
L <= 0;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
else
case sen_in is
--직진
when "0001000" =>
if count1 = L then
if L > MIN then
L <= L - 20;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
when "0001100" =>
if count1 = L then
if L > MIN then
L <= L - 20;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
when "0011000" =>
if count1 = L then
if L > MIN then
L <= L - 17;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
--회전1
when "0000100" =>
if count1 = L then
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
when "0010000" =>
if count1 = L then
if L < MAX then
L <= L + 5;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
--회전2
when "0000110" =>
if count1 = L then
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
when "0110000" =>
if count1 = L then
if L < MAX then
L <= L + 10;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
--회전3
when "0000010" =>
if count1 = L then
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
when "0100000" =>
if count1 = L then
if L < MAX then
L <= L + 15;
end if;
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
--시작선, 도착선, 교차로, 탈선.;;;
when others =>
if count1 = L then
motor_clk1 <= '1';
count1 <= 0;
else
motor_clk1 <= '0';
count1 <= count1 + 1;
end if;
end case;
end if;
end if;
end process;
--오른쪽
process(RESET,CLK, sen_in)
begin
if RESET = '0' then
count2 <= 0;
motor_clk2 <= '0';
R <= 10000;
elsif rising_edge(CLK) then
--도착
if S = 2 then
if count2 = R then
if R < MAX then
R <= R + 20;
else
R <= 0;
end if;
motor_clk2 <= '1';
count2 <= 0;
else
motor_clk2 <= '0';
count2 <= count2 + 1;
end if;
else
case sen_in is
--직진
when "0001000" =>
if count2 = R then
R <= L;
motor_clk2 <= '1';
count2 <= 0;
else
motor_clk2 <= '0';
count2 <= count2 + 1;
end if;
when "0001100" =>
if count2 = R then
R <= R - 17;
motor_clk2 <= '1';
count2 <= 0;
else
motor_clk2 <= '0';
count2 <= count2 + 1;
end if;
when "0011000" =>
if count2 = R then
R <= R - 20;
motor_clk2 <= '1';
count2 <= 0;
else
motor_clk2 <= '0';
count2 <= count2 + 1;
end if;
.......................... 대충 이렇게 나가는 건데... 400라인이 넘는건데..
너무 길어서 이것 밖에 안나오내요. ㅠ
이번 논리회로실험 프로젝트 - 라인 트레이서의 소프트웨어 부분이랄까. ;
VHDL이라는 프로그래밍 언어이구요.
이걸 하드웨어에 처 넣고 작동시키면..
까만바닥위의 하얀선을 따라서 하드웨어가 쫘악 달려갑니다.
출발선을 지나서 직선코스, 곡선코스, 교차로를 지나 도착선에 도착하면 다시 출발선을 지나기 전에 멈추게 됩니다.
요즘 이것때문에 속이 좀 탑니다. ㄲㄲ
너무 세세하게 짜다보니 작동은 안하고 코드길이만 늘어나고. ㅠ
달리고 싶어하는 우리 붕붕이의 욕구를 어서 충족시켜줘야 할텐데요. ㅋ