Design library IEEE use IEEE STDLOGIC1164 ALL use
라인 트레이서의 설계 - Design library IEEE; use IEEE. STD_LOGIC_1164. ALL; use IEEE. STD_LOGIC_ARITH. ALL; use IEEE. STD_LOGIC_UNSIGNED. ALL; signal signal entity line_tracer is Port ( RSTB : in std_logic; CLK_4 M : 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_n. A : out std_logic; MTL_n. B : out std_logic; MTR_A : out std_logic; MTR_B : out std_logic; MTR_n. A : out std_logic; MTR_n. B : 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; motor_rcnt : integer range 0 to 25000; phase_rclk : std_logic; phase_lcnt : std_logic_vector (1 downto 0); phase_lout : std_logic_vector (3 downto 0); phase_rcnt : std_logic_vector (1 downto 0); phase_rout : std_logic_vector (3 downto 0); begin =====Clock(500 Hz)Generator========= = process(RSTB, CLK_4 M) variable cnt : integer range 0 to 4000; begin if RSTB = '0' then cnt : = 0; clk_500 <= '0'; elsif rising_edge (CLK_4 M) then if cnt >= 3999 then --정 상 동작시 -if cnt >= 2 then --시뮬 레이션시 cnt : = 0; clk_500 <= not clk_500; else cnt : = cnt + 1; end if; end process; ====================== = 4
라인 트레이서의 설계 - 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"; 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"; mtr_speed <="11"; -빠른좌회전 when "1111101" => mtl_speed <="01"; mtr_speed <="11"; -빠른좌회전 when others mtr_speed <="00"; -- 정지 end case; mtr_speed <="01"; - 빠른우회전 when "1001111" => mtl_speed <="11"; => mtl_speed <="00"; end if; 5 end process;
라인 트레이서의 설계 - Design ==== 모터속도값에 따른 좌, 우모터 속도결정 ==== 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; -- 100 Hz when "10" => speed_r <= 9999; -200 Hz when "11" => speed_r <= 6249; -320 Hz when others => speed_r <= 6249; -320 Hz end case; else case mtr_speed is when "00" => speed_r <= 0; 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; -- 100 Hz when "10" => speed_l <= 9999; -- 200 Hz when "11" => speed_l <= 6249; -- 320 Hz when others => speed_l <= 6249; end case; else case mtl_speed is 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; 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; 6
라인 트레이서의 설계 - Design process(RSTB, speed_l, CLK_4 M, motor_lcnt) begin if RSTB = '0' or speed_l = 0 then motor_lcnt <= 0; phase_lclk <= '0'; elsif rising_edge (CLK_4 M) then if (motor_lcnt >= speed_l) then motor_lcnt <= 0; phase_lclk <= not phase_lclk; else motor_lcnt <= motor_lcnt + 1; end if; end process; process(RSTB, speed_r, CLK_4 M, motor_rcnt) begin if RSTB = '0' or speed_r = 0 then motor_rcnt <= 0; phase_rclk <= '0'; elsif rising_edge (CLK_4 M) then if (motor_rcnt >= speed_r) then motor_rcnt <= 0; phase_rclk <= not phase_rclk; else motor_rcnt <= motor_rcnt + 1; end if; end process; --=================== --===== 왼쪽 모터 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; 7 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; MTL_A <= phase_lout(0); MTL_B <= phase_lout(1); MTL_n. A <= phase_lout(2); MTL_n. B <= phase_lout(3); MTR_A <= phase_rout(0); MTR_B <= phase_rout(1); MTR_n. A <= phase_rout(2); MTR_n. B <= phase_rout(3); end Behavioral; 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; end process; -===================== 8
- Slides: 9