Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Imagine that you are part of a team designing a robot that can navigate a maze.

ID: 3842200 • Letter: I

Question

Imagine that you are part of a team designing a robot that can navigate a maze. As part of this design,

you have been tasked with determining how to interface to an I2C ultrasonic range sensor. Your team

leader informs you that you will be using the MB1202 I2CXL-MaxSonar-EZ0.

Your job is to a write a simple mbed program that reads and prints the range values from the sensor

once every second.

What to submit:

You will submit a mini-report containing:

1. A half page write-up that summarizes the most important things to know about interfacing to

this sensor. (You should include things like the device address, how to configure it, how to read

data from it, what format the data is in, etc.)

2. The source code of your mbed program that reads and prints the value of the range sensor once

every second. Your code should be heavily commented to discuss exactly what each line does

and why.

Explanation / Answer

entity moore_4s is

   port(
       clk       : in   std_logic;
       B,R   : in   std_logic;
       reset   : in   std_logic;
       TL,TR   : out   std_logic
   );
  
end entity;

architecture rtl of moore_4s is

   -- Build an enumerated type for the state machine
   type state_type is (Home,Go_stright,Go_right,G0_left);
  
   -- Register to hold the current state
   signal state : state_type;

begin
   -- Logic to advance to the next state
   process (clk, reset)
   begin
       if reset = '1' then
           state <=Home ;
       elsif (rising_edge(clk)) then
           case state is
               when Home=>
                   if (B='0' and R='1') then
                       state <= Go_stright;
                   else
                       state <= Home;
                   end if;
               when Go_stright=>
                   if B = '1' then
                       state <= G0_left;
                   elsif(R='0')
                       state <= Go_right;
                   else
                   state <=Go_stright;
                   end if;
               when Go_right=>
                   if B= '1' then
                       state <= G0_left;
                   elsif(R='0')
                       state <= Go_right;
                   else
                   state <=Go_stright;
                   end if;
               when G0_left=>
                   if B= '1' then
                       state <= G0_left;
                   elsif(R='0')
                       state <= Go_right;
                   else
                   state <=Go_stright;
                   end if;
           end case;
       end if;
   end process;
  
   -- Output depends solely on the current state
   process (state)
   begin
  
       case state is
           when Home =>
               TL <= '0'
               TR <= '0';
           when Go_stright =>
               TL <= '0'
               TR <= '0';
           when Go_right =>
               TL <= '1'
               TR <= '0';
           when G0_left =>
               TL <= '0'
               TR <= '1';
       end case;
   end process;
  
end rtl;