Home

Lab Manual

image

Contents

1. e DE2_PIO_GREENLED9 BASE for the nine LEDGs LEDGS is MSB bit 8 and LEDGO LSB bit 0 3most significant bit least significant bit 2 5 1 completed O 2 5 2 completed O 2 5 3 completed O e DE2_PIO_KEYS4_BASE for the four buttons KEY3 is MSB bit 3 and KEYO LSB bit 0 e DE2_PIO_HEX_LOW28_BASE for the seven segment displays The seven segment display has four digits The leftmost digit is controlled by the seven most significant bits HEX3 bits 27 through 21 the left middle digit is controlled by the next seven bits HEX2 bits 20 through 14 then fol lows the right middle digit HEX1 bits 13 through 7 and the rightmost digit by the least significant bits HEXO bits 6 through 0 Update the main loop in your program and include a macro that will cause the time value to be written in binary form on the 16 red LEDs LEDR15 through LEDRO Use the natural BCD encoding with four groups of four bits each 2 5 2 The bcd2sevenSeg function Write a C function bcd2sevenSeg with the following prototype int bcd2seven int inval The purpose of the function is to convert 4 bit binary code to 7 bit seven segment code The four least significant bits of the input value are to be con verted into a 7 bit value such that this value can be sent directly to a seven segment display to produce the appropriate digit Recommended digit pat terns are shown in the figure below To light up a segment of a seven segment disp
2. 26 will return the value 29 and so on Update your program from the previous task so that prime numbers are calculated by the background program loop and printed on the console win dow at the same time as time is shown on the HEX displays and LEDRs Make sure that the behavior can still be manipulated by the buttons as spec ified above The function nextPrime will work on the DE2 board at the lab session To be able to run the nextPrime function in the NiosII Instruction Set Simulator you need to 1 right click on the project folder 2 choose System Library Properties 3 check the box Emulate multiply and divide instructions 4 click Apply If you forget to do this the simulator may give an error message like Break instruction called without debugger attached 2 10 completed 2 11 Questions Study the configuration used for the DE2 board which you find in the system h file Answer the following questions 1 Which Nios processor is used in this configuration Give the number of stages in the processor pipeline 2 The configuration contains a number of different memories Order these memories after typical access times and give the size of each memory 3 Which I O devices and timer devices are used in the preperation tasks of this lab Give their address spaces and IRQ levels 2 11 completed 3 Laboratory Tasks to be performed at the lab session 3 1 Cand Assembler Connect the DE2 board with a USB
3. cable to your laptop Program the FPGA with the provided sof file and download your program from Task 2 4 onto the board Answer all questions the teacher might ask task completed signed by teacher 0 eee e eee eee eee ee n 3 2 Parallel I O Output Run your program from Task 2 5 on the DE2 board and demonstrate how you output the time value to the LEDs and the seven segment display Answer all questions the teacher might ask task completed signed by teacher 0 cece eee cece eee eee ee 3 3 Parallel I O Input Run your program from Task 2 6 on the DE2 board and demonstrate the func tion of the buttons Answer all questions the teacher might ask task completed signed by teacher 0 cece cece cece ences 3 4 Interrupt Run your program from Task 2 8 on the DE2 board and explain how you im plemented the button input Answer all questions the teacher might ask task completed signed by teacher 0 cece eee eee ences 3 5 Hardware Timer Run your program from Task 2 9 and 2 10 on the DE2 board Answer all ques tions the teacher might ask task completed signed by teacher 0 cece cece eee e eee ee 3 6 Questions Present your answers to the questions from Task 2 11 to the teacher task completed signed by teacher 0 cece cece eee eee eens 3 7 Surprise Task To show that you understood the lab s cont
4. found PRIME_TRUE If the loop ended normally we found a prime return perhapsprime Return the prime we found return perhapsprime When the loop ends perhapsprime is a real prime 13
5. 1 Each time you push the button KEY1 the time shall stop counting KEY2 Each time you push the button KEY2 the time value presented shall be incremented by one second KEY3 Each time you push the button KEY3 the time value shall be reset to 00 00 Draw a flow chart to describe the behavior of the pollkey function Add a call to a pollkey function in your C coded main loop Helpful hints Write the C code of the function pollkey in the same file as the timeloc variable and the main program This makes it possible for the pollkey function to reference the timeloc variable You can use a variable RUN to indicate if the counting is ON or OFF and use this variable to decide if tick is going to be called or not 2 7 Response Time If you run the program above you will find that the response time when you push a button might be disturbingly long Probably also some button pushes are lost because the pollkey function is called only once per second Modify your program so that the pollkey function is called once per mil lisecond Make sure that the time variable timeloc still will be incremented only once per second 2 8 Interrupt using HAL functions Refresh your memory concerning how to use interrupts in software and hard ware especially in the Nios II CPU Find out which HAL functions to use to initiate and register interrupts in Nios II Information on HAL functions can be found in Software Developers Handbook Altc chapter 8 E
6. Gp fo B amp KTH VETENSKAP JO OCH KONST A ae KTH Information and Communication Technology IL2206 Embedded Systems Laboratory 1 Input Output and Interrupts in Nios II Systems August 27 2010 1 Objectives This laboratory will help you to e get used to the hardware and software of the laboratory environment e deepen your understanding of how C and Assembler functions interact e deepen your understanding of I O handling with polling and interrupt e access embedded peripherals by means of C Macros and the HAL Sys tem Library e get used to the Altera documentation 2 Preparation Tasks to be performed as preparation before the lab session Read this laboratory manual in detail before you start with preparation tasks reading completed Complete the preparation tasks before your lab session in order to be al lowed to start the laboratory exercises Hardware Abstraction Layer Please claim your seat in time After 15 minutes laboratory teachers may re allocate unused seats to other students including students who have been unable to book a seat For admission all preparatory tasks must be finished and some tasks are strictly required for admission The laboratory will be conducted by groups of two students However each student has to understand the developed source code and the prepara tion tasks The course assistants will check that students are well prepared When preparing for the labora
7. II IDE Valuable information can also be found in the lecture notes that can be found on the course homepage 2 4 Cand Assembler In this lab you will develop a program that will display a time value with dif ferent output devices and read from input devices for manipulation You will start with simply printing out the value into a terminal window Create a new project called 1ab1 in the Nios II IDE The configuration file ptf is available in a zipped archive from the course homepage Add also the source files from the archive c and s to your new project You will find the following source files puttime c contains the C function void puttime int timeloc that reads the time value stored at the memory address given by the pointer pa rameter timeloc and prints it to a terminal window The printout is in the format 42 33 tick c contains the C function void tick int timeloc that increments the time value stored at memory address given by the pointer parameter timeloc by one delay_asm s contains a Nios II assembly subroutine which delays program execution by the number of milliseconds given by a parameter hexasc_asm s contains a stub for a Nios II assembler subroutine which you need to implement as described below This subroutine is called from the C code within the function puttime labl c contains the main loop of the program 2 3 completed O Note that you might have to answer questions about the source code durin
8. ents you will get a surprise task that you need to finish during the lab session You cannot complete it at home If you do not finish it during the session you will get a new task in the next session surprise task ___ given by teacher in session task completed signed by teacher 0 cece eee cece cece eens 10 4 Examination In order to pass the laboratory the student must e have completed the preparation tasks of Section 2 before the lab session e have completed the laboratory tasks of Section 3 e have answered the questions of Section 2 11 THE StHUGENT S shits ocd Pe SOS Se BSS Bate SA A a BE eS SP ose has have successfully completed laboratory 1 signed by teacher jfe seni uhri e ea emia vids cad ea E EAS References Alta Altera Embedded Peripherals IP User Guide Version UG 01085 10 0 0 Altb Altera Nios IT Processor Reference Handbook Version NII5V1 10 0 Altc Altera Nios II Software Developers Handbook Version NII5V2 10 0 Altd Introduction to the Altera Nios II Soft Processor DE2 Altera DE2 Development and Education Board User Manual Version 1 4 11 A nextPrime C code In the main loop call nextPrime as follows next nextPrime next Produce a new prime printf nNext Prime is d next The nextPrime function itself x NextPrime Return the first prime number larger than the integer given as a
9. g the lab session You need to be able to explain what every function does Take a look at the file delay_asm se The subroutine delay has one input parameter in r4 that determines how many milliseconds the subroutine will wait before returning to its caller Draw a flow diagram that visualizes how the subroutine delay works In order to achieve a 1 millisecond delay in the inner loop you need to adjust the parameter delaycount which is defined at the top of the file and currently set to 0 To calculate the delay time use the fact that the processor runs at 50 MHz and assume that it usually can execute one instruction per cycle Also assume that the simulator has a slowdown factor of 300 to simu late one second of Nios II runtime will take 5 minutes of real time This will give a reasonable starting value for the delay routine parameter Also calcu late the parameter for running it on the board as you will need it during the lab session Draw a flow chart for a subroutine to convert a 4 bit hexadecimal value to the corresponding 7 bit ASCII code See the full specification for hexasc below Examples binary 0010 hexadecimal digit 2 is converted to 011 0010 ASCII code for 2 binary 1011 hexadecimal digit B is converted to 100 0010 ASCII code for B Implement the subroutine starting from the skeleton provided within the file hexasc_asm s Make sure that your subroutine is commented so that the teacher can follow your
10. lay the corresponding bit should be zero 0 A one 1 will shut the seg ment off bit index 2 5 3 The puthex function Write a C function puthex with the following prototype void puthex int inval The purpose of the function is to display the current time on the seven segment digits HEX3 through HEXO The puthex function should call bcd2sevenSeg Add a call to the puthex function in your C coded main loop The call to puthex function will be tested on the lab occasion not in the simulator 2 6 Polling Recall which macro to use when you want to read values from the buttons KEY3 to KEYO 5BCD stands for binary coded decimal four bits are used for one digit e g 87 is represented as 1000 0111 Create a new project called 1ab1_I0 and copy all files from the previous project to this new project Write a C function pollkey with the following prototype void pollkey The function shall poll the keys and affect the behaviour of the time presen tation Each time you push a button the behavior must change As a simplification you may assume that a button is always released before another or the same button is pressed and that two or more buttons are never pressed at the same time It is out of the scope of this lab to take care of all possibilities but you are of course allowed to do it KEYO Each time you push the button KEYO the time shall start counting KEY
11. le to make use of it Often the given references provide example code for instance how to program the timer to generate alarm and how to program the input keys to generate interrupts The main focus of the reading should be on the following e Introduction to the Altera Nios II Soft Processor Altd Read this thoroughly it is a very good introduction see instructions on the course homepage e Nios II Processor Architecture and Programming Model Chapters 2 and 3 of Altb Nios II Application Binary Interface and Instruction Set Reference Chapters 7 and 8 of Altb Especially important are parameter passing and size of datatypes The reference Chapter 8 provides detailed information about all in structions Hardware Abstraction Layer and HAL system library Chapters 2 5 6 8 and 14 of Altc Here you can find out which macros to use for reading and writing reg isters in I O circuits PIO and Timer You can also find information on how to use HAL functions to initiate and use interrupts Nios II PIO Core and Interval Timer Core Chapters 9 and 27 of Alta Especially I O register organization and use in PIO and Timer Details of the Cyclone II FPGA board that is used in this laboratory is de scribed in the DE2 Development and Education Board User Manual DE2 You should also have a look on the project templates that are available when you create a new application in the Nios
12. line of thought and understand your code Specification Name The subroutine must be called hexasc Input parameters Only one in register r4 The 4 least significant bits in reg ister r4 specify a number from 0 through 15 The values of all other bits in the input must be ignored Return value Only one returned in register r2 The 7 least significant bits in register r2 must be an ASCII code as described below All other bits in the output must be zero Required action Input values 0 through 9 must be converted to the ASCII codes for the digits 0 through 9 respectively Input values 10 through 15 must be converted to the ASCII codes for the letters A through P respectively Side effects The values in registers r2 through r15 may be changed All other registers must have unchanged values when the subroutine returns You MUST follow the specification Helpful hints Use registers r8 through r15 for any temporary values within your sub routine You can find the ASCII chart on many websites e g on Wikipedia Edit the main program such that the time value is incremented and printed out once every second Use the Nios II Instruction Set Simulator to run your program Using the simulator tune your delay subroutine to an accuracy better than 10 no more than 6 seconds of error in one minute of simula tion Verify that the time is printed once per second 2 5 Parallel I O 2 5 1 PIO macros In order
13. parameter The integer must be positive define PRIME_FALSE 0 Constant to help readability define PRIME_TRUE 1 Constant to help readability int nextPrime int inval int perhapsprime Holds a tentative prime while we check it int testfactor Holds various factors for which we test perhapsprime int found Flag false until we find a prime if inval lt 3 Initial sanity check of parameter if inval lt 0 return 1 Return 1 for zero or negative input if inval 1 return 2 Easy special case if inval 2 return 3 Easy special case else Testing an even number for primeness is pointless since all even numbers are divisible by 2 Therefore we make sure that perhapsprime is larger than the parameter and odd perhapsprime inval 1 1 While prime not found loop for found PRIME_FALSE found PRIME_TRUE perhapsprime 2 Check factors from 3 up to perhapsprime 2 for testfactor 3 testfactor lt perhapsprime gt gt 1 testfactor 1 found PRIME_TRUE Assume we will find a prime if perhapsprime testfactor 0 If testfactor divides perhapsprime found PRIME_FALSE then perhapsprime was non prime goto check_next_prime Break the inner loop go test a new perhapsprime 12 check_next_prime This label is used to break the inner loop if
14. to access the hardware such as I O ports on the DE2 board by soft ware Altera provides macros that hide the memory mapped low level in terface to the device Information about these macros can be found in Soft ware Developers Handbook Altc Chapter 7 Developing Device Drivers for the Hardware Abstraction Layer 2 4 completed O In order to write to a parallel I O port use the macro IOWR_ALTERA_AVALON_PIO_DATA Example The command IOWR_ALTERA_AVALON_PIO_DATA DE2_PIO_REDLED18_BASE 0x3ffff writes 1s to all 18 red leds and thus turns on all LEDRs In order to read from a parallel I O port use the macro IORD_ALTERA_AVALON_PIO_DATA Example The command IORD_ALTERA_AVALON_PIO_DATA DE2_PIO_KEYS4_BASE re turns state of the buttons as an integer bit pattern a 0 means that the corresponding button is pressed Symbolic names of I O ports and I O registers can be found in the system h file This file is generated when the system library is built and compiled You can find the system h file in your projects It is situated in the system library in folder Debug system_description gt system h You have to include some files in your program if you are using macros and or symbolic names of IO ports for instance include system h include altera_avalon_pio_regs h Symbolic names used in our CPU configuration are e DE2_PIO_REDLED18_BASE for the eighteen LEDRs LEDR17 is MSB bit 17 and LEDRO LSB bit 0
15. tory work Whenever you have completed a preparation task of the laboratory mark the preparation task as completed by putting a cross into the corresponding cir cle At the lab session Whenever you have completed a laboratory task show it to the teacher and answer all questions about your program The teacher will mark the labo ratory task as completed by writing a signature on the corresponding dotted line 2 1 Lab Access and Account You will perform the lab on your own notebook computer After you have been registered for the course in the KTH study system Ladok make sure that you can log on to the KTH wireless network There will be no spare computers in the course laboratory 2 2 Setting up the Lab Environment In order to perform the lab a virtual machine with all the needed software is provided Install the virtual machine on your computer and follow the intro ductory tutorial at http www ict kth se courses 1IS1200 2009 2010 nios2setup idefirst html to get comfortable with the development environment You also need to download the source and configuration files for this lab which are available in a zip file from the course homepage 2 3 Literature A lot of information that is needed to solve the preparation tasks can be found in the Altera documentation on Nios II Altb Altc Alta which is available on the course homepage The student is encouraged to get a good overview of the Altera documentation and to be ab
16. ue shall be set to 00 00 KEY3 Each time you push the button KEY3 the the time value shall be set to 59 57 2 9 Using a Hardware Timer Most processors offer possibilities to use hardware timer circuits As the timer circuits are clocked by a crystal oscillator the accuracy is in the order of 1 per million or even better In the Nios II processor several timers are available Update your program to use a timer instead of using a programmed delay Information on timers with the Nios II can be found in the Software Develop ers Handbook Altc Section Using Timer Devices of Chapter 6 Develop ing Programs Using the Hardware Abstraction Layer Create a new project called lab1_timer and copy all files from the previous project to the new project Modify the new project to use HAL functions to order alarm once per second to print the current time value on terminal and hex display Keep the functionality of the buttons from the previous exercise You must write the alarm handler function and use the HAL function to initiate the system to use it 2 10 Introducing Valuable Foreground Work In the end of this lab manual you will find the code for the function nextPrime Its prototype is int nextPrime int inval This function returns the smallest prime number greater than the parameter inval Calling nextPrime with a value of 17 will for example return the value 19 since this is the next prime Calling it with the value
17. xception Handling In the previous program most of the CPU time is spent polling the keys to detect changes Most of the CPU time no changes occur and valuable CPU time is wasted It might be smarter to let the CPU work with something useful instead of waiting for buttons to change 2 6 completed O 2 7 completed O 2 8 completed O 2 9 completed O The buttons have hardware support for interrupts Information on this can be found in the Embedded Peripherals IP User Guide Alta chapter 9 PIO Core Create a new project called lab1_int and copy all files from the previous project to the new project Modify the program in your new project to use interrupts from the keys instead of polling This means that you must write an interrupt service rou tine for the button interrupt name the function key_InterruptHandler and that you must initialize the system so that interrupts from the button PIO will cause the key_InterruptHandler function to be executed You must also enable interrupts from the button PIO by writing appropriate value s to the appropriate register s in the button PIO using the appropriate macro s The behavior caused by the buttons shall be changed compared to the previ ous exercise KEYO The button KEYO shall toggle between start and stop counting the time KEY1 Each time you push the button KEY1 the time value shall be incre mented by one KEY2 Each time you push the button KEY2 the the time val

Download Pdf Manuals

image

Related Search

Related Contents

8 = baignade final  LOADING THE MASK AND THE SAMPLE  1769-RN016 - Rockwell Automation  Palsonic DVD2030 DVD Player User Manual  YAMAHA WR250X 08-11  アース トステッ プガイド ご使用にナ よる別に、 必ずお読みください  Tejaluz Ficha técnica 2014 mayo  12.03.2009 39063 Les 106 printemps de Pierre - Villars-sur  Eaton Personal Solution-Pac. Point-To-Point Power Management Software + RS232 cable bundle  Manuale Installazione Manutenzione Italiano CCT R410A ON OFF  

Copyright © All rights reserved.
Failed to retrieve file