Home
Complete ECE 375 Manual - Oregon State University
Contents
1. TekBot 2 Open the CodeVision Integrated Development Environment IDE and select New Project You have two options here either run the Wizard or don t The wizard for CodeVision will quickly generate values to be stored in specific places in the AVR to setup peripheral devices like the A D converters and the serial port We don t need to do this so don t use the wizard You are asked to name your project Put the project file 1n its own directory with the source code you got from the web CodeVision creates a lot of files so you don t want to put it just anywhere After you have named the file a short selection screen pops up as shown in Figure 1 Click Add and add the code you downloaded Click the top tab called Compiler to bring up the compiler options s Files c Compiler After Make ZNECE3 75Lab1 junk pri x Cancel Help Figure 1 Project Setup Screen 2009 Oregon State University ECE375 Manual Page 19 Section Two C Assembler Machine Code TekBot 3 Figure 2 shows a properly configured compiler screen All values are specific for the AVR board you have This configuration will not necessarily work on other chips or boards The part is the ATMegal28 running at 16Mhz You are using a small memory model with 32768 bytes of external RAM The RAM requires a wait state Everything else 1s left in its default Configure Project dance_ 102 prj
2. Files C Compiler After Make Code Generation Globally Hdefine Paths SRAM Chip AT megal 2d Y Data Stack size H O24 bytes Clock 1 6 000000 4 MHz Internal SRAM size 4096 bytes Memory Mode e External SRAM size 32768 bytes M External SRAM Wat State Ce Small SC Code Generatio Ee fo Bit Yarables size 16 Size Su d Promote char toit W char is unsigned ate Jh 8 bit enume Enhanced Core Instructions Program Type v Automatic Register Allocation Use an External Startup Initialization File v Enable Warnings Stack End Markers File Output Farmat s CHF ROM HEX EEP Use the Terminal 40 in AA Studio Application s printf Features int width x Cancel 7 Help Figure 2 Compiler Settings 2009 Oregon State University ECE375 Manual Page 20 Section Two C Assembler Machine Code TekBot 4 Figure 3 shows the After Make settings You want to program the chip after make and you don t want to verify erasure DO NOT MESS WITH THE FUSE BITS Your AVR board can become unusable 1f you write to the wrong fuse bit without knowing what you are doing Configure Project lah1 nr x Files C Compiler Alter Make Jh Program the Chip Execute User s Program Merge data from a ROM File for FLASH Programming Chip Programming Options FLASH Lack Bit f Ha Protection Fuse Bit s CESELO 0
3. Programming disabled Programming and Verification disabled Boot Lack Bit Ge BOl 1 B 2 1 B l 0B 2 1 BO1 0 BO2 0 C BO1 1 B02 0 Boot Lack Bit 1 B11 1 B12 1 C B11 0B12 1 C B11 0B12 0 C B11 1 B12 0 Figure 3 After Make Settings 5 Click OK and CodeVision should open the source file Examine this file so you understand what 1s happening It is written in C you should have learned C in CS151 CS261 or elsewhere If you are having difficulties check the web and teach yourself or ask for assistance from your TA 2009 Oregon State University ECE375 Manual Page 21 Section Two C Assembler Machine Code TekBot Pseudo Code for Lab 2 Dance C Code e Initialize Port s e Loop Forever Forward for 500mS Reverse for 500mS Right for 1000mS Left for 2000mS Right for 1000mS Compiling 1 Now that you understand the code and have connected your TekBot as expected you will want to compile and download your code to your TekBot This is where the beauty of an IDE 1s In an IDE all you need to do 1s click a single button rather than use a separate program to compile your code Select Project Compile or press F9 The code will compile and give you a summary If there are any errors or warnings ask your TA for help 2 After you have compiled your code it is time to make the files to be downloaded Select Project Make or press shift F9 Again a w
4. real excitement The idea of having two robots play freeze tag with each other sounds like a good idea You think the best way to do this is to have each robot emit a certain code when the user with the remote presses a certain button This code would then be detected by any robot that could see it except the one firing and cause the robot to freeze for five seconds When the robot unfreezes 1t should immediately resume what it was doing After three freezes the robot should stop working until it 1s reset The code your robot should transmit to freeze other robots 1s shown in Figure 2 The robot not the remote transmits this code Make one of the buttons on the remote transmit a code to the robot that has the robot transmit the freeze code The freeze command code from your remote should be 0b11111000 Remote Control e Remote Transmits Freeze Command gt 0b11111000 Robot Transmits Freeze Signal gt 0b01010101 Figure 2 Freeze Tag Operation To show your design you will need to work with another team to have the two robots compete Show your TA and have each team turn in a copy of their code with a written description TA Signature 2009 Oregon State University ECE375 Manual Page 56 Section Seven Remotely Operated Vehicle v2 0 2009 Oregon State University ECE375 Manual Page 57 Appendix A Parts Lists APPENDIX PARTS LISTS 2009 Oregon State University ECE375 Manu
5. CO n LD 3RELAB 18 PREL amp 2370000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 A _7 PROCEDURE ue dede een en um 5 lt 1 Looking at C Code and the A VI S U 1O 4 o0 o 0o Go S966 66999 9999998886966666999996666666606666 18 Compiling C Code and Down OaC TI ooooooooooo o9 9999666 6666969 9 9 9 999 999998866666660606666996 22 AONE IVC OM sense tete menu eme im di IN REL M M 22 STUDY QUESTIONS REPORT DEE e I ECSU i dd iral E DEF rA PER FORI A PIX a ODE FR DNI I M rff VOR EE pA ZEN HEINE 23 CHALLENGE 23 CH LL ul gp Mi e 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 u SECTION THREE DATA MANIPULATION AND THE LCD DISPLAY 25 2009 Oregon State University ECE375 Manual Page 3 PROCEDURE Got DINE PHAR VANNES Go C co NOK ch NV 26 PO COR EEN 26 ns ce HEFTE 26 LCD Driver User Eu CN 27 TE sua L EE EM T S AT AAS PETE AAT E 27 a sas R EPP E CUR ane RA R did iii tee 27 a NI NOU I ONES UNE 27 EO Ee a a CN 6 0 ng T TP nh TY 28 Beie EEN 28 ie an D K an ee 28 a eee EE 28 Beni ME 28 Bm toc BEE EEN 29 par NP Dal OO s SK A K A A Unis 29 TERNE I ONE NEE 30 STUDY OUESTIONS REPORT o 000000000000000000000000000000000000000000000000000 0000000000000000000000000
6. R ISP ISP Header uem E SIC Keeps St BS C l gt gt gt TC gt CT OO NI PBS Figure 54 Block diagram of the analog board ECE375 Manual Page 62 2009 Oregon State University APPENDIX C SUPPLIERS 2006 Oregon State University ECE375 Manual Page 63 Appendix C Suppliers DigiKey 701 Brooks Ave South Thief River Falls MN 56701 0677 800 344 4539 http www digikey com Mouser Electronics 1000 N Main Street Mansfield TX 76063 800 346 6873 http www mouser com TekBots 220 Owen Hall Oregon State University Corvallis OR 97331 tekbots_support eecs oregonstate edu http eecs oregonstate edu tekbots Solarbotics 179 Harvest Glen Way N E Calgary Alberta Canada T3K 4J4 866 B ROBOTS http www solarbotics com McMaster Carr P O Box 7690 Chicago IL 60680 7684 562 692 5911 http www mcmaster com Jameco Electronics 1355 Shoreway Rd Belmont CA 94002 800 831 4242 http www jameco com Page 64 ECE375 Manual 2006 Oregon State University
7. Finally the data from the MDR can be moved to the IR or ACC depending on the instruction This works vice versa for moving data to data memory Data from the ACC 1s moved to the MDR the data address is put into the MAR and finally the data within the MDR can be stored into ESC Data Memory at the memory address located in the MAR Memory Direct immediate and indirect addressing modes are allowed in ESC AVR ESC Data Addresses Memory Address 2009 Oregon State University ECE375 Manual Page 48 Section Six Extremely Simple Computer ESC 0100 0101 0102 0103 0104 0110 00 012F 1F 0130 ESC 00 Program Memory 014F 1F Figure 2 ESC gt AVR Memory Map Data Memory Since data address space is 5 bits there are 2 5 32 bytes RAM in ESC data address space is 00 1F 5 bits in the ESC instruction specify a direct memory address You will store the ESC data memory in the ATmegal28 data memory locations 0110 012F Be aware of the conversion between 5 bit ESC memory addresses to 16 bit AVR memory addresses For example ESC memory location 07 corresponds to the ATmegal28 data memory location 0117 Program Memory ESC instructions are stored in ESC program memory You should use the ATmegal28 data memory locations 0130 014F as the ESC program memory Op code Mnemonic Range Instruction Description 76543210 of 2009 Oregon State University ECE375 Manual Page 49 Section Six Extr
8. Program Description You are to write a program using ESC mnemonics and convert it to binary form fill the ESC program memory area with this program This program should scroll the contents of 5 locations in ESC data memory in the following way TOM 2 TOM gt TOM M TO OM T gt TOM Note that the character indicates a blank space Assemble the program by hand and load it into ESC program memory Initialize by hand in ESC simulator for the first 5 ESC data memory locations with the first 3 letters of your name following by two space characters Execute your simulator and show your TA that the program is working in ESC data memory using fixed memory locations STUDY QUESTIONS REPORT 2009 Oregon State University ECE375 Manual Page 51 Section Six Extremely Simple Computer ESC Write up a short summary that details what you did and why explain any problems you may have encountered and answer the below Your write up and code must be submitted to your TA by the beginning of class the week following the lab NO LATE WORK IS ACCEPTED Since this 1S a group project only one lab report needs to be submitted per group Make sure both the group members names are on the report CHALLENGE Since this extra credit 1s worth quite a bit in the overall lab scheme you are going to have to work for it Create an ESC compiler This means you need to create a simple program in any language you choose that reads in
9. This is a group project You can work in groups of two PRELAB No prelab is required PROCEDURE Specifications The details of your extremely simple computer from here on out referred to as ESC are as follows 2009 Oregon State University ECE375 Manual Page 46 Section Six Extremely Simple Computer ESC Instruction Format Internal Data Bus M To from memory and WO devices control signals External control signals Figure 1 ESC Architecture Diagram Data 8 bits signed Registers There are only 4 special registers in the ESC 1 Accumulator ACC The accumulator is not addressable It is used in some ESC instructions but its address does not appear in these ESC instruction bit vectors Instead with the operations that use the accumulator it is built in that the accumulator should be used The ESC accumulator should be located in the ATmega128 data memory location 0100 2009 Oregon State University ECE375 Manual Page 47 Section Six Extremely Simple Computer ESC 2 Program Counter PC The use of the PC 1s transparent to the ESC user The PC 1s initialized to 00 the beginning of the program memory space and incremented after each ESC instruction The PC should be located in ATmegal28 data memory location 0101 Although the ESC program memory only needs 3 bits to address we need to set this to correspond to AVR data memory this means you will have to write a function that
10. an asm file containing your ESC Assembly program in it The ESC compiler will then parse through the asm file converting all the assembly mnemonic instructions i e ADDM 04 into the appropriate binary op code 1 e 00100100 or 24 This new op code is then written out to an obj file With this output file you can very easily program your ESC simulator by cutting and pasting the op codes into a DB statement and using the LPM command to initialize the ESC program memory with it To get credit you must demonstrate this program to your TA and turn in a copy of the source code with your report NOTE You can write this in any language you want C C 1s a good choice since you don t get enough of it in your undergrad curriculum and all TAs are proficient at C C so they should be able to help you If VB 1s more to your taste go ahead But if you are really courageous write your program in PERL PERL is a good language for text manipulation and parsing although it 1s not really user friendly 2009 Oregon State University ECE375 Manual Page 52 Section Seven Remotely Operated Vehicle v2 0 SECTION SEVEN REMOTELY OPERATED VEHICLE V2 0 2009 Oregon State University ECE375 Manual Page 53 Section Seven Remotely Operated Vehicle v2 0 SECTION OVERVIEW e Use your knowledge of computer architecture to create a real system as a proof of concept for a possible consumer product e Improve your knowledge of interrupt
11. an engineer 1s to be able to choose the BEST option based on all pertinent information Write your assembly program and download it to your TekBot Show your TA the operation and the code and have them sign below for credit Be sure your code is well commented Skeleton code 1s available on the webpage TA Signature STUDY QUESTIONS REPORT Write a short summary that details what you did and why explain any problems you may have encountered and answer the questions below Submit your write up and code to your TA via email by the beginning of class the week following the lab NO LATE WORK IS ACCEPTED Study Questions 1 As an engineer you should be able to justify your design and testing choices You have implemented this bumper TekBot in three ways now Explain the benefits and costs of all three implementations Some important areas of interest include but are not limited to efficiency speed cost of context switching time to code understandability etc 2009 Oregon State University ECE375 Manual Page 43 Section Five Simple Interrupts 2 Now that you have a basic understanding of interrupts would work would 1t be possible to use a timer counter interrupt to perform the wait loop while the robot 1s between transitions within the external interrupt HINT The order in which the interrupt is located within the interrupt vector list is also the priority the lower on the list the higher the priority Give a reasonable argum
12. electrical components are likely to be damaged by static electricity Static charge can build up to many thousands of volts but with little energy This cannot harm humans but it can easily damage electronic components To ensure static safe handling the best practice 1s to wear an anti static strap and connect it to an earth ground such as a computer case or a water pipe If you do not have an anti static wristband you can instead touch a ground every few minutes to discharge your static build up 2009 Oregon State University ECE375 Manual Page 9 Section One Introduction to AVR Development Tools SECTION ONE DEVELOPMENT TOOLS INTRODUCTION TO AVR 2009 Oregon State University ECE375 Manual Page 10 Section One Introduction to AVR Development tools SECTION OVERVIEW Complete the following objectives Connect your AVR microcontroller board to a TekBot Create a new AVRStudio4 project Download and compile the sample AVR Assembly source code Understand how to run and operate the Universal Programmer Upload and run the sample program on the TekBots AVR microcontroller board PRELAB In labs to come you will be required to complete a prelab for each lab The prelab will cover concepts and knowledge that is required for the lab The prelabs are due at the beginning of your lab section each week If you do not have your prelab done at the beginning of the lab period you will receive no credit for the prelab Prelabs a
13. to properly setup and call the functions in the LCD driver To do this you must first include it into your program Unlike the definition file the LCD driver contains actual assembly code and thus cannot be included at the beginning of the program file like the definition file A quick look at the AVR Starters Guide under proper coding structure tells us that any include code file 1s included at the end of the program 1 e the last lines The actual LCD driver file is called LCDDriver asm and can be downloaded from the lab website There will also be another program file called LCDTest asm that utilizes every function described below You can download it for a sample of using the LCD The following are the LCD driver function definitions In order for any function call to work the stack pointer must be initialized prior to the function call LCDlnit This subroutine initializes the serial interface that 1s used to communicate with the LCD display initializes the Hitachi Display Chips with 8 bit Incremental DD RAM Pointer with no features and sets the display to 2x16 characters reall LCDlInit Call LCD Init Subroutine LCDWrite This 1s a generic function that will write out both lines of text to the LCD display The line data is fetched from the following AVR data memory addresses Line 1 0100 010F Line 2 0110 011F In order to use this function you must first put the data 1 e ASCII string that you want displayed on the L
14. 0000000000 31 OS D ee ane a ee nd nn 31 CHALLENGE o eo so ee0c 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 31 SECTION FOUR LARGE NUMBER ARITHMETIC EECH 33 SECTION OVERVIEW eee 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 34 PR PRO MER LI CUIVIS EMI MEI E PROC DURE PPP ASSIGNMENT a STUDY OUESTIONS REPORT DEE 36 S ANG UE T ARR ee SES A SVS S ER PR SERRE EE H 36 IAT MI DA E O PR R ie D SECTION FIVE SIMPLE INTERRUPTS 41 BECTION OP VEE VIE WO nt tie tri il io e PRELAB Reeg 42 PROC DURE a nt e I TO oiii Ua casei ccs iene ce OPM eae C Ca n 43 2009 Oregon State University ECE375 Manual Page 4 Wierni pine KE E 43 STUDY OUBSTIONSUREPORT eds e sie UU TE 43 ARR a ed SECTION SIX EXTREMELY SIMPLE COMPUTER ESC 45 SECTION OVERVIEW 9 Ome w o NI n PPP ET 46 PRELAB M PORE 10 PROCEDURE Y a ei LTE core dd dessert te A EAE tt berne A k delka ka 46 Bir WEE 47 Ke LES E 47
15. ARS ae AVE PR RE D A NURecd PMS RA R Do ada Ka en PA MAA ed NO Na a 48 AER E ue E 49 Program Memory E 49 JE TC CONS sire ties ae ea E t 50 EE E CO S1 Ter rror D CRD OS en na ee te 0 1 7707 0 177 51 S H I l QUESTIONS REPORT dee A E E sass aca ates va scan ec sss vs vs ora dv con ca asta vas e SECTION SEVEN REMOTELY OPERATED VEHICLE V2 0 53 BECTHIUNOVERVIEW nds C C C c r0 n PRELAB E Problem ER ie E 54 STUDY OUESTIONS REPORT aaa cc MEDIE E EE Mi E CHALLENGE BREEZE KL GE APPENDIX A PARTS LISTS i ieossvasazicixbsktusSsiide Egger gedd Reeg 58 PARIS LIST EE APPENDIX B SCHEMA DIG S a ee ea angers ess 60 MEGAT28 sl 2009 Oregon State University ECE375 Manual Page 5 Figure 51 Block diagram of the charger board 61 A R ISP 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 62 Figure 54 Block diagram of the analog board 62 APPENDIX Eet 63 2009 Oregon State University ECE375 Manual Page 6 2009 Oregon State University ECE375 Manual Page 7 During this course you will work with components and circuits that you will use in your own engineering careers The objective is to show the
16. CD in the appropriate line address in data memory Then call the function Move ASCII string to line addresses 0100 011F reall LCDWrite Write string to LCD LCDWrLn1 This function will write the ASCII string in the first line AVR data memory address 0100 010F to the first line of the LCD Display In order to use this function you must first put the data 1 e ASCII string that you want displayed on the LCD display line 1 in the line 1 addresses 1n the data memory and call the function 2009 Oregon State University ECE375 Manual Page 27 Section Three Data Manipulation and the LCD Display Move ASCII string to line addresses 0100 010F reall LCDWrLnl Write string to LCD LCDWrLn2 This function will write the ASCII string in the second line AVR data memory address 0110 011F to the second line of the LCD display In order to use this function you must first put the data 1 e ASCII string that you want displayed on the LCD display line 2 in the line 2 addresses in the data memory and call the function Move ASCII string to line addresses 0110 011F reall LCDWrLn2 Write string to LCD LCDClear This subroutine will clear both lines of the LCD display and the lines in AVR data memory will be cleared to the ASCII value of space No prior setup 1s required reall LCDClear Clear both lines of LCD LCDCirLn1 This subroutine will clear line 1 of the LCD Display and line 1 in the AVR data memory i
17. ECE 375 DMPUTER ORGANIZATION AND ASSEMBLY A TekBots Course INTRODUCTION TO C 2009 Oregon State University ECE375 Manual Page i Copyright Information Copyright 2009 Oregon State University School of Electrical Engineering amp Computer Science EECS This document is the property of Oregon State University and the School of EECS Limited use of this document is allowed according to the following criteria Materials are free to use except for the cost of reproduction and must always bear this statement in any reproduction Materials created using this information may not be labeled as TekBots materials without the prior written consent of both Oregon State University and the School of EECS Disclaimer of Liability Oregon State University Platforms for Learning TekBots and other partner schools are not responsible for special consequential or incidental damages resulting from any breach of warranty or under any legal theory including lost profits downtime goodwill damage to or replacement of equipment or property or any costs of recovering reprogramming or reproducing any data stored in or used with our products The aforementioned parties are also not responsible for any personal damage including that to life and health resulting from use of any of our products You take full responsibility for your product application no matter how life threatening it may be Internet Access We maintain Inter
18. K You can find this information from either the AVR Instruction Set guide or the ATMegal28 Reference Manual You can find both of these on the TekBots webpage for the ECE375 course HINT These registers are related to external interrupts 3 The AVR microcontroller uses interrupt vectors to run code when an interrupt is triggered What is an interrupt vector List the memory locations for the following vectors in the AVR microcontroller Timer Counter2 Comparison Match External Interrupt 2 and USARTI Rx Complete 4 Inthe AVR microcontroller like with many others there are several different ways of triggering interrupts Below is a sample signal being input onto one of the external interrupt pins List where the interrupt would trigger on this waveform if the interrupt was set up as a rising edge b Falling Edge c Level High and d Level Low TT ee ee ee TT TT T 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Figure 1 Sample Input to External Interrupt PROCEDURE 2009 Oregon State University ECE375 Manual Page 42 Section Five Simple Interrupts Introduction Most modern day computing systems use interrupts to communicate with peripheral devices This lets the microprocessor s function and perform calculations until a peripheral device needs attention Some examples of this are how PC hardware used to have interrupts that a user would have to define so that maybe a sound c
19. al Page 58 Appendix A Parts Lists PARTS LIST cription y a128 2 isp ramming table ale Jumper Blocks 2009 Oregon State University Supplier ig ur e TekBots TekBots TekBots Digikey ECE375 Manual plier a128 2 isp isp cable 228 ND Fig A Fig C Fig B Page 59 endix B Schematics 2009 Oregon State University ECE375 Manual Page 60 endix B Schematics EGA128 2 IR Transmitter IR Receiver TE PHAAGI 2 Hadari x2 Vee zn x Gnd ia iv Ui Saak R34 03 Header1 2 External RAM Pert _ 7 3 Port_C 14 9 tan Rh 15 E Kr d 20 SCH BEL L CN di 20000000 Dr Li quw 4 ri ah RE h ED ED IE Dh ei vw 1 5 ON L a Wen LL Pert FCT 03 TXD amp PDA RDA POI _TQ9C2 TOS I EzbEtBittiE 2 RER B lu Haadar1x2 B tuF 0 CS Zu 2418 LCD Part 6C2 0 Hitachi Hi 6 4 og 2 KS m i 8SPiSSEZB8E RS fo tuF RES CES a tu a tuF a tuF Ja tuF c c c3 CQ cit G2 c4 cs n Kic Tal Oregon State University TekBots 2004 Copyright 2003 Oregon State University TITLE DU Adriaan Smit Date Drawing Number Sheet of megal28 2 April 21 2004 2 2 1 1 Figure 51 Block diagram of the charger board 2009 Oregon State University ECE375 Manual Page 61 endix B Schematics
20. and only use 3 registers In order to do this you would shift everything to the right instead of to the left and also rotate through the carry So 1f the carry bit 1s set after the shift add the multiplicand to the high register of the result and shift again otherwise just shift Note that when shifting to the right you need to rotate through the carry this means that whatever is in the carry bit will be shifted in the most significant bit and the least significant bit will be shifted out into the carry bit For example c MB B gt gt Rotate Right Through Carry Bit The following figure demonstrates this Multiply 1011 Multiplicand 1101 Multiplier 0000 1101 lt Load Multiplier into low register l 0000 0110 lt Shift right through carry 1011 Carry is set so add multiplicand 0 1011 0110 lt Result of addition 0 0101 1011 Shift right through carry Don t add since carry is 0 0101 1011 lt Result thus far l 0010 1101 lt Shift right through carry 1011 lt Add multiplicand since carry is set 1101 1101 lt Result of carry l 0110 1110 lt Rotate right through carry 1011 lt Add multiplicand since carry is set 2009 Oregon State University ECE375 Manual Page 38 Section Four Large Number Arithmetic l 0001 1110 lt Result of addition 0 1000 1111 lt Result after final shift note that a 1 was shifted in because 1t was the carry that was set from the last addition As
21. ard or joystick could ask the microprocessor for attention Using interrupts can be tricky and sometimes wasteful When an interrupt request comes in the microprocessor has to stop what it is doing store any special variables and then service the interrupt Once the interrupt is done the processor then must reload its original special variables and restart what it was doing For example if a peripheral wants the microprocessor to store a single byte of data every couple of clock cycles it may try to interrupt the microprocessor every couple of clock cycles This would force the microprocessor to spend all of its time storing its special variables servicing the interrupt reloading the special variables and then starting all over again when the next interrupt comes 1n The cost of servicing an interrupt in this manner is called a context switch This 1s why many modern computers have coprocessors and peripheral controllers like DMA for example to handle these frequent requests Interrupting a TekBot You will need to write a short assembly program that causes your TekBot to move forward Then when either its right or left whisker is hit it will need to react by interrupting the AVR microcontroller to back up and turn away from the point of impact This will make your TekBot function as it has before in Lab 1 and Lab 2 but using a different method in code This is an important point to note There is ALWAYS more than one option solution Your job as
22. converts the 5 bit ESC program memory address into the corresponding 16 bit AVR data memory address 3 Instruction Register IR The use of the IR 1s also transparent to the ESC user The current ESC instruction as a binary code is stored in the IR The ESC simulator will read the instruction that is in the IR register to know what operations to do The ESC IR should be located at ATmegal28 data memory location 0102 The IR should be initialized to 00 4 Memory Address Register MAR The MAR will be used to access data memory in ESC This register is very similar to the PC It contains the address in ESC data memory where data is being loaded and stored This register should be located at ATmegal28 data memory location 0103 When accessing the ESC data memory the address of the ESC data memory must be put into this register A function is then called that converts the 5 bit ESC data memory address into the corresponding 16 bit AVR data memory address The MAR should be initialized to 00 5 Memory Data Register MDR The MDR 1s used to hold the input and output data from the data memory 1n the ESC All data must go through this register before coming from or going to ESC data memory This register should be located at the ATmegal28 data memory location 0104 An example of usage for getting memory from data would be as follows The data memory address is stored in the MAR Then the data from the address in the MAR 1s stored within the MDR
23. ection contains all of the tasks to be Procedure completed All tasks are related to lecture Keeping this in mind will help in better understanding the lecture and lab material The study questions are intended to give more practice and insight into what has been learned in lab and lecture The study questions will be due in the next week s lab Study Questions The challenge sections of labs are extra credit Performing the tasks in the Challenges challenge sections will improve understanding of what is being learned and will result in some really cool innovations LAB SAFETY Safety is always important when working with electricity and electronics This includes both the safety for you as well as safety for the circuit components you are working with Concerns such as high voltage or currents can affect the human body while static safety and proper component use can affect the life of your circuits Personal Safety When working with high voltages and currents it is important that you remember that you can be hurt if your body becomes the circuit since the human body is a conductor of electricity This issue has long been combated by using the one hand rule Whenever you are working with a potentially dangerous circuit turn it off but if it cannot be turned off use only one hand when working on it This will prevent a circuit from being made through your heart which could be potentially fatal Component Safety Many
24. emely Simple Computer ESC Data soi This op code identifies a group of instructions that does not need an address or data in LSB bits 00000ddd STMI Store immediate data 3 LSB sign extended into address specified E NN the accumulator 000100 J CLRA J Cleartheaccumulatr 00010000 LDMI Load indirect read into the accumulator the value at the address specified by the contents currently in accumulator wuwo HAUT RH ESC simulator stops execution 001aaaaa ADDM Add direct memory location Si content to accumulator and place result in the accumulator ben 10aaaaa SUBM 0x Subtract direct memory location lt lt 31 content from accumulator mx laaaaa Move the contents of a direct memory location to the accumulator 100aaaaa Store the contents of accumulator into a memory location 101 NEL DT UMP lt Jump unconditional lt 15 d lt 15 111ddddd MOVI 16 lt Move immediate to Figure 3 Instructions for the ESC Simulator Instructions 2009 Oregon State University ECE375 Manual Page 50 Section Six Extremely Simple Computer ESC All instruction codes in ESC are 8 bits There are three separate formats for the groups of instructions 1 The first group consists of ADDM SUBM MOVI LDM STM JUMP and JMPZ instructions For these the most significant 3 bits are used for the op code and the other 5 are used for the direct address to spec
25. ent either way Challenge 1 Sometimes your TekBot can get caught in a loop where it 1s stuck 1n a corner and 1t continually backs up hits the right whisker then backs up and hits the left whisker then the right then left and so on Add a memory to your TekBot so that it can detect this problem and when it has hit alternating whiskers five times it will stop turn around 180 degrees and resume forward motion to get out of the corner In addition correct the simple problem of the TekBot hitting the same wall several times In this scenario the TekBot hits one of its whiskers backs up and turns away but does not turn far enough and hits the same object In this case you need to make the TekBot backup and turn away twice as far as 1f the whisker has been hit twice in a row Write your program and keep it well documented Turn in your code along with your write up and have you TA sign below that they have seen your functioning code TA Signature 2009 Oregon State University ECE375 Manual Page 44 Section Six Extremely Simple Computer ESC SECTION SIX EXTREMELY SIMPLE COMPUTER ESC 2009 Oregon State University ECE375 Manual Page 45 Section Six Extremely Simple Computer ESC SECTION OVERVIEW Review and utilize all knowledge about computer organization Create the link between hardware and software Develop and simulate a functional simulator Enhance knowledge about functions and subroutines Note e
26. estions for this lab assignment CHALLENGE Complete the assignment with the following shift and add multiplication technique instead of sum of products technique described above If you complete the challenge section it will count for both the lab assignment and challenge portion 2009 Oregon State University ECE375 Manual Page 36 Section Four Large Number Arithmetic Although the sum of products technique 1s easier for humans to perform multiplications 1t 1s not the most efficient way for multiplying binary numbers especially very large numbers like 1024 bit numbers Also it 1s very difficult to implement a sum of products multiplier in hardware So a variation to the technique was created and used the inherent properties of a base 2 number system This technique is known as the shift and add multiplier Referring back to the basic concepts of mathematics multiplication has two operands the multiplicand or the operand to be multiplied and the multiplier When a decimal number is multiplied it essentially adds the multiplicand to itself for the amount specified by the multiplier This seems pretty obvious until you use binary In binary the multiplier 1s used to determine whether the multiplicand 1s added or not The figure below will demonstrate both decimal and binary multiplications Decimal 23 Multiplicand T 16 Multiplier 138 6 32 138 E 230 1 23 23 and then shift 23 left one 230 368 Final Multipl
27. he IR the receiver can see this signal and will receive the same data This means you can compare what you sent with what you receive to see if there has been an error in transmission This error could be because there are multiple remotes running at one or a possible programming error 5 You would like to have some minimal intelligence on the robot When either of the front whiskers 1s triggered the robot should reverse and turn away from the point of contact ignoring any input from the remote control After the robot has avoided the object it should resume what it was doing before the impact There is a piece of sample skeleton code available on the web If you would like to use it go ahead If not feel free to do your own design 2009 Oregon State University ECE375 Manual Page 55 Section Seven Remotely Operated Vehicle v2 0 STUDY QUESTIONS REPORT Write up a short summary that details what you did and why explains any problems you may have encountered and answer the questions below Be sure to explain the operation of your code 1n the document Do not rely only on the comments in your code to describe the function of the code This write up is due by 4pm on Friday of dead week One of the TAs will be available in the lab to take your submissions NO LATE WORK IS ACCEPTED CHALLENGE FREEZE TAG Since you are going to be showing your proof of concept to upper management you feel you need to have something that can generate some
28. his address each time a command 1s transmitted You have decided to send two eight bit codes one address and one data Address code must start with a 0 and data codes must start with a 1 Figure 1 shows an example Device ID Action Code un T c RS c O UO 0 X XX xX xX xX x Command Structure Figure 1 Example command structure 2009 Oregon State University ECE375 Manual Page 54 Section Seven Remotely Operated Vehicle v2 0 2 The AVR boards you are using have a built in IR transmitter and receiver connected to one of the serial UARTs You feel that the UART 1s a good option for communicating to the robot You will need to setup the UART on both the robot and the remote The AVR can set up the UART to communicate at high speeds but you know that the IR transmitter and receiver cannot work this fast You should use a baud rate of 2400 3 For your simple proof of concept model you only need a few actions forward stop reverse left and right To make your life easier you decide to spec out what the different commands are before you start coding These commands are shown below in Table 1 Command Action Code Forward 0b10110000 Backward 0b10000000 Turn 0b10100000 Right Turn Left 0b10010000 Halt 0b11001000 Future 0b11111000 Use Table 1 Action codes for proof of concept model 4 You can take advantage of a built in loop back for the IR system on the AVR boards When something 1s transmitted using t
29. ication Product Now we apply this same knowledge to a binary system that uses 4 bit values The basic principle 1s that we shift through the multiply When a 1 1s received we add the multiplicand to the low bit of the result if a zero 1s received we do nothing We then shift the entire result one bit to the left thus essentially multiplying the result by 2 and repeat the process Below is an example Binary 4 bit 1011 Multiplicand 1101 lt Multiplier Multiplier LSB 1 0000 1011 lt 1 1011 1011 1011 shift left zero 00001011 0 0000 0000 0 1011 0000 0000 shift left one 00000000 0000 1011 lt Add results together l 0010 1100 lt 1 1011 1011 1011 shift left two 00101100 0011 0111 lt Add results together MSB 1 0101 1000 1 1011 1011 1011 shift left three 01011000 1000 1111 lt Add results together to get final product Proof Multiplicand Multiplier Product Bin 1011 1101 1000 1111 2009 Oregon State University ECE375 Manual Page 37 Section Four Large Number Arithmetic Dec 11 T 13 143 Correct Although the method above 1s sound and easily understandable there 1s a more efficient method For the purpose of this example assume you are running on a 4 bit system where the registers are 4 bits It would take 4 registers to do the method above A better way would be to share the low result registers with the multiplier registers so you can shift all the registers at once
30. ify an ESC Data Memory address or signed data The format for these instructions will be Bit 7 Bit Bit5 Bit4 Bit3 Bit2 Bitl BitO OPCODE Address or Data 2 The second group consists of the HALT CLRA LDMI and STMI For the HALT CLRA and LDMI instruction the most significant 5 bits are used to the op code They do not use the other 3 bits except that STMI uses the least significant 3 bits sign extended to occupy 8 bits as the immediate data to be stored Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bitl Bin OPCODE X X X Note the exception when the instruction is STMI bits lt 2 1 0 gt will contain signed immediate data limited to the range 000 to 111 4 3 when using indirect addressing mode NOTE For all signed data you will need to sign extend the signed data values to fill the 8 bits 1 e JMP 13 10110011 Data value gt 00010011 Sign Extended gt 11110011 Assignment You will be working in groups of two You are to write assemble and simulate the ESC using AVR assembly language according to the specifications described above In order to demonstrate to your TA that your ESC 1s properly working you will need to write a test program described below and run it on your simulator In addition your TA will provide you with some other ESC code to test other instructions not used in your test program NOTE Feel free to write your own ESC program that will test all the various functionality of ESC Test
31. in R2 and R3 The operation result is placed in the registers R4 RS and R6 1 1 Possible Carry In Bit RO RI Possible Carry Out Bit gt 1 R2 R3 2009 Oregon State University ECE375 Manual Page 34 Section Four Large Number Arithmetic As this calculation demonstrates we need to add R1 to R3 and accommodate for any carry in bit The result of this operation is stored in R6 Next we add RO to R2 and accommodate for any carry in bit from the previous operation If there is a final carry bit then it is stored in R4 Note that since we want to reserve the carry out bit from the operation we actually get a 17 bit result 16 bit plus the carry But since the AVR architecture inherently supports 8 bit numbers and we use 3 registers we treat the result as a 24 bit number where the most significant byte has the value of either 1 or 0 depending on the carry out bit The AVR instruction set contains a special instruction to perform multiplication MUL This instruction multiplies two registers and stores the result in registers RO and R1 Therefore a multiplication of 2 single byte registers generates a 2 byte result This instruction can be used as a fast and efficient way to multiply two 8 bit numbers Unfortunately it can be very complicated to use when multiplying 16 or more bit numbers The easiest way to understand how to multiply large numbers is to visualize it like using the paper method to multiply this method is also know
32. in the fashion described above You will need to expand on this function for the lab assignment ASSIGNMENT Write a program in AVR Assembly that calculates the result of A B 2 A and B are 16 bit numbers or 2 bytes thus A B will produce a 3 byte result since we want to save the carry bit That result will then be multiplied by itself to produce a final 6 byte result To do this you will need to write two functions a function that adds two 16 bit numbers and produces a 24 bit result and a function that multiplies two 24 bit numbers The two operands will be entered in data memory during simulation time Operand A is at the data memory location 0100 and 0101 Operand B is at data memory location 0102 and 0103 The 6 byte result will be stored in the data memory locations 0104 0109 This lab will not use the TekBot platform or the AVR board It is purely a simulation based lab Write and assemble the program test it and demonstrate the program to your TA The TA will provide two numbers for you to run the simulation on when you submit the assignment Turn in the write up and the source code to your TA STUDY QUESTIONS REPORT Write a short summary that details what you did and why explain any problems you may have encountered and answer the questions below This write up and your code should be submitted to your TA by the beginning of class the week following the lab NO LATE WORK IS ACCEPTED Study Questions No additional qu
33. indow will appear showing if there were any errors or warnings If you set up your project as asked you should just need to press the enter key to program your TekBot Of course your TekBot needs to be connected to your PC and powered on first Your Own Code You need to write a simple C program that will make your TekBot act like it did in Lab 1 Your TekBot should travel forward until it encounters and object then back up and turn away from the object If for some reason both whiskers are triggered at the same time your TekBot needs to back up and turn to the RIGHT HINT Use the delay ms function 1 Write a simple C program that performs this function You will probably want to use the skeleton code available on the web and modify it as needed Remember which version of the TekBot you have when designing the motor control logic It 1s recommended that you use the pin out in the skeleton file but it 1s not necessary 2 Demonstrate the operation of your TekBot to your TA for credit Have him her sign below TA Signature STUDY QUESTIONS REPORT Write a short summary that details what you did and why explain any problems you may have encountered and answer the questions below Your write up and code must be submitted to your TA via email by the beginning of class the week following the lab NO LATE WORK IS ACCEPTED 2009 Oregon State University ECE375 Manual Page 22 Section Two C Assembler Machine Code TekBo
34. ing well structured code as defined in the AVR Starters Guide Initialization A program initialization consists of any code that is only run once at the beginning of the program This code does not belong in the MAIN program this is why most Assembly programs begin with INIT and not MAIN The INIT function is not a function in the classic sense but rather a function that is called at reset and at power on and jumps to the main program once it is finished There are several things that should be contained in the INIT function The first and foremost is the initialization of the stack pointer The stack in AVR operates in a higher to lower address fashion meaning that newest element on the stack is in a lower address space than the previous element Therefore the stack should be initialized to the highest data address space available See the AVR Starters Guide for more information about the stack 2009 Oregon State University ECE375 Manual Page 26 Section Three Data Manipulation and the LCD Display Other things that are initialized within the INIT function are ports timers interrupts and other peripherals For this lab you will need to initialize the LCD display Making a function call to the LCD Initialization Subroutine does the LCD initialization You will also need to move data from the program memory to data memory in the INIT function LCD Driver User Manual To successfully use the LCD display for this lab you will need
35. lines from left to right When a character 1s at the end a line it will be displayed at the beginning of the opposite line 1 e a character on slot 16 of line 1 will go to slot 1 of line 2 and a character on slot 16 of line 2 will go to slot 1 of line 1 You will also want to add a wait loop after all the characters have moved one slot so that you can read the characters Below is an example of the display and motion where signifies a space 1 Line My Name is Line 2 John Doe wait 25sec 2 Line 1 My Name is Line 2 John Doe wait 25sec gt Line 1 e My Name 1 Line 2 s John Do wait 25sec 2009 Oregon State University ECE375 Manual Page 31 Section Three Data Manipulation and the LCD Display 4 Line 1 oe My Name Line 2 1s John D wait 25sec etc Use the strings that are required for the lab to scroll Submit this code with your report Demonstrate the challenge problem to the TA for credit 2009 Oregon State University ECE375 Manual Page 32 Section Four Large Number Arithmetic SECTION FOUR LARGE NUMBER ARITHMETIC 2009 Oregon State University ECE375 Manual Page 33 Section Four Large Number Arithmetic SECTION OVERVIEW e Understand and use arithmetic and ALU operations e Manipulate and handle large numbers e Create and handle functions and subroutines PRELAB e For this lab you will be asked to pe
36. maries that detail what you did and why you did it Explain any problems you may have had and answers some questions that are specific to each lab The hard copy of write up along with your code should be submitted to your TA by the beginning of class the week following the lab NO LATE WORK IS ACCEPTED The write up should be typed It should be neat and free of misspelled words Be sure you have used sufficient comments for ANOTHER STUDENT to be able to understand your code Code that 1s not well documented will be penalized severely If you are interested 1n an example of what this might look like look at the TekBots web page or the code you just downloaded Study Questions Labs will commonly have study questions for you to think about while performing the lab You will need to answer these questions within your lab write up This lab has no lab write up so there are no study questions 2009 Oregon State University ECE375 Manual Page 14 Section One Introduction to AVR Development tools CHALLENGE Challenge problems are additional tasks that can be preformed for the labs By successfully completing a challenge problem you can get extra credit for your lab To get credit for the challenge problem you must successfully demonstrate it to your TA as well as document it in your lab write up 1 You have learned to use a simple tool to download a program into your TekBot Modify the program so the TekBot reverses twice as long before tu
37. n as the sum of products technique The following figure illustrates the typical paper method 24 24 4x6 24 12 2x6 12 shifted by one 28 4x7 28 shifted by one 14 2x7 14 shifted by two As you can see the paper method multiplies small numbers numbers less than 10 and then adds all the products to get the final result We can use this same technique for large binary numbers Since there 1s an instruction that supports multiply MUL we can multiply two 8 bit numbers at a time and then add up all the products Below is an example of how to multiple two 16 bit numbers Al A2 BI B2 H22 L22 H21 L21 H12 L12 H11 L11 PI P2 P3 P4 2009 Oregon State University ECE375 Manual Page 35 Section Four Large Number Arithmetic As you can see the result of multiplying two 16 bit or 2 byte numbers gives a 32 bit or 4 byte result In general when multiplying to binary numbers the result will be twice the size of the operands For reference the H and the L signify the high and low byte of the result of each multiplication and numbers signify which values where multiplied B and A For example L21 1s the resulting low byte of multiplying B2 and AI together Also note that the four results are just the following PI lt H11 carry from P2 P2 lt H21 H12 L11 carry from P3 P3 lt H22 L21 L12 P4 lt L22 The skeleton code provided for the lab will contain an algorithm that multiplies 2 16 bit numbers
38. n the same fashion as LCDClear No prior setup is required reall LCDClrLnl Clear line 1 LCDCIrLn2 This subroutine will clear line 2 of the LCD display and line 2 in the AVR data memory in the same fashion as LCDClear No prior setup 1s required rcall LCDCIrLn2 Clear line 2 LCDWriteByte This function allows you to write a single ASCII character or byte anywhere on the LCD display This allows complete control over where things go within the display and does not require the AVR data memory lines as 1n the previous functions There are three registers that need to be initialized prior to calling this function count Holds the index value of the line to where the ASCII Char will be written 0 15 of 39 Indexes 0 15 are visible on the display but can be up to 39 thus indexes 16 39 are off screen If count has a value of 3 then the ACSII char will be written to the 3 element on the LCD display line Holds the line number that the char is going to be written to 1 or 2 mpr Contains the value of the ASCII char to be written 0 255 Example of writing D to Line 2 slot 7 2009 Oregon State University ECE375 Manual Page 28 Section Three Data Manipulation and the LCD Display Idi mpr D mpr lt D ldi line 2 line lt 2 ldi count 7 count lt 7 rcall LCDWriteByte Write Byte to LCD Display Bin2ASCII This function will convert an unsigned 8 bit binary number in
39. net systems for your use They can be used to obtain free TekBots software and documentation and also to purchase TekBots products These systems may also be used to communicate with members of TekBots and other customers Access information is shown below E mail tekbots eecs oregonstate edu Web http eecs oregonstate edu education tekbots html 2009 Oregon State University ECE375 Manual Page ii TABLE OF CONTENTS ECE 375 INTRODUCTION TO COMPUTER ORGANIZATION AND ASSEMBLY l PREFACE oraa sk ene poet A S A O E Oe 7 IMPORTANT SYMBOLS D LAB STRUCTURE PPR T EEE EE AE T EOE A NEEE LE ESE AE E E S AA E LAB SAFETY EENG idi d E 9 Re E ne cr cm moon ue oo 9 SECTION ONE INTRODUCTION TO AVR DEVELOPMENT TOOLS 10 LAB 11 PRELAB 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 23 A PROCEDUR sn ec ec M Looking at some AVR Source e E 12 4 al P STUDY QUESTIONS A kPORT 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 R H ions 14 S O TA a s lt s ss i ia HALLENGE 15 CH A L ul DO SB 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 l4 7 SECTION TWO C ASSEMBLER MACHINE CODE TEKBOT 17 SECTION OVERVIEW P OP RO ro C
40. non electrical engineer how electronics 1s important to other engineering fields You will be designing sensors and sensor circuits to measure real phenomena not just arbitrary circuits Everything learned in lecture has relevance and 1s useful 1n later courses and future careers As various tasks are performed in these labs pay attention to how lecture material relates to the tasks Understanding how the lecture material is used and applied will greatly improve understanding of the topics IMPORTANT SYMBOLS This symbol indicates an important note that should be remembered Paying attention to notes like these will make tasks easier and more efficient This symbol designates information that must be followed If caution is ignored the task may appear impossible Ignored caution symbols can lead to damaged systems This symbol represents something that should not be forgotten Reminder symbols are used to make sure an important step has been completed before continuing The innovation symbol indicates an opportunity to advance beyond what is required These sections will give more insight into the what why and how of a certain topic Use these to learn more or get ideas for nifty innovations 2009 Oregon State University ECE375 Manual Page 8 LAB STRUCTURE Section The section overview will describe briefly what will be learned in the Overview section and what will be done The procedure portion of each s
41. our computer 2009 Oregon State University ECE375 Manual Page 12 Section One Introduction to AVR Development tools 3 Follow the steps in Section 2 1 2 in the AVR Starters Guide to create a new project In most IDE tools a project is the base starting area to your program It consists of all files you use and any settings for the program When following this tutorial you ll want to use the AVR assembly source code you downloaded from the web in step 1 4 With the current project activated in step 4 follow the Project Simulation tutorial in Section 2 1 3 of the AVR Starters Guide to learn how to compile and simulate your program By the end of this step you should know how to successfully create an AVR project from scratch and be able to compile it into usable program hex code 5 When assembly source code is compiled it creates a binary program file called a HEX file with a hex extension This HEX file contains the actual binary instructions that are used by the ATmegal28 and 1s what needs to be uploaded onto the AVR Microcontroller Board Unfortunately AVRStudio4 does not have the ability to program the actual chip To do this you will need to run the Universal Programmer This is an open source program that can upload the AVR HEX programs to the various AVR microcontrollers 6 Follow the tutorials in Section 3 of the AVR Starter to install PonyProg and upload the AVR program into the ATmegal 28 Use the HEX file that was gene
42. play You must first correctly initialize your program To help you along the process skeleton code is provided Use this as a starting point When you are finished demonstrate your LCD Display to the TA to get credit Have them sign below 2009 Oregon State University ECE375 Manual Page 30 Section Three Data Manipulation and the LCD Display TA Signature STUDY QUESTIONS REPORT Write a short summary that details what you did and why explain any problems you may have encountered and answer the questions below Submit your write up and code to your TA via email by the beginning of class the week following the lab NO LATE WORK IS ACCEPTED xe Questions In this lab you were asked to manipulate data by moving it around in memory In fact the AVR architecture has two different memories a program memory and data memory Briefly explain the differences and purposes of these memories within your write up 2 You also learned how to make function calls Explain how the function call works its connection to the memory stack and why a RET instruction must be called to return from a function To help you understand comment out the stack pointer initialization in the beginning of the code and try running the program Observe and comment on this behavior CHALLENGE Not being content with displaying a static message you would like to add some flare by creating a scrolling marquee style message Your text will scroll across the
43. rated by AVRStudio4 from the previous steps HINT When testing and debugging a program it 1s useful to keep both AVRStudio4 and PonyProg running at the same time Load only the HEX file the first time you start PonyProg If you make changes to the code simple recompile and then ALT TAB over to PonyProg and hit the Reload files button This will update the HEX file within PonyProg to reflect any changes made to the program Then upload the code to the chip again 2009 Oregon State University ECE375 Manual Page 13 Section One Introduction to AVR Development Tools 7 With the program uploaded into the microcontroller unplug the TekBot from the computer and turn it on Observe the behavior the TekBot should be operating in the similar BumpBot fashion Demonstrate your TekBot to your TA TA Initials Theory of Operation for Lab 1 AVR Assembly Code Initializes key components of the ATmega128 Starts the TekBot moving forward Polls the whiskers for input If right whisker is hit o Backs up for a second o Turns left for a second o Continues Forward If left whisker is hit o Backs up for a second o Turns right for a second o Continues Forward STUDY QUESTIONS REPORT For this lab there will be no write up This lab 1s simply for familiarization and introduction to AVR Studio and PonyProg You will automatically get 20 points for this lab for obtaining the TA s initials as indicated For all other labs you will write up short sum
44. re to be submitted on paper not by email For this lab no prelab is required PROCEDURE Wiring Your TekBot 1 The first step is to look at the wiring diagrams available on the TekBots webpage To make the wires for connecting your TekBot boards together you will need to use the ribbon cable that came with your kit with male headers soldered to the ends and a bit of heat shrink tubing on the connections There 1s a short tutorial on the web that explains this process 1n detail 2 Because we are working with a modular programmable AVR microcontroller board you can connect the whisker inputs and motor controller outputs to any pins on any port on the board But for the demo lab to work properly these cables need to be connected in a certain way This configuration should be used throughout the course It uses the pin s alternative functions rather than its primary functions As the course progresses you will learn what both of these functions are Table 1 next page shows the proper pin connections 2009 Oregon State University ECE375 Manual Page 11 Section One Introduction to AVR Development Tools Right Whisker External Interrupt 4 Left Whisker External Interrupt 5 Right Motor Enable 4 PWM Output for Timer Counter0 ee Direction Timer Counter Timer Counter m Timer Counter2 Table 1 TekBots Connections to AVR Microcontroller Board 3 When you have completed the wiring be sure to ask your TA to look 1t o
45. rform arithmetic operations on numbers that are larger than 8 bits To do this you should understand the different arithmetic operations supported by the AVR Architecture List and describe all the different forms of ADD SUB and MUL i e ADC SUBI MULF etc e Write pseudo code that describes a function that will take two 16 bit numbers in data memory addresses 0110 0111 and 0121 0122 and add them together The function will then store the resulting 16 bit number at the address 0100 0101 Hint The upper address in the high byte of the number and don t forget about the carry in bit PROCEDURE Arithmetic calculations like addition and subtraction are fundamental operations in many computer programs Most programming languages support several different data types that can be used to perform arithmetic calculations The ATmegal28 uses 8 bit registers and has several different instructions to perform basic arithmetic operations on 8 bit operands Examples of instructions that add or subtract 8 bit registers are ADD R0 RI R0 RO RI ADC RO RI RO RO RI Carry Bit SUB RO R1 RO RO RI If we are required to manipulate data with 16 or more bits with AVR instructions then we need to perform intermediate steps to manipulate 8 bit registers to produce the correct result The following figure demonstrates the addition of two 16 bit numbers One of the 16 bit numbers 1s located in registers RO and R1 and the other number 1s
46. rning away and resuming forward motion Demonstrate this to your TA and be turn in a copy of you modified assembler program 2009 Oregon State University ECE375 Manual Page 15 Section Two C Assembler Machine Code TekBot SECTION TWO c ASSEMBLER MACHINE CODE TEKBOT 2009 Oregon State University ECE375 Manual Page 17 Section Two C Assembler Machine Code TekBot SECTION OVERVIEW Complete the following objectives e Look at a sample C program e Write a sample C program for the AVR microcontroller e Compile the code using the CodeVision IDE and compiler e Download this code to your AVR board and verify its function PRELAB Remember no late prelabs will be accepted Write a pseudo code program for making your TekBot move the way it did in Lab 1 Your robot should detect objects using its whiskers reverse and turn away from the object PROCEDURE Looking at C Code and the CodeVision Studio 1 Download the sample code available on the web page This is simple C code that is well commented and ready to compile All code that you produce should be as well commented as this code Save this code where you can find it in your UNIX file share network drive commonly called drive Z There are two different programs on the web be sure to get the correct one for your TekBot 2009 Oregon State University ECE375 Manual Page 18 Section Two C Assembler Machine Code
47. s and ability to use them e Learn how to use the Universal Synchronous Asynchronous Receive Transmit USART on the megal28 PRELAB 1 In this project you are going to be given a set of functions that you need to have your toy perform Find another toy that uses a microcontroller and describe the functions that it performs For each function explain the interesting code mega128 specific setup registers ext mechanics and or electronics needed PROCEDURE Problem You work for TekToy Co a global subsidiary of TekBots International You are working on designing a new toy for the remotely controlled line of products You want to build a simple robot that can be controlled using IR You want to use IR because it is cheaper and requires less design than an equivalent RF system Your first step 1s to build a proof of concept model so that you can sell the idea to management You dig through your desk and come across your TekBots base from when you were in school and a couple of AVR microcontroller boards for the TekBot Since you know how to use these parts you decide to build your proof of concept model with them Specifications Below 1s a list of things to consider while creating your design 1 You would like to have multiple robots running at the same time so you need to somehow make a robot respond only to its own remote control You decide to do this by assigning each robot a distinct address The remote should transmit t
48. t Study Questions 1 This lab required you to begin using new tools for compiling and downloading code to your AVR enabled TekBot using the C language Explain why it 1s beneficial to write code in a language that can be cross compiled Also explain some of the problems of writing in this way 2 Your program does essentially the same thing as the assembly program you downloaded for Lab 1 Compare the size of the output bin files and explain the differences in size between them CHALLENGE 1 Modify your TekBot so it can move objects across a table top Your TekBot needs to push objects that it touches a short distance An example of how your TekBot should work 1s TekBot hits object TekBot continues forwards for a short period of time TekBot backs up slightly TekBot turns slightly towards the object TekBot repeats steps a through d o Ch Er S There are several ways to approach this problem but you must accomplish it by revising your firmware change the C program or rewrite it To get credit for this challenge you must demonstrate the operation of your TekBot to your TA and submit a copy of the code used 2009 Oregon State University ECE375 Manual Page 23 Section Three Data Manipulation and the LCD Display SECTION THREE DATA MANIPULATION AND THE LCD DISPLAY 2009 Oregon State University ECE375 Manual Page 25 Section Three Data Manipulation and the LCD Display SECTION OVERVIEW Complete
49. ta usually FF The movement within data memory is accomplished with the different variations of Load and Store commands There are two main addressing modes to move the data direct addressing and indirect addressing Direct addressing is best when you want to move data to and from a single memory location like an extended I O register Indirect addressing uses the X Y and Z pointers and is useful for moving data to multiple areas of data memory For example using indirect addressing in conjunction with a while loop you could move blocks of data around in memory See the AVR Starters Guide for more information on pointers and indirect addressing The following is some pseudo code you can use to properly read a bunch of data from program memory Z lt Beginning Address of string in Program Memory Y lt Beginning Address in Data Memory for string do mpr lt ProgMem Z Z DataMem Y lt mpr Y while Z End Address of string in Prog Memory Writing Your Name You are to write your name on the first line of the LCD Display and a simple phrase such as Hello World on the second line of the LCD Display In order to accomplish this you must have you two strings in program memory using the DB directive Then read the data from program memory and store it into the appropriate spots in data memory that are used for Line 1 and Line 2 Then make a simple call to the correct function to display the two lines on the LCD dis
50. the following objectives Understand the basics of data manipulation Initialize a program e stack registers LCD etc Use indirect addressing with the X Y and Z pointers Read data from program memory Move data around in data memory Setup and successfully call functions and subroutines PRELAB The answers to the prelab questions can be found in the AVR Starters Guide and the AVR Instruction Set What is the stack pointer How is the stack pointer used and how do you initialize it Provide pseudo code NOT actual assembly code that illustrates how to initialize the stack pointer What does the AVR instruction LPM do and how do you use it Provide pseudo code that shows how to use the LPM instruction Look at the definition file ml 28def inc What is contained within this definition file What are the benefits of using this definition file How would you include it into your AVR Assembly program PROCEDURE Introduction For this lab you will learn to use the LCD Display on the AVR microcontroller board In order to use the LCD display you will need to learn to properly initialize your program You will also learn how to move data from your program memory into your data memory This data is what will be displayed on the LCD display To help you along the way a project skeleton file will be provided This file will contain some code and comments directing you to what code to write and where The file will also give you a basis for writ
51. to the numerically equivalent ASCII string 1 e 186 gt 186 For this function three registers are needed mpr Contains the 8 bit binary number to be converted X Pointer Contains the start address to AVR data memory when the ASCII string will be stored count Will contain the number of characters that are written once the function has completed This function 1s useful for printing a number that you don t always know what the value will be 1 e not a constant value such as a counter When using this function be aware that up to three characters could be written For example 1f you had the value 138 in the mpr and the address of 0112 in the X pointer you would get the following after calling this function DataMem 0112 1 DataMem 0113 3 DataMem 0114 8 count 3 Here 1s an example of calling the function described above Idi mpr 138 mpr lt 138 Idi XL low 0112 X lt 0112 Idi XH high 0112 X 0112 reall Bin2ASCII Call Bin2ASCII There are many other functions within the LCD driver but they are support functions for those described above and should not be called individually Modifying any function within the driver 1s not recommended as it could damage the performance of the function but feel free to play around if you like With that said 1f you do modify the driver or add another function that improves the performance let your TA know what you did and ho
52. ver before you turn the power on If you have wired things incorrectly especially if you have switched Vcc and ground you WILL destroy parts of your TekBot Please have the TA initial in the space below that you have shown your TekBot to them TA Initials Looking at some AVR Source Code 1 Download the sample code available on the webpage This is a simple AVR source code that will run your TekBot In the simple BumpBot fashion All code that you produce should be as well commented as this sample code Save this code where you can find it in your UNIX file share network drive commonly called drive Z 2 AVRStudiod is the Integrated Development Environment IDE that you will be using to develop your AVR assembly code throughout the remainder of the course with the exception of Lab 2 AVRStudio4 is a powerful IDE created by Atmel for their line of AVR microcontrollers You will be using it to write assembly programs for your AVR microcontroller board that uses an ATmegal28 microcontroller Section 2 of the AVR Starter Guide which can be found on the TekBots website contains a good overview on how to use the program as well as some step by step tutorials Briefly read through this section to gain a basic understanding of the IDE Optional If the IDE 1s not already installed on the computer or if you are doing this lab from home read through and follow the steps in Section 2 1 1 of the AVR Starters Guide to download and install AVRStudio4 on y
53. w it works or why it 1s better and we might add it to future versions of the driver Data Manipulation To be able to move data from one memory to another you first must understand the memory The ATmegal28 is an 8 bit AVR architecture This means all data is moved around 8 bits or 1 byte at a time thus all register and data memory are 8 bit wide 2009 Oregon State University ECE375 Manual Page 29 Section Three Data Manipulation and the LCD Display However the AVR Op Code is 16 or 32 bits and for efficiency reasons the program memory 1s 16 bits or 2 bytes wide This means that when you read from the program memory you will have to read 2 bytes for every address space 1n the program memory When writing a program it is often necessary to include data directly into program memory instead of entering it into the data memory each a time a simulation is run The DB Data Byte directive allows data to be written directly to the program memory during compilation For example the following code demonstrates how to create data in program space DATA DB 05 F4 When the program is compiled the hex data 0x05 and OxF4 will be located in the program memory at the address specified by the label DATA To read this data use the LPM Load Program Memory instruction Note Since the program memory is 16 bits wide the data after the DB directive needs to be in multiples of 16 bits Otherwise the compiler will insert an extra byte of da
54. you can see the shift and add technique can be easily created with a simple for loop that loops a specific amount of times depending on the size of the data for the case above we used 4 bit numbers so we looped 4 times In the loop there is a simple rotate left and an add depending on the carry bit This technique can be easily used for any sized number with minimal effort and is used internally for multiplications with most micro architectures 2009 Oregon State University ECE375 Manual Page 39 Section Five Simple Interrupts SECTION FIVE SIMPLE INTERRUPTS 2009 Oregon State University ECE375 Manual Page 41 Section Five Simple Interrupts SECTION OVERVIEW e Understand how and when interrupts can be used e Demonstrate the use of simple interrupts e Explore how to configure interrupts on a microcontroller PRELAB Be sure to have completed these prelab questions before your lab They will help you to perform the tasks 1n this lab and hopefully give you more time to experiment 1 In computing there are traditionally two ways for a microprocessor to listen to other devices and communicate These two methods are commonly called polling and interrupts A large amount of information about these two methods exists Please describe what each of them is and a few examples where you would choose one over the other 2 What 1s the function for each bit in the following registers in the ATMegal28 EICRA EICRB and EIMS
Download Pdf Manuals
Related Search
Related Contents
Black & Decker 90068347 Instruction Manual Samsung Galaxy J7 Hướng dẫn sử dụng Les Relations publiques du Rotary mode d`emploi Samsung 27"-os minimál stílusú LED Monitor fém állvánnyal como realizar la localizacion y reparacion de averias de los FinePix S8000fd Mode d`emploi Philips DLM4347 Copyright © All rights reserved.
Failed to retrieve file