ex1 - upc universitat politècnica de...

20
EX5: Setting up applications with microcontrollers EX 5 DIGITAL CIRCUITS AND SYSTEMS Setting up applications with microcontrollers 1.1 Cooperative group TEAM NUMBER: ___________ DUE DATE: ________________ 1 st review due date: ________________ STUDY TIME: Study time (in hours) Group work Classroom and laboratory sessions Sessions out of classroom Individu al Student 1 Student 2 Student 3 STATEMENT: My signature below indicates that I have (1) made equitable contribution to EX 5 as a member of the group, (2) read and fully agree with the contents (i.e., results, conclusions, analyses, simulations) of this document, and (3) acknowledged by name anyone outside this group who assisted this learning team or any individual member in the completion of this document. Today’s date: __________________ Active members Roles: (reporter, simulator, etc.) (1) ________________________________________ _______________ 1

Upload: others

Post on 24-Mar-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EX5: Setting up applications with microcontrollers

EX 5 DIGITAL CIRCUITS AND SYSTEMS

Setting up applications with microcontrollers

1.1 Cooperative groupTEAM NUMBER: ___________

DUE DATE: ________________ 1st review due date: ________________

STUDY TIME:

Study time

(in hours)

Group work Classroom and laboratory sessions

Sessions out of classroom

Individual Student 1

Student 2

Student 3

STATEMENT:

My signature below indicates that I have (1) made equitable contribution to EX 5 as a member of the group, (2) read and fully agree with the contents (i.e., results, conclusions, analyses, simulations) of this document, and (3) acknowledged by name anyone outside this group who assisted this learning team or any individual member in the completion of this document.

Today’s date: __________________

Active members Roles: (reporter, simulator, etc.)

(1) ________________________________________ _______________

(2) _________________________________________ _______________

(3) _________________________________________ _______________

Acknowledgement of individual(s) who assisted this group in completing this document:

1

Page 2: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EPSC – CSD: Digital Circuits and Systems

(1) _______________________

(2) _______________________

1.2 Abstract Explain here the most significant developments, results or conclusions about the exercise. Use the remaining space in this sheet (200 words maximum).

(This section is mandatory. You must complete it in order to get a mark.)

2

Page 3: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EX5: Setting up applications with microcontrollers

CONTENT

Setting up applications with microcontrollers.............................................................................................1

1.1 Cooperative group.....................................................................................................................................1

1.2 Abstract.....................................................................................................................................................1

1.3 Description................................................................................................................................................3

1.4 Topics........................................................................................................................................................3

1.5 Design flow and integrated development environment............................................................................4

1.5.1 Installing MPLAB and the Microchip HITECH C Lite compiler.....................................................4

1.6 Visiting microcontroller sites....................................................................................................................5

1.7 PIC16F87X microcontrollers....................................................................................................................5

1.7.1 Architecture.......................................................................................................................................5

1.7.2 PIC assembler: RISC instruction set.................................................................................................6

1.8 Analysis of a FSM-like application...........................................................................................................7

1.8.1 Generating the CLK signal for the FSM...........................................................................................8

1.8.2 Hands on the design a 5 second timer..............................................................................................8

1.9 Problem solution (títol 2)..........................................................................................................................9

1.9.1 Part 1 (títol 3)....................................................................................................................................9

1.10 References...............................................................................................................................................10

1.11 Study plan to solve the exercise..............................................................................................................10

1.12 Topics and activities checklist................................................................................................................11

1.13 Grading grid............................................................................................................................................11

1.14 Questions in solving EX 5.......................................................................................................................12

3

Page 4: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EPSC – CSD: Digital Circuits and Systems

1.3 DescriptionThis exercise will establish the basics for working with microcontrollers for the remaining of the term. Instead of continuing Chapter III trying, for instance, to design other more complex subsystems or even our own microprocessor like many books in VHDL does, we are going to buy a commercial one and program it using C. Programming in assembler, which is a language much more hardware-dependent, taking into account the amount of time left in the course, would be far more difficult than doing it in C. If it is of your interest, you can learn it later on in an autonomous way once achieved the goals of this subject.

Therefore, in this Chapter IV, the idea is to build applications replacing the “hardware programming” of FPGA and PLD by “software programming” a microcontroller. The concept of a microcontroller consists of a complete computer architecture into a single chip: microprocessor, data and program memory and input/output peripherals.

There are a wide range of commercial microcontrollers to choose from in order to learn the basics and start applying them to build simple applications. We have decided to pick up the PIC16F family of flash microcontrollers from Microchip, one of the leading vendors. However, everything to be designed can be easily migrated to the PIC18F technology.

We will proceed in five steps: (1) some theory on the PIC16F877A microcontroller architecture; (2) installing the integrated programming environment MPLAB from Microchip to compile, debug and program the chips; (3) the prototyping hardware and the way to run simulations of analogue and digital circuits which include microcontrollers; (4) a known framework for developing projects based on our FSM style using the Timer0 to emulate the CLK signal using interrupts; (5) a kick off exercise that will consist of the 5 seconds timer (the same idea from EX4).

1.4 Topics The following topics have been listed from the course’s specific and cross-curricular learning objectives 1: #13, #14. After studying Chapter 4 and successfully completing all the assignments in this task, you will be able to:

------------- Part 1: The theory -------------

1. Draw the typical design flow for a microcontroller-based application: concept, hardware, program flow diagrams, coding in assembler or C, Proteus VSM simulation, prototype using evaluation board, verification, in-circuit debugging or microcontroller emulation, PCB design and production.

2. Identify and list commercial microcontrollers and their manufacturers.

3. Search books and the Internet to analyse information about microcontroller chips and their applications (web portals or electronic magazines on the subject of microcontrollers).

4. Explain the basics of a microcontroller-based embedded system. Architecture of a computer (CPU, memory, peripherals). Harvard architecture of an 8-bit microcontroller like the PIC16F877A. Explain why a microprocessor (CPU) can be considered a programmable dedicated processor from Chapter III. Explain the roles of the EEPROM program memory and the RAM memory.

1 http://epsc.upc.edu/projectes/ed/CSD/units/Guia_docent_E1_v2.pdf

4

Page 5: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EX5: Setting up applications with microcontrollers

5. Explain the basic concepts of the C compiler. From C language to assembler. Disassembling. Advantages and drawbacks of C language and assembler.

6. Analyse simple applications in assembler or C and deduce the program flowchart from the written code.

------------- Part 2: Analysis of an application designed in our FSM style -------------

7. Analyse the Heads or Tails game, an example on programming in FSM style:

a. Plan a microcontroller application as if it were a simple FSM or a dedicated processor from Chapters II and III respectively. This is:

i. General schematic or top block diagram.

ii. Internal architecture using components and signals (and control unit + datapath if it is the case)

iii. State diagram for the FSM

b. Explain the role of Timer0 as the FSM CLK generator.

c. Draw a program flowchart (which is like a ASM chart) for every function: interrupt service routine (state register), output logic (CC2), and future state logic (CC1).

d. Convert the program flowchart in C (or in assembler, if it were the case).

e. Generate the “*.hex” and “*.cof” files compiling the code using MPLAB and HITECH software.

f. Simulate and debug the application using the virtual PICDEM 2 Plus board.

g. Download the configuration code (*.hex) to the training board, using for example the In Circuit Debugger/programmer ICD2, and measure and characterise the project using laboratory instrumentation.

8. Explain the way to program I/O ports.

9. Explain the block diagram (at RTL level) and the way to program the Timer0.

------------- Part 3: Your own design -------------

10. Follow the above design flow to obtain a 5-seconds timer using C, MPLAB, Proteus-VSM, the PIC16F877A, and the PICDEM 2 plus board.

5

Page 6: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EPSC – CSD: Digital Circuits and Systems

Fig. 1 Some concepts included in this exercise.

1.5 Design flow and integrated development environment1.5.1 Installing MPLAB and the Microchip HITECH C Lite compiler

a) Once having downloaded and installed the latest MPLAB software version from the Microchip web page and the HITECH C Lite compiler, run a sample project from our web page, for example the square wave generator. Examine the circuit schematic and deduce and draw its flow diagram. Here you are in Fig. 2 to typical microcontroller-based design flow.

6

Page 7: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EX5: Setting up applications with microcontrollers

Fig. 2 Typical design flow for microcontroller or embedded systems

1.6 Visiting microcontroller sites b) Visit some Internet sites portals like the ones in Fig. 3 or others listed at the Magazines2 section and find an

embedded system based on an 8-bit microcontroller. Copy the specifications, the circuit schematic, the microcontroller in which it is based, the program flow chart and the link to the application.

2 http://digsys.upc.es/ed//revistes/magazines.html

7

Page 8: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EPSC – CSD: Digital Circuits and Systems

Fig. 3 Typical Internet microcontroller portals for searching information

1.7 PIC16F87X microcontrollers 1.7.1 Architecture

c) Examine the architecture in Fig. 4 and list components which you could be able to design using VHDL as in previous chapters.

d) Study the PC16F877A datasheet to find answers for the following questions related to the basic building blocks which are represented in Fig. 4.

http://epsc.upc.edu/projectes/sed/SED/unitats/unitat_2_3/DataSheet_PIC16F87XA.pdf

1. Explain the differences between Harvard and Von Neumann microprocessor architectures.

2. Which is the main architectural difference between 8/16/32 bits microprocessors?

3. Which are the functions of the FLASH (ROM) memory and the RAM registers?

4. Explain what the stack memory is and how it is used for.

5. List the blocks which are peripherals.

6. List the blocks which may be included into de CPU (Central Process Unit).

7. Explain the main characteristics of the Bank0 and Bank1 of the RAM memory.

8. How many clock cycles are required for executing an instruction in assembler?

9. Describe the fashion in which the following assembler instructions are executed and the resources involved:

INCF PORTA,F (F = 1, PORTA = 05h)

DECFSZ PORTB,W (W = 0, PORTB = 06h)

8

Page 9: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EX5: Setting up applications with microcontrollers

Fig. 4 PIC16F877 architecture

1.7.2 PIC assembler: RISC instruction set

e) Analyse and print (Courier New, 8p) the disassemble listing of the square wave generator in section a). Explain how the C compiler has translated C statements into assembler instructions (see Fig. 5).

9

Page 10: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EPSC – CSD: Digital Circuits and Systems

Fig. 5 PIC16F877A Assembler instruction set

1.8 Analysis of a FSM-like application In this section, you are going to use as “theory” the example of a “Head & Tails” generator available at the web page. We are going to follow a finite state machine coding style, thus remembering and using again Chapter I, II and III concepts and topics, even if you are writing software code instead of synthesising hardware. FSM-style programming will be the only one permitted in the course, in order to standardise procedures, facilitate class discussions and assignments’ assessment. You might consider that such limitation to your creativity may be seen as a drawback. However, it is indeed, a great advantage in many other aspects. This idea of coding C

10

Page 11: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EX5: Setting up applications with microcontrollers

programs in FSM style was originally inspired in the PicKit1 Flash Starter Kit User’s Guide 3 (Appendix C, Lesson 2).

f) Draw the architecture of a FSM, and explain the ideas on how it will be solved using a microcontroller. Explain the function main() and what it is used for.

g) Explain how the I/O ports are configured in order to interface inputs (sensors, pushbuttons, switches, etc.) and digital outputs (LED, displays, motors, etc.)

1.8.1 Generating the CLK signal for the FSM

h) Learning how to use the Timer0: firstly, the hardware diagram (RTL schematic); secondly, the bits and registers that are in charge of configuring the peripheral; and finally, the explanation of a sample C program in charge of handling the peripheral (using interrupts).

i) Explain the schematic in Fig. 6 to handle interrupts for the single PIC interrupt vector.

Fig. 6 Interruption scheme for PIC16F87X microcontrollers

j) Draw the program flowcharts (main function, state register, CC1 and CC2) for the heads and tails game. Explain the way operations and questions have been translated to C.

3 http://ww1.microchip.com/downloads/en/DeviceDoc/40051D.pdf

11

Page 12: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EPSC – CSD: Digital Circuits and Systems

1.8.2 Hands on the design a 5 second timer

k) To put into practise all the concepts studied previously, try to design the same 5 seconds timer from EX4.

l) Add the LCD display to show timer information.

Do not modify the text from page 3 to page 9

12

Page 13: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EX5: Setting up applications with microcontrollers

1.9 Problem solution (títol 2)1.9.1 Part 1 (títol 3)

Part 1.1 (títol 4)

És necessari que seguiu aquestes indicacions per qualsevol dels vostres documents en aquesta assignatura. Aprendre-les forma part de la competència de comunicació escrita. Adapteu els vostres documents al format subministrat per aquesta plantilla.

Si alguna indicació o format no l’acabeu d’entendre bé, pregunteu-nos-ho o aclariu els dubtes, però no lliureu mai res que no compleixi aquestes indicacions perquè no us ho corregirem i perdreu el temps.

Afegiu aquí el vostre text (estil normal) encapçalat amb títols (Títol 2 i 3 i 4), amb figures (estil “llegenda” o “epígrafe”) i referències creuades en el text com aquesta Fig. 7 (és una referència creuada a la llegenda, veureu que surt en color gris quan la cliqueu) a les figures que inseriu. Fixeu-vos que la primera vegada que obrireu aquest document en Word 2007, no us sortirà aquesta llegenda “Fig.”, així que haureu de crear-ne una, i després, encara que la esborreu,ja us quedarà la referència. Veureu també que la numeració de les figures és un paràmetre automàtic. Si seleccioneu tot el document, i premeu “F9” actualitzareu tota la numeració.

També l’índex de la pag. 2 és completament automàtic. Es genera sol ( a partir de referències, índex de continguts, Inseriu un índex de continguts) i s’actualitza sol a partir també de “F9” havent seleccionat tot el text de document. És possible que la primera vegada que l’actualitzeu desaparegui. No passa res, simplement cal tornar-lo a generar a partir del menú referències i taula de contingut.

Fixeu-vos en la Fig. 7. Les imatges han d’estar centrades i alineades amb el text. Si voleu posar un parell d’imatges a la mateixa línia, inseriu primer una taula d’un parell de columnes i tot seguit feu invisibles les vores. El millor que podeu fer és “cut & paste” de la pròpia taula que veieu, i, canviar les figures per les vostres.

Feu referència també en el text a les fonts bibliogràfiques o de web que consulteu d’aquesta manera [1] (és una referència creuada a l’element numerat [1]). Expliqueu perquè les heu consultat i quina informació útil heu trobat.

Per corregir la primera versió del vostre treball, no imprimiu ni lliureu des de les pàgines 3 a la 5. És l’enunciat del problema. Sols cal que imprimiu les 2 primeres pàgines que contenen els detalls personals, el resum i l’índex, i a partir d’aquesta mateixa pàgina 6. Però feu-ho amb la numeració correcta. És a dir, treballeu sempre sobre aquest document, i en tot cas, importeu altres textos que tingueu cap a aquest mateix document i formateu-los correctament.

Insistim sobre això mateix: treballeu sempre sobre aquest mateix fitxer per preparar la vostra solució. Així usareu tots els estils i formats que ja té predefinits aquest document.

13

Page 14: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EPSC – CSD: Digital Circuits and Systems

Fig. 7 Exemple de peu de figura que segueix la numeració de l’enunciat (llegenda).

Heu d’instal·lar els correctors ortogràfics en català, espanyol i anglès en el vostre paquet d’eines office. I sobretot, corregir qualsevol error mentre escriviu. Si treballeu això estalviareu molta feina als vostres companys i instructors.

1.10 References Modify or add new references to this section. Follow the same format.

[1] http://digsys.upc.es . Comment: at the EX5 web page there is information on the Heads & Tails example. [retrieved 11/2010]

[2] Reese, R. B., Microprocessors, from Assembly language to C Using the PIC18Fxx2, Da Vinci Engineering Press, 2005.

[3] www.microchip.com . Comment: manufacturer web site. Here you can browse for everything on PIC’s. For example, here you are the MPLAB IDE User’s guide.

[4]

- Before delivering the exercise Remember to add your own sources and references

1.11 Study plan to solve the exercise Establish a study plan, a task distribution scheme and other requirements to succeed in producing a good solution when working cooperatively: flux diagrams, concept maps, schematics, tables, pictures, etc.

14

Page 15: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EX5: Setting up applications with microcontrollers

(This section is mandatory. It must be filled in order to get a mark.)

15

Page 16: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EPSC – CSD: Digital Circuits and Systems

1.12 Topics and activities checklist

Topics Activities

Group member in

charge Comments

1 2 3

Part 1: The theory

1. Microcontroller design flowa)

2. Analyse information about microcontrollers applications b)

3. Analyse the architecture of an 8-bit microcontroller like the PIC16F877A and describe their main blocks and peripherals

c), d)

4. Explain the basics of a microcontroller-based embedded system. Architecture of a computer (CPU, memory, peripherals)

d)

5. From C to assembler: disassembling e)

6. Deduction of program flow charts from code f)

Topics Activities

Group member in

charge Comments

1 2 3

Part 2: Analysis of an application designed in our FSM style

7. Programming in FSM styleg), h), i), j)

8. Explain the way to program I/O ports. g)

9. Explain the block diagram (at RTL level) and the way to program the Timer0 h)

Part 3: Your own design

10. Design an application in FSM style Follow the above design flow to obtain a 5-seconds timer using C, MPLAB, Proteus-VSM, the PIC16F877A, and the PICDEM 2 plus

k), l)

16

Page 17: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EX5: Setting up applications with microcontrollers

board.

1.13 Grading grid Here you are the way the exercise could be grades.

Part 1

Installing software and studying the theory

Part 2

Analysis of the Head or Tails game

Part 3

Designing the 5 seconds timer

Total

a), b), c), d), e), f) g), h), i), j) k), l)

Scores 3p 2p 5p

Self-assessment

Instructor’s grades

Do not forget to annotate your own self assessment before uploading the exercise at your site.

1.14 Questions in solving EX 5Write here your questions, comments, doubts, opinions, etc. Add more sheets if necessary to report your progress or comments though the exercise.

[Add something here. It’s impossible to deeply understand everything in this complex subject !] Use this space to reflect and conclude about the course/exercise or whatever related to the content…

17

Page 18: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/.../1011Q1/EX/EX5/CSD_Curs_10_11_Q1_EX5.docx · Web viewMy signature below indicates that I have (1) made equitable contribution

EPSC – CSD: Digital Circuits and Systems

18