Chap. 18 라인 트레이서의 설계 라인 트레이서 바닥에 그려진 선을 따라가는 로봇을 의미 라인 트레이서 구성도 (선을 잘 따라가도록 판단 및 제어) (바퀴를 굴려줌) (선 감지)
라인 트레이서의 설계 - 개념도 라인 트레이서 VHDL 코드 작성 개념도
라인 트레이서의 설계 - Design 센서 데이터에 따른 좌,우 모터 속도 결정 센서 데이터 (중앙의 5비트) 좌, 우 모터 속도 (11:320Hz, 10:200Hz, 01:100Hz, 00:정지) 좌 우 비고 11011 11 빠른 직진 10001 01 느린 직진 10011 10 느린 우회전 10111 빠른 우회전 00011 00111 01111 11001 느린 좌회전 11101 빠른 좌회전 11000 11100 11110 그 외 00 정지
라인 트레이서의 설계 - Design library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity line_tracer is Port ( RSTB : in std_logic; CLK_4M : in std_logic; SENSE : in std_logic_vector(6 downto 0); LIGHT : out std_logic_vector(6 downto 0); MTL_A : out std_logic; MTL_B : out std_logic; MTL_nA : out std_logic; MTL_nB : out std_logic; MTR_A : out std_logic; MTR_B : out std_logic; MTR_nA : out std_logic; MTR_nB : out std_logic); end line_tracer; architecture Behavioral of line_tracer is signal clk_500 : std_logic; signal mtl_speed : std_logic_vector (1 downto 0); signal mtr_speed : std_logic_vector (1 downto 0); signal speed_l : integer range 0 to 25000; signal speed_r : integer range 0 to 25000; signal motor_lcnt : integer range 0 to 25000; signal phase_lclk : std_logic; signal motor_rcnt : integer range 0 to 25000; signal phase_rclk : std_logic; signal phase_lcnt : std_logic_vector (1 downto 0); signal phase_lout : std_logic_vector (3 downto 0); signal phase_rcnt : std_logic_vector (1 downto 0); signal phase_rout : std_logic_vector (3 downto 0); begin =========Clock(500Hz)Generator=================== process(RSTB,CLK_4M) variable cnt : integer range 0 to 4000; begin if RSTB = '0' then cnt := 0; clk_500 <= '0'; elsif rising_edge (CLK_4M) then if cnt >= 3999 then --정상 동작시 -- if cnt >= 2 then --시뮬레이션시 clk_500 <= not clk_500; else cnt := cnt + 1; end if; end if; end process; =============================================
라인 트레이서의 설계 - Design --========== Infrared Light Emission =========== LIGHT(0) <= clk_500 ; LIGHT(1) <= clk_500 ; LIGHT(2) <= clk_500 ; LIGHT(3) <= clk_500 ; LIGHT(4) <= clk_500 ; LIGHT(5) <= clk_500 ; LIGHT(6) <= clk_500 ; --========================================= --=== Line Status Sensing & 좌,우 모터 속도값 결정 ===== process(RSTB,CLK_500) begin if RSTB = '0' then mtl_speed <="00"; mtr_speed <="00"; -- 느린 직진 elsif falling_edge (CLK_500) then case SENSE is when "1110111" => mtl_speed <="11"; mtr_speed <="11"; -- 빠른직진 when "1100011" => mtl_speed <="01"; mtr_speed <="01"; -- 느린직진 when "1100111" => mtl_speed <="11"; mtr_speed <="10"; -- 느린우회전 when "1000111" => mtl_speed <="11"; mtr_speed <="01"; -- 빠른우회전 when "1001111" => mtl_speed <="11"; mtr_speed <="01"; -- 빠른우회전 when "1011111" => mtl_speed <="11"; mtr_speed <="01"; -- 빠른우회전 when "1110011" => mtl_speed <="10"; mtr_speed <="11"; -- 느린좌회전 when "1111011" => mtl_speed <="01"; mtr_speed <="11"; -- 빠른좌회전 when "1110001" => mtl_speed <="01"; when "1111001" => mtl_speed <="01"; when "1111101" => mtl_speed <="01"; when others => mtl_speed <="00"; mtr_speed <="00"; -- 정지 end case; end if; end process;
라인 트레이서의 설계 - Design ==== 모터속도값에 따른 좌,우모터 속도결정 ==== process(mtl_speed) ==== 모터속도값에 따른 좌,우모터 속도결정 ==== process(mtl_speed) variable for_sim : std_logic; begin for_sim := '0'; -- 1: 시뮬레이션시 0:정상동작시 if for_sim = '0' then case mtl_speed is when "00" => speed_l <= 0; -- 0 Hz when "01" => speed_l <= 19999;-- 100Hz when "10" => speed_l <= 9999; -- 200 Hz when "11" => speed_l <= 6249; -- 320Hz when others => speed_l <= 6249; end case; else when "00" => speed_l <= 0 ; when "01" => speed_l <= 8; when "10" => speed_l <= 4; when "11" => speed_l <= 2; when others => speed_l <= 2; end case; end if; end process; process(mtr_speed) variable for_sim : std_logic; begin for_sim := '0'; -- 1: 시뮬레이션시 0:정상동작시 if for_sim = '0' then case mtr_speed is when "00" => speed_r <= 0; -- 0 Hz when "01" => speed_r <= 19999;-- 100Hz when "10" => speed_r <= 9999; -- 200Hz when "11" => speed_r <= 6249; -- 320Hz when others => speed_r <= 6249; --320Hz end case; else case mtr_speed is when "00" => speed_r <= 0; when "01" => speed_r <= 8; when "10" => speed_r <= 4; when "11" => speed_r <= 2; when others => speed_r <= 2; end case; end if; end process;
라인 트레이서의 설계 - Design process(RSTB,speed_l, CLK_4M,motor_lcnt) begin if RSTB = '0' or speed_l = 0 then motor_lcnt <= 0; phase_lclk <= '0'; elsif rising_edge (CLK_4M) then if (motor_lcnt >= speed_l) then motor_lcnt <= 0; phase_lclk <= not phase_lclk; else motor_lcnt <= motor_lcnt + 1; end if; end if; end process; process(RSTB,speed_r, CLK_4M,motor_rcnt) if RSTB = '0' or speed_r = 0 then motor_rcnt <= 0; phase_rclk <= '0'; elsif rising_edge (CLK_4M) then if (motor_rcnt >= speed_r) then motor_rcnt <= 0; phase_rclk <= not phase_rclk; else motor_rcnt <= motor_rcnt + 1; end if; end if; --===================================== --===== 왼쪽 모터 phase Output(1상 여자방식) ====== process(RSTB,phase_lclk,phase_lcnt) begin if RSTB = '0' then phase_lcnt <= (others => '0'); elsif rising_edge (phase_lclk) then phase_lcnt <= phase_lcnt + 1; end if; end process; process(RSTB, phase_lcnt) begin if RSTB = '0' then phase_lout <= (others => '0'); else case phase_lcnt is when "00" => phase_lout <= "1000"; when "01" => phase_lout <= "0100"; when "10" => phase_lout <= "0010"; when "11" => phase_lout <= "0001"; when others => phase_lout <= "0000"; end case; end if; end process; --===========================
--========================================== 라인 트레이서의 설계 - Design --====== 오른쪽 Phase Output(1상 여자방식) ========= process(RSTB,phase_rclk,phase_rcnt) begin if RSTB = '0' then phase_rcnt <= (others => '0'); elsif rising_edge (phase_rclk) then phase_rcnt <= phase_rcnt + 1; end if; end process; process(RSTB, phase_rcnt) begin if RSTB = '0' then phase_rout <= (others => '0'); else case phase_rcnt is when "00" => phase_rout <= "0001"; when "01" => phase_rout <= "0010"; when "10" => phase_rout <= "0100"; when "11" => phase_rout <= "1000"; when others => phase_rout <= "0000"; end case; end if; --========================================== MTL_A <= phase_lout(0); MTL_B <= phase_lout(1); MTL_nA <= phase_lout(2); MTL_nB <= phase_lout(3); MTR_A <= phase_rout(0); MTR_B <= phase_rout(1); MTR_nA <= phase_rout(2); MTR_nB <= phase_rout(3); end Behavioral;
라인 트레이서의 설계 - Simulation 라인 트레이서의 시뮬레이션 결과 파형 화면