EECS 270: Lab 7. Real-World Interfacing with an Ultrasonic Sensor and a Servo

Similar documents
EECS150 Spring 2007 Lab Lecture #5. Shah Bawany. 2/16/2007 EECS150 Lab Lecture #5 1

PWM System. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

I hope you have completed Part 2 of the Experiment and is ready for Part 3.

Lab 6. Binary Counter

Additional Programs for the Electronics Module Part No

Digital Debug With Oscilloscopes Lab Experiment

Hardware Flags. and the RTI system. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

EE 314 Spring 2003 Microprocessor Systems

Model 305 Synchronous Countdown System

CprE 288 Introduction to Embedded Systems (Output Compare and PWM) Instructors: Dr. Phillip Jones

Introduction to project hardware

Lab 5. Binary Counter

Adafruit 16-channel PWM/Servo Shield

READ THIS FIRST: *One physical piece of 8.5x11 paper (you may use both sides). Notes must be handwritten.

Adafruit 16-Channel PWM/Servo HAT & Bonnet for Raspberry Pi

Sequential Logic Circuits

Adafruit 16-Channel PWM/Servo HAT for Raspberry Pi

PIC Functionality. General I/O Dedicated Interrupt Change State Interrupt Input Capture Output Compare PWM ADC RS232

Laser Writer. Final Project Report December 8, 2000 Engineering 155, Micro Processor design. Jerod Meacham Bryce Nichols.

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC 180A DIGITAL SYSTEMS I Winter 2015

Intro to Engineering II for ECE: Lab 3 Controlling Servo Motors Erin Webster and Dr. Jay Weitzen, c 2012 All rights reserved

HOMANN DESIGNS. DigiSpeed. Instruction manual. Version 1.0. Copyright 2004 Homann Designs.

EE283 Electrical Measurement Laboratory Laboratory Exercise #7: Digital Counter

DASL 120 Introduction to Microcontrollers

Module -18 Flip flops

Grundlagen Microcontroller Counter/Timer. Günther Gridling Bettina Weiss

Digital Logic Troubleshooting

Experiment 5: Basic Digital Logic Circuits

MiniProg Users Guide and Example Projects

Blind Spot Monitor Vehicle Blind Spot Monitor

Chemistry Hour Exam 1

Digital Electronics Course Objectives

Adafruit 16-channel PWM/Servo Shield

1.) If a 3 input NOR gate has eight input possibilities, how many of those possibilities result in a HIGH output? (a.) 1 (b.) 2 (c.) 3 (d.) 7 (e.

DM74ALS169B Synchronous Four-Bit Up/Down Counters

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING BENG (HONS) ELECTRICAL & ELECTRONICS ENGINEERING SEMESTER TWO EXAMINATION 2017/2018

ENGG1015: lab 3. Sequential Logic

Adafruit 16-Channel Servo Driver with Arduino

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

Spec. Instructor: Center

PHYSICS 536 Experiment 14: Basic Logic Circuits

ENGR 210 Lab 12: Analog to Digital Conversion

Industrial Automation Training Academy. Arduino, LabVIEW & PLC Training Programs Duration: 6 Months (180 ~ 240 Hours)

Digital Applications of the Operational Amplifier

Configuring CorePWM Using RTL Blocks

PWM LED Color Control

Instructional Demos, In-Class Projects, & Hands-On Homework: Active Learning for Electrical Engineering using the Analog Discovery

ENGR-4300 Fall 2006 Project 3 Project 3 Build a 555-Timer

EE 308 Lab Spring 2009

OBJECTIVE The purpose of this exercise is to design and build a pulse generator.

INF3430 Clock and Synchronization

SDR14TX: Synchronization of multiple devices via PXIe backplane triggering

Java Bread Board Introductory Digital Electronics Exercise 2, Page 1

logic system Outputs The addition of feedback means that the state of the circuit may change with time; it is sequential. logic system Outputs

Project 3 Build a 555-Timer

Lab Exercise 9: Stepper and Servo Motors

In this lecture, we will first examine practical digital signals. Then we will discuss the timing constraints in digital systems.

Name EET 1131 Lab #2 Oscilloscope and Multisim

Lab 1.2 Joystick Interface

Microprocessor & Interfacing Lecture Programmable Interval Timer

6.111 Lecture # 19. Controlling Position. Some General Features of Servos: Servomechanisms are of this form:

ArbStudio Training Guide

AC : A TURING MACHINE FOR THE 21ST CENTURY

Digital Electronics. A. I can list five basic safety rules for electronics. B. I can properly display large and small numbers in proper notation,

Need Analog Output from the Stamp? Dial it in with a Digital Potentiometer Using the DS1267 potentiometer as a versatile digital-to-analog converter

Controlling DC Brush Motor using MD10B or MD30B. Version 1.2. Aug Cytron Technologies Sdn. Bhd.

2014 Paper E2.1: Digital Electronics II

Sequential Logic Circuits

EE 42/100 Lecture 24: Latches and Flip Flops. Rev B 4/21/2010 (2:04 PM) Prof. Ali M. Niknejad

CHAPTER 5 NOVEL CARRIER FUNCTION FOR FUNDAMENTAL FORTIFICATION IN VSI

BME 194: Applied Circuits Lab 04: hysteresis

EE 308 Spring S12 SUBSYSTEMS: PULSE WIDTH MODULATION, A/D CONVERTER, AND SYNCHRONOUS SERIAN INTERFACE

RC Filters and Basic Timer Functionality

νµθωερτψυιοπασδφγηϕκλζξχϖβνµθωερτ ψυιοπασδφγηϕκλζξχϖβνµθωερτψυιοπα σδφγηϕκλζξχϖβνµθωερτψυιοπασδφγηϕκ χϖβνµθωερτψυιοπασδφγηϕκλζξχϖβνµθ

CS/EE Homework 9 Solutions

Bohunt School (Wokingham) Internet of Things (IoT) and Node-RED

Final Report MAL-9000

ENGR 1110: Introduction to Engineering Lab 7 Pulse Width Modulation (PWM)

EE 209 Lab Range Finder

EE 42/100 Lecture 24: Latches and Flip Flops. Rev A 4/14/2010 (8:30 PM) Prof. Ali M. Niknejad

EECS150 - Digital Design Lecture 28 Course Wrap Up. Recap 1

Breadboard Primer. Experience. Objective. No previous electronics experience is required.

Quantizer step: volts Input Voltage [V]

PRESENTATION OF THE PROJECTX-FINAL LEVEL 1.

FPGAs: Why, When, and How to use them (with RFNoC ) Pt. 1 Martin Braun, Nicolas Cuervo FOSDEM 2017, SDR Devroom

ANLAN203. KSZ84xx GPIO Pin Output Functionality. Introduction. Overview of GPIO and TOU

Experiment 9 : Pulse Width Modulation

Connect Four Emulator

Cornerstone Electronics Technology and Robotics Week 21 Electricity & Electronics Section 10.5, Oscilloscope

FPGA-Based Autonomous Obstacle Avoidance Robot.

University of Pittsburgh

CorePWM Datasheet. Product Summary. Table of Contents. Core Deliverables. Intended Use. Key Features. Synthesis and Simulation Support

DE1.3 Electronics 1. Tips on Team Projects

Graphical Control Panel User Manual

The SOL-20 Computer s Cassette interface.

Class #6: Experiment The 555-Timer & Pulse Width Modulation

SRV ENGINEERING COLLEGE SEMBODAI RUKMANI VARATHARAJAN ENGINEERING COLLEGE SEMBODAI

Input/Output Control Using Interrupt Service Routines to Establish a Time base

E85: Digital Design and Computer Architecture

Adder Comparator 7 segment display Decoder for 7 segment display D flip flop Analysis of sequential circuits. Sequence detector

Transcription:

EECS 270: Lab 7 Real-World Interfacing with an Ultrasonic Sensor and a Servo 1. Overview The purpose of this lab is to learn how to design, develop, and implement a sequential digital circuit whose purpose is to interface with actual hardware devices. Your lab is broken into three tasks: In the first task, you will work with an ultrasonic distance sensor, using it to determine how far away an object is from the sensor and displaying that distance using the 7-segment displays. Wikipedia has a decent article on ultrasonic sensors in general 1. There is also a student-written slide show you might find helpful 2 in understanding how the sensors work. In the second task, you will work with a servo a fairly easy-to-use motor which can easily be turned to a specific angle. You will make it so pressing a button will turn the motor 5 degrees in one direction or another. There are some fairly good on-line resources for using a servo 3,4 and we suggest you look them over. For the last task, you will combine the servo and distance sensor, making a device that sweeps the area in front of it, looking for the nearest object. All of your code for this lab is to be done in Verilog. The lab with worth a total of 165 points. In addition, you can earn up to 15 points of extra credit. Preparation Before you begin the lab, we strongly recommend you read about servos and distance sensors. We ve provided a brief tutorial as part of this document, but reading the references mentioned above would be wise. Read the entire lab, including the in-lab, before starting the pre-lab. 1 http://en.wikipedia.org/wiki/ultrasonic_sensor 2 http://www.eecs.umich.edu/courses/eecs270/270lab/270_docs/distance Sensor Presentation.pdf 3 http://www.servocity.com/html/how_do_servos_work_.html 4 http://pcbheaven.com/wikipages/how_rc_servos_works/

Ultrasonic Sensor The ultrasonic distance sensor we will be using is the LV-MaxSonar-EZ1 5. It measures distance to the detected object by sending out an ultrasonic pulse and measuring how long it takes to see the pulse reflected back. It provides range information from 6 inches out to 254 inches with 1 inch resolution. The sensor will indicate that an object from 0 to 6 inches away is 6 inches away. This particular sensor has a number of ways that one could talk to it. We will be using the pulse width interface, though it also supports a serial interface and an analog interface. Every 49ms the device will output a pulse. The length of time the signal is high (the pulse width) indicates how far away the detected object is. The pulse will be high for 147μs for every inch the detected object is from the sensor. So if the pulse duration were 1.47ms, the sensor would be indicating the nearest object is 10 inches away. The datasheet (referenced above or easily found with a web search) provides some additional information (though it can be a challenge to read). Figure 1 provides a graphical view of this. Period: 49ms Pulse width Figure 1: Pulse width output Dealing with asynchronous inputs External inputs are not generally synchronized to our local clock and thus might be changing near the rising edge of the clock. This could violate set-up or hold time constraints and cause the output to be metastable 6, potentially leading to system failure. Figure 2 below shows a recommended synchronizer. It consists of two flip-flops. The data coming out of the second flip-flop will be synchronized to the local clock 7. Asynchronous data D Q D Q Synchronized data Clock Figure 2: Synchronizer 5 http://www.maxbotix.com/documents/mb1010_datasheet.pdf 6 From Wikipedia: In metastable states, the circuit may be unable to settle into a stable '0' or '1' logic level within the time required for proper circuit operation. As a result, the circuit can act in unpredictable ways, and may lead to a system failure 7 See http://www.stanford.edu/class/ee183/handouts/synchronization_pres.pdf for a fairly detailed overview on clock synchronization, including an analysis of mean time between failures.

Servo A servo is a motor that allows for precise control of angular position. Servos are controlled by sending them a pulse of variable width at a fixed frequency. The servo we will be using is the EMAX ES08ma 8. This servo requires that the pulse have a minimum pulse width of 0.6 ms, a maximum pulse width of 2.4ms, and a period of 20ms. If the pulse width you send to the servo is out of range, the servo will not work properly. Period: 20 ms Pulse Width: 0.6 ms 2.4 ms Minimum Pulse Width Pulse Width: 0.6 ms 0 deg Pulse Width: 1.5 ms 90 deg Maximum Pulse Width Pulse Width: 2.4 ms 180 deg Figure 3: Pulse width and motor s position. As seen in Figure 3, the angle the servo turns to is determined by the pulse width that is applied. The servo expects to see a pulse every 20ms (50Hz). The pulse width will determine the position of the motor. For example, a 1.5ms pulse will make the motor turn to the 90 degree position. The servo would hold this position if the same pulse width is supplied every 20ms. 8 https://media.digikey.com/pdf/data%20sheets/seeed%20technology/108090001_web.pdf

2. Pre-Lab [55 points] 1) The servo operates at 50Hz while the DE2 board has an internal clock that runs at 50MHz. What is the period of the 50 MHz system clock? The 50 Hz servo? [3 points] 2) Say you wanted to design a circuit that had a 50MHz clock as an input and it was to generate a glitch-free output that had a frequency of 50Hz and was high for 1.5ms and low the rest of the time. Figure 4 is a start at implementing such a circuit. [12 points] a) In your own words, explain what this design is doing. Describe in terms of X and Y. [3] b) What is the value of X you would need? [2] c) What is the value of Y you would need? [2] d) How many bits would the counter need? [2] e) What role is the D flip-flop playing? [3] Reset N-bit up counter Clock Q < X? ==Y? D D flip-flop Q Clock Periodic Pulse Input Clock Figure 4: Pulse generation circuit 3) Write a Verilog module that implements the circuit in Figure 4 with the values for N, Y, and X you computed in the above question. The only input should be the input clock (clk) and the only output should be the periodic pulse (pulse). Provide a timing simulation waveform showing the pulse you generate. (You will need to create a 50MHz clock for the stimulus. An example test bench showing you how to do these is posted with the lab) [20 points] 4) Consider the following Verilog code 9 where A is the input and Ar[1] is the output: [7 points] reg [1:0] Ar; always @(posedge clk) Ar <= {Ar[0], A}; a) What does that code implement? Draw a figure using registers. Clearly label A, Ar[0], and Ar[1] in your figure. [5] b) Why might this code be useful in this lab? (In other words, how does it relate to anything you ll need to do in this lab?) You may need to read the in-lab section to answer this question. [2] 5) If the ultrasonic distance sensor detected an object that was 21 inches away: [4 points] a) For how long would the pulse be high? [2] b) For how many 50MHz clock ticks would the pulse be high? [2] 9 The {} operator is concatenate. So {1 b1, 2 b00, 1 b1, 3 b010} is the same as 7 b1001010.

6) Draw a circuit which has two inputs: a clock (clk) and a one bit input (A). Your circuit is to generate an output (X) of 1 if and only if A was a 1 on the last clock edge and is a 0 on the current clock edge. Hint: this can be done with 1 two-input gate, a D flip-flop and an inverter. [5 points] 7) Complete the binary to hexadecimal 7-segment display Verilog code below. [4 points] module SevenSegmentDisplayDecoder(in, ssout); input [3:0] in; output reg [6:0] ssout; always @* case (in) 4'h0: ssout = 7'b1000000; 4'h1: ssout = 4'h2: ssout = ; 4'h3: ssout = ; 4'h4: ssout = ; 4'h5: ssout = 7'b0010010; 4'h6: ssout = ; 4'h7: ssout = 7'b1111000; 4'h8: ssout = ; 4'h9: ssout = 7'b0011000; 4'hA: ssout = ; 4'hB: ssout = 7'b0000011; 4'hC: ssout = 7'b1000110; 4'hD: ssout = 7'b0100001; 4'hE: ssout = ; 4'hF: ssout = ; endcase endmodule

3. In-lab As mentioned in the overview, this lab has three different tasks: implementing the interface to the ultrasonic sensor, implementing the interface to the servo motor, and implementing a closest object detector. The lab is broken into two parts Part 1 and Part 2. As far as ground rules go you may use any part of Verilog you wish other than multiplication (*), division (/) and mod (%). You are to do your entire design in Verilog (no schematic capture). Part 1 Sensor and Servo For this part you will turn in the first two tasks: implementing the interface to the ultrasonic sensor and implementing the interface to the servo motor. Connecting the devices to the board and debugging The ultrasonic distance sensor and servo are conveniently mounted on a custom PCB board that plugs into the 40 pin GPIO header on the DE2. There are keys (slots) on the mating connectors to insure they are properly aligned. You should not have to remove or install these. If you do, you should ask your instructor for assistance to avoid damage to the connector pins. You should something like this on your kit if it is properly installed. Figure 5: Picture of the board connected to the servo and distance sensor

FPGA Connections The servo pulse and sensor signal are attached to the following FPGA pins 50MHz clock FPGA PIN_Y2 Servo Pulse FPGA PIN_Y17 Sensor Signal FPGA PIN_AC15 You might find it helpful to observer the servo pulse you are generating or confirm and observer the ultrasonic sensor pulse. There are test points on the interface board to provide easy connection to these signal with an oscilloscope. Ask the instructor for help setting one up if you want to give it a try

Ultrasonic distance sensor [35 points] For this task, you are to display the range of the detected object on the DE2 board using two sevensegment displays. You are to display the distance in hexadecimal. Hints/design issues: Keep in mind that the signal coming from the ultrasonic sensor is not synchronized to your FPGA s clock. You ll need to fix that. The 50Mhz system clock found is found on pin PIN_Y2. You will want to use a counter and a register. The counter to count how long the pulse is high, while the register grabs that value once the pulse has gone low. The register s value is what you ll display on the 7-segment display. Consider avoiding using magic constants and instead use defines throughout your code. This can prevent a number of rather silly but hard-to-find errors. You will be well served to sketch out a design before you start coding. The sensor logic is very difficult to debug on the kit. Use the sensor test bench posted with the lab to debug you design. Be sure to use timing simulation for accurate simulation. You will probably want to add other outputs from your design to the test bench to monitor and debug your design. Demo 1 Ultrasonic Distance Sensor Demonstrate the function of your ultrasonic distance sensor to a 270 instructor. Servo motor [35 points] Design a controller for the servo. This controller is to use three of the buttons to implement reset (Key 3), increment (Key 2), and decrement (Key 1). When reset is pressed, regardless of other buttons, the motor will return to initial position--0 degrees. Otherwise, each time the increment button is pressed the motor is to turn 5 degrees clockwise. And each time the decrement button is pressed, the motor is to turn 5 degrees counterclockwise. Note that the motor can only operate within 180 degrees, so any button press that would cause the angle to be above 180 degrees or below 0 degrees should be ignored. Hints/design issues: The buttons are not synchronized to your FPGA s clock. You ll need to fix that. Keep in mind that a single button press will cause the button s state to change for more than just one clock tick. You are going to need some way to detect that the button has gone from a not-pressed state to a pressed state. You did something like this in the pre-lab. There is a really nice way to combine your solution to the above two issues into a single, very short, module. Consider avoiding using magic constants and instead use defines throughout your code. This can prevent a number of rather silly but hard-to-find errors.

Use one of the pushbutton or slide switches to provide a system reset to initialize your system like the starting PWM pulse width. You will be well served to sketch out a design before you start coding. Like the sensor logic, this logic can be very difficult to debug on the kit. A test bench is provided that provides a 50MHz clock, reset, KEY0 and KEY1 press. Add more outputs as necessary to debug your design. Be sure to use the timing mode simulation. Demo 2 Servo Motor Demonstrate the function of your servo motor to a 270 instructor. Part 2 Closest Object Scanner [30 points] For this task, you will combine the servo and ultrasonic sensor to make a device which finds the distance to the nearest object. The sensor will be mounted on the servo and you will use this combined device to scan the area in front of the combined device. When the enable (DIP switch 17) is high, the servo is to automatically scan from 0 to 180 degrees and back (180 to 0 degrees) continuously and is to report the closest object it has seen thus far on two seven segment displays. When reset is high (no matter the value of enable) the detector shall return to 0 degrees. Once reset is low and enable is high, a new search is to be started. Hints/design issues: The servo s operating speed at 4.8V is 0.19sec/60 with no load. The speed in lab might be a bit lower due to the mounted sensor. Please do not exceed 0.03sec/5 for this design. Spend some time thinking about how you will need to change and combine your designs from part 1 before starting on this part. Demo 3 Object Scanner Demonstrate the function of your object scanner to a 270 instructor. Extra credit [up to 15 points] You may do any of the following, but cannot earn more than 15 extra credit points. You will not get any extra credit points if you haven t finished parts 1 and 2. Further, no extra credit can be earned after part 2 is due. The points earned here are quite small compared to the amount of work involved. Sonar display: For this task, you will break up the 180 degree sweep of the combined device from part 2 into 8 equally sized arcs. Rather than displaying the closest object s distance, you are to use the eight seven-segment displays to indicate how close an Figure 6: The left-most segment indicates the object is far, the middle that it is at a medium distance and the rightmost that the object is close.

object is in each of those 8 arcs. You will use the display to indicate if objects are close (<8 inches), far (>20 inches) or at a medium distance as shown in Figure 6, with each 7-segment display representing a different section of the 180 degree sweep. Only the object detected as closest in the most recent sweep of that section should be displayed. [10 points] Follow-me: Your combined device should do a single sweep of the 180 degrees, find the closest object and then return to pointing at that object. After that initial set up, you design should follow that object if it moves slowly enough. You ll want to keep twitching the device to the left and right to track an edge of that object. [10 points] Demo 4 Extra Credit Demonstrate your extra credit to 270 instructor. The instructor will evaluate your demo. 4. Post-lab [10 points] Turn in all Verilog code written for this lab.