element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
FPGA
  • Technologies
  • More
FPGA
Blog Build a project with the Arty S7 - Line Follower Robot (Part 3) - Interfacing Sensors and Logic Implementation
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join FPGA to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: rahulkhanna
  • Date Created: 31 Jul 2022 8:46 AM Date Created
  • Views 2637 views
  • Likes 7 likes
  • Comments 10 comments
  • arty-s7
  • 7 Ways to Leave Your Spartan-6
  • spartan-7
  • Spartan_Migration
Related
Recommended

Build a project with the Arty S7 - Line Follower Robot (Part 3) - Interfacing Sensors and Logic Implementation

rahulkhanna
rahulkhanna
31 Jul 2022

From my previous post, We had addressed the hardware issue, installed Vivado 2019.2, and executed the demo program. We will interface with the IR sensors and will be discussing the Logical Implementation in this blog. 

Reasons to switch from Spartan-6 to Spartan-7 FPGAs #1
Build a project with the Arty S7 - Line Follower Robot (Part 1) - Introduction
Build a project with the Arty S7 - Line Follower Robot (Part 2) - Setting up Vivado 2019.2 and Demo program 
Build a project with the Arty S7 - Line Follower Robot (Part 3) - Interfacing Sensors and Logic Implementation
Build a project with the Arty S7 - Line Follower Robot (Part 4) - Hardware Assembly 
Build a project with the Arty S7 - Line Follower Robot (Part 5) - Project Demo
Build a project with the Arty S7 - Line Follower Robot (Part 6) - Adding sensors to the LFR
Build a project with the Arty S7 - Line Follower Robot (Part 7) - Summary

Logic Implementation

We will be using the five IR sensors to identify the black line. Based on the sensor data, the speed of the left and right motors are changed to catch and follow the line. 

These conditions are applied to follow the line. 

  1. When S3 is ON, both motors will move forward.
  2. When S4 or S5 is ON, the left motors will move forward.
  3. When S1 or S2 is ON, the right motors will move forward.
  4. When S1, S2, and S3 are ON, the left motors will move reverse and the right motor will move forward.
  5. When S3, S4, and S5 are ON, the left motors will move forward and the right motor will move reverse.

image

if mid_sensor detects black 
    // Move Forward 
    set left motor ON
    set right motor ON
if right_sensor detects black 
    // Move Right 
    set left motor ON
    set right motor OFF
else if left_sensor detects black 
    // Move Left
    set left motor OFF
    set right motor ON
endif

Create a Vivado Project file

We will be creating a sensors_test project to test the IR sensors and Motor Driver Shield. 

image

Select RTL Project and make sure you select Do not specify sources at this time. 

image

Select Arty S7-50 Board under the Boards tab. 

image

Check the Project Summary and then Click the Finish button.

image

Click on Add Sources in the Project Manager and select Add or create constraints. 

image

Select the constraints file for the Arty S7-50 board.

image

From the pinout, we will be using Digital I/O from IO0 to IO9 for this line follower application

image pinoutimage

The IR Sensors are connected to the pins IO0, IO1, IO2, IO4, and IO7 and the motor driver pins are connected to IO3, IO5, IO6, and IO11. We will be updating the constraints as shown below. 


## LEDs

set_property -dict { PACKAGE_PIN E18 IOSTANDARD LVCMOS33 } [get_ports { led[0] }]; #IO_L16N_T2_A27_15 Sch=led[2]

set_property -dict { PACKAGE_PIN F13 IOSTANDARD LVCMOS33 } [get_ports { led[1] }]; #IO_L17P_T2_A26_15 Sch=led[3]

set_property -dict { PACKAGE_PIN E13 IOSTANDARD LVCMOS33 } [get_ports { led[2] }]; #IO_L17N_T2_A25_15 Sch=led[4]

set_property -dict { PACKAGE_PIN F18 IOSTANDARD LVCMOS33 } [get_ports { led[3] }]; #IO_L16P_T2_A28_15 Sch=led1_g

set_property -dict { PACKAGE_PIN G17 IOSTANDARD LVCMOS33 } [get_ports { led[4] }]; #IO_L14N_T2_SRCC_15 Sch=led0_g



## IR Sensors

set_property -dict { PACKAGE_PIN L13 IOSTANDARD LVCMOS33 } [get_ports { sen[0] }]; #IO_0_14 Sch=ck_io[0]

set_property -dict { PACKAGE_PIN N13 IOSTANDARD LVCMOS33 } [get_ports { sen[1] }]; #IO_L6N_T0_D08_VREF_14 Sch=ck_io[1]

set_property -dict { PACKAGE_PIN L16 IOSTANDARD LVCMOS33 } [get_ports { sen[2] }]; #IO_L3N_T0_DQS_EMCCLK_14 Sch=ck_io[2]

set_property -dict { PACKAGE_PIN T14 IOSTANDARD LVCMOS33 } [get_ports { sen[3] }]; #IO_L13N_T2_MRCC_14 Sch=ck_io[4]

set_property -dict { PACKAGE_PIN V17 IOSTANDARD LVCMOS33 } [get_ports { sen[4] }]; #IO_L16N_T2_A15_D31_14 Sch=ck_io[7]




## Motor Driver Pins

#set_property -dict { PACKAGE_PIN R14 IOSTANDARD LVCMOS33 } [get_ports { left_m[0] }]; #IO_L13P_T2_MRCC_14    Sch=ck_io[3]

#set_property -dict { PACKAGE_PIN R16 IOSTANDARD LVCMOS33 } [get_ports { left_m[1]}]; #IO_L14P_T2_SRCC_14 Sch=ck_io[5]

#set_property -dict { PACKAGE_PIN R17 IOSTANDARD LVCMOS33 } [get_ports { right_m[0] }]; #IO_L14N_T2_SRCC_14 Sch=ck_io[6]

#set_property -dict { PACKAGE_PIN H17 IOSTANDARD LVCMOS33 } [get_ports { right_m[1]}]; #IO_L22N_T3_A16_15 Sch=ck_io11_mos



image

Interfacing IR Sensors

IR transmits infrared lights. When infrared rays fall on the white surface, it’s reflected back and caught by photodiodes which generate some voltage changes. When IR light falls on a black surface, light is absorbed by the black surface and no rays are reflected back, thus photodiode does not receive any light or rays. We will be using the five IR sensors to identify the black line. 

Let's add the design sources to the project. 

image

Select SystemVerilog and name the file as top.sv

image

Add the following code to the top.sv file. 

module top (
input wire logic [4:0] sen,
output logic [4:0] led
);

always_comb begin
led[0] = sen[0] ? 1'b1 : 1'b0;
led[1] = sen[1] ? 1'b1 : 1'b0;
led[2] = sen[2] ? 1'b1 : 1'b0;
led[3] = sen[3] ? 1'b1 : 1'b0;
led[4] = sen[4] ? 1'b1 : 1'b0;
end
endmodule

image

Now, let's test the above code - IR Sensors. 

image              image

Interfacing Motor Driver

The H-Bridge Motor Drivers L298N is used to drive DC motors as they require much more current than the IO ports.

image

We will create design sources named "motor_control.sv" and "pwm.sv" and add the following code to the pwm.sv file. 

module pwm (
input wire logic clk,
input wire logic [7:0] duty,
output logic pwm_out
);

logic [7:0] cnt = 8'b0;
always_ff @(posedge clk) begin
cnt <= cnt + 1;
end

always_comb pwm_out = (cnt < duty);
endmodule

Add the following code to the motor_control.sv file. 

module motor_control(
input wire logic clk,
output logic [1:0] left_m, [1:0] right_m
);

logic [7:0] speed = 8'd0;

pwm in1 (.clk, .duty(speed), .pwm_out(left_m[0]));
pwm in2 (.clk, .duty(speed+255), .pwm_out(left_m[1]));
pwm in3 (.clk, .duty(speed), .pwm_out(right_m[0]));
pwm in4 (.clk, .duty(speed+250), .pwm_out(right_m[1]));

endmodule

Now, let's test the above code - Motor Control (PWM) 

image

Yay! Now the Hardware is ready to be programmed. Next, we will be assembling the Hardware components in the next blog.

  • Sign in to reply
Parents
  • Jan Cumps
    Jan Cumps over 3 years ago

    Majority of the images don't show.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rahulkhanna
    rahulkhanna over 3 years ago in reply to Jan Cumps

    I'm able to see the images on this blog. Let me check once again. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • rahulkhanna
    rahulkhanna over 3 years ago in reply to Jan Cumps

    I'm able to see the images on this blog. Let me check once again. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube