질문게시판 > vhdl 소스코드 라인트레이서 질문

TODAY451 TOTAL2,693,085
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 질문게시판 | vhdl 소스코드 라인트레이서 질문

페이지 정보

작성자 woni 작성일2018-06-01 15:50 조회10,455회 댓글1건

본문

	

제가 리모콘 버튼을 누르면 라인트레이서가 전진하고

버튼을 떄면 그 전진한 거리를 기억하여 제자리로 후진하게 만들고

다시 그 전후진한 거리를 기억하여 전후진을 반복하는 소스코드를 짜고있습니다.

아래 코드중 틀린 부분을 설명과 어떻게 바꿔야하는지 질문입니다.

 

-- IRobLab 3000

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity rf_robot2 is
Port ( rstb : in std_logic;
           clk_4m : in std_logic;
     restore : in std_logic;
           rf_data : in std_logic_vector(2 downto 0);
           mtl : out std_logic_vector(3 downto 0);
           mtr : out std_logic_vector(3 downto 0));
end rf_robot2;
architecture Behavioral of rf_robot2 is
signal forward : 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 250000;
signal speed_r : integer range 0 to 250000;
signal motor_lcnt : integer range 0 to 250000;
signal phase_lclk : std_logic;
signal phase_clk : std_logic;
signal restore1 : std_logic;
signal motor_rcnt : integer range 0 to 250000;
signal mcnt : integer range 0 to 250000;
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);
signal cnt : integer range 0 to 250000;

begin
 process(rf_data)
 begin
 forward <= rf_data(2);
  case rf_data is
    when "100" =>   -- forward
     mtl_speed <= "11";
     mtr_speed <= "11";
 when "000" =>   -- reverse
     mtl_speed <= "11";
     mtr_speed <= "11";
    when "110" =>   -- turn right
     mtl_speed <= "11";
     mtr_speed <= "00";
    when "101" =>   -- turn left
     mtl_speed <= "00";
     mtr_speed <= "11";
    when "010" =>   -- reverse turn right
     mtl_speed <= "00";
     mtr_speed <= "11";
    when "001" =>   -- turn left
     mtl_speed <= "11";
     mtr_speed <= "00";
    when others =>
     mtl_speed <= "00";
     mtr_speed <= "00";
   end case;
 end process;
 process(mtl_speed,phase_clk,cnt,restore1)
 begin
  if(cnt=0 and restore1 ='1') then
 speed_l <=0;
  elsif rising_edge(phase_clk) then
   case mtl_speed is
   when "00" =>
    speed_l <= 0;
   when "01" =>
    speed_l <= 124999;
   when "10" =>
    speed_l <= 62500;
   when "11" =>
    speed_l <= 50000;
   when others =>
    speed_l <= 50000;
  end case;
  end if;
  end process;
 process(mtr_speed,phase_clk,cnt,restore1)
 begin
  if(cnt=0 and restore1 ='1') then
 speed_r <=0;
  elsif rising_edge(phase_clk) then
   case mtr_speed is
   when "00" =>
    speed_r <= 0;
   when "01" =>
    speed_r <= 124999;
   when "10" =>
    speed_r <= 62500;
   when "11" =>
    speed_r <= 50000;
   when others =>
    speed_r <= 50000;
  end case;
  end if;
  end process;

process(rstb,clk_4m)
 begin
   if rstb = '0' then
   phase_clk <= '0';
   mcnt <=0;
  elsif rising_edge(clk_4m) then
   if mcnt >= 50000 then
    phase_clk <= not phase_clk;
  mcnt <=0;
   else
     mcnt <=mcnt+1;
   end if;
  end if;
 end process;

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)
 begin
   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;
 end process;

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;

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;
       if(restore1 = '0') then
   cnt <= cnt +1;
 elsif (cnt/=0) then
   cnt <=cnt-1;
 end if;
  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 <= "1000";
    when "01" => phase_rout <= "0100";
    when "10" => phase_rout <= "0010";
    when "11" => phase_rout <= "0001";
    when others => phase_rout <= "0000";
   end case;
  end if;
 end process;

process(restore, phase_clk)
 begin
  if rising_edge(phase_clk) then
   restore1 <= restore;
  end if;
 end process;
 
 mtl(0) <= phase_lout(0) when restore1 ='0' else phase_lout(3);
 mtl(1) <= phase_lout(1) when restore1 ='0' else phase_lout(2);
 mtl(2) <= phase_lout(2) when restore1 ='0' else phase_lout(1);
 mtl(3) <= phase_lout(3) when restore1 ='0' else phase_lout(0);
 mtr(0) <= phase_rout(3) when restore1 ='0' else phase_rout(0);
 mtr(1) <= phase_rout(2) when restore1 ='0' else phase_rout(1);
 mtr(2) <= phase_rout(1) when restore1 ='0' else phase_rout(2);
 mtr(3) <= phase_rout(0) when restore1 ='0' else phase_rout(3);
end Behavioral;

  • BASIC4MCU 작성글 SNS에 공유하기
  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기

댓글 1

조회수 10,455

master님의 댓글

master 작성일

VHDL은 제가 사용해보지 않아서 모릅니다.
http://cafe.naver.com/lazydigital
이 카페 임베디드홀릭님이 친절하시니 여기서 질문글로 작성해보세요

질문게시판HOME > 질문게시판 목록

MCU, AVR, 아두이노 등 전자공학에 관련된 질문을 무료회원가입 후 작성해주시면 전문가가 답변해드립니다.
ATMEGA128PWMLED초음파
아두이노AVR블루투스LCD
UART모터적외선ATMEGA
전체 스위치 센서
질문게시판 목록
제목 작성자 작성일 조회
공지 MCU, AVR, 아두이노 등 전자공학에 관련된 질문은 질문게시판에서만 작성 가능합니다. 스태프 19-01-15 19439
공지 사이트 이용 안내댓글[28] master 17-10-29 34139
질문 atmega128 uart 질문입니다.댓글[1] 새글 bme12 01:03 9
질문 라즈베리파이에 풀 프레임 이미지센서 활용에 대한 질문이 있습니다. 이미지새글첨부파일 KYLO 23-06-04 13
질문 아두이노 시리얼 번호를 이용해 led 제어 새글 wnion 23-06-04 15
질문 ATMEGA128 혹시 여기서 왜 인터럽트 기능이 안되는지 알 수 있나요 새글 IEEE 23-06-04 26
질문 stm32f767을 이용해서 자이로가속도 센서의 값 받아오기 새글 rlchwjswk 23-06-03 15
질문 아두이노 모터제어 관련해서 질문드립니다!댓글[1] 이미지새글첨부파일 아두이노어렵잖아 23-06-03 29
질문 atmega128 디지털조도센서 코드오류댓글[1] 이미지 까미 23-06-02 32
질문 atmega128 디지털 조도 센서댓글[1] 까미 23-06-02 32
질문 적외선리모콘으로 부저를제어 하는방법 질문입니다.댓글[4] Tell 23-06-02 21
질문 lora 무선 모듈에 관한 질문입니다.댓글[1] 로이스10 23-06-01 19
질문 적외선 송수신기 DC모터2개 제어 질문입니다.댓글[5] Tell 23-06-01 33
질문 스텝모터 제어 코드 질문댓글[5] pmh11 23-05-31 36
질문 초음파 센서를 이용한 인원 카운팅댓글[1] 초음파야 23-05-31 29
질문 모터 Hall 스위치 연결 문의댓글[1] 오후 23-05-31 22
질문 아두이노 lcd 문자 스크롤디스플레이 wnion 23-05-31 25
답변 답변글 답변 : 아두이노 lcd 문자 스크롤디스플레이댓글[1] master 23-05-31 29
질문 아두이노 타이머 인터럽트 미ㅏㄴㅇ 23-05-30 40
답변 답변글 답변 : 아두이노 타이머 인터럽트댓글[6] master 23-05-30 46
질문 THC-Soil Sensor with TTL 모듈 아두이노 센서값 받아오기댓글[1] ppiickle 23-05-30 31
질문 stm32 psd센서구동 질문댓글[2] 수포자 23-05-29 28
질문 앱인벤터 아두이노 보드 LCD 글씨 나타내기 질문댓글[7] 이미지 당찬병아리 23-05-29 45
질문 atmega128 led와 fan댓글[3] 이라 23-05-28 47
질문 stm32f767 스텝모터 속도 질문있습니다 123132 23-05-27 35
답변 답변글 답변 : stm32f767 스텝모터 속도 질문있습니다 master 23-05-28 31
질문 아트메가 128 코딩 오류 질문입니다.댓글[1] 태태킴 23-05-27 36
질문 스텝모터 제어하는 소스파일인데 질문있습니다. Bs드리프터 23-05-27 39
답변 답변글 답변 : 스텝모터 제어하는 소스파일인데 질문있습니다. master 23-05-27 37
질문 모터 컨트롤러와 웜기어 모터 연결 문의 드립니다댓글[1] 오후에 23-05-27 30
게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기