ex1 - upc universitat politècnica de...

17
EX6: Designing a microcontroller-based one-minute timer EX 6 DIGITAL CIRCUITS AND SYSTEMS A one-minute timer 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 6 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: vodieu

Post on 30-Jan-2018

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EX6: Designing a microcontroller-based one-minute timer

EX 6 DIGITAL CIRCUITS AND SYSTEMS

A one-minute timer

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 6 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/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

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/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EX6: Designing a microcontroller-based one-minute timer

CONTENT

A one-minute timer..............................................................................................................................................1

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

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

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

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

1.5 Design strategy..........................................................................................................................................3

1.5.1 Block diagram and specifications for the one-minute timer.............................................................3

1.5.2 Phase I: Interfacing Timer1 by interrupts........................................................................................5

1.5.3 Phase II: Adding the LCD.................................................................................................................5

1.5.4 Phase III: Set timer’s time using buttons..........................................................................................6

1.5.5 Phase IV: Adding a sound alarm......................................................................................................6

1.6 Problem solution (títol 2)..........................................................................................................................7

1.6.1 Part 1 (títol 3)....................................................................................................................................7

1.7 References.................................................................................................................................................8

1.8 Study plan to solve the exercise................................................................................................................9

1.9 Topics and activities checklist................................................................................................................10

1.10 Grading grid............................................................................................................................................10

1.11 Questions in solving EX 6.......................................................................................................................11

3

Page 4: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EPSC – CSD: Digital Circuits and Systems

1.3 DescriptionThis exercise will consist in developing a simple application like a one minute timer, using the input/output programmable ports, the timer/counter T0 to emulate the FSM clock, and some other PIC16F877A peripherals such as the LCD display and the Timer 1 controlled via interruptions.

The idea is to develop your first projects using C in our FSM-like coding style, the Proteus VSM virtual laboratory simulator, and a standard training board from Microchip like the PICDEM 2 Plus for prototyping the final design. Low level assembler language will be optional in case of any of you were interested.

In this exercise, some of the most common PIC16F peripherals will be studied. The procedure will be very similar for all of them: firstly, the hardware diagrams; secondly, the bits and registers that are in charge of the peripheral commanding; and finally, the explanation of a sample C program (found in books, datasheets or Internet) in charge of handling the peripheral.

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:

------------- Design a C-based microcontroller application in FSM-like style -------------

1. Plan and develop through the microcontroller’s design flow an application such as a one minute digital timer using C and the PIC16F877A using the FSM programming style.

2. Develop a complex project through the planning of consecutive phases in which only a limited number of specifications are met each time.

3. Use the virtual laboratory Proteus-VSM to simulate microcontroller-based applications.

4. Use the “virtual” and real Picdem 2 Plus board to simulate, debug and prototype designs.

5. Use the “step” mode and “watch” variables and registers and other CPU information to debug the program

6. Explain the main characteristics of a peripheral like the LCD display and how to program it.

7. Explain the block diagram of the Timer1 peripheral, the configuration registers and bits, how to program it using interrupts.

8. (extra) Explain the USART port and program it to communicate the one-minute timer to a PC.

9. Use laboratory instruments to characterise time domain specifications and measure design’s performance.

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/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EX6: Designing a microcontroller-based one-minute timer

1.5 Design strategy 1.5.1 Block diagram and specifications for the one-minute timer

Fig. 1 shows an schematic for the 1-minute programmable timer. Its specifications, which can be added in several phases until the final design is achieved, include:

- Power supply: 5 V (from a 9 V battery or from the power mains using a voltage regulator)

- PIC16F877A microcontroller.

- Hardware platform: PICDEM 2 Plus board.

Mode of operation:

- Set the timing period using the up/down buttons. Trigger the countdown simply clicking the “Start” button. While timing, a LED is turned ON. Once the timing has finished, a sound alarm is set for some seconds. The timing period can be cancelled simply using the “Reset” button.

Inputs:

- A couple of pushbuttons to set timing period in seconds. When “Time_Up” is pressed the timer counts up at 2 Hz rate until the maximum of 59 s is reached; when “Time_Down” is pressed, the timer counts down until the minimum 0 s is reached. When the pushbutton is released, the number on the display is kept as the timing period.

- A switch which select between seconds or tenth of seconds. When in teth of seconds, “Time_Up” and “Time_Down” works as before but at 1 Hz rate to set the tenth of second’s value.

- A pushbutton “Trigger” to start the down counting from the initial time period displayed in the LCD, which was set previously using the up/down set timing buttons.

- The Reset (MCLR_L) button which returns the system to its initial state.

Outputs:

- A 2-rows LCD display (based on the Hitachi HD44780 chip) to show the timer’s count and messages.

- A LED which turns on when timing.

- An alarm LED which turns on when the timer count reaches zero. After 15 s, it turns off.

- A buzzer output which also generates a sound 2.5 kHz signal when the count reaches zero. After 15 s, it turns off as the LED.

5

Page 6: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EPSC – CSD: Digital Circuits and Systems

Connections:

- An asynchronous communication serial port to a PC [COM1, parity even, 1 bit stop, 19200 b/s], will send commands to the timer and will receive its state].

1 MIN PROGRAMMABLE TIMER

CCT001

MCLR_L

START

TIMER_OUT

LED1

TRIGGER

RESET

VDC

1N914

R110k

DC1 48V

RELAY

B148V

GND

VDC

VDC

3 2

U1:A

4049

OSC1

Power Driver

Time_DownTIME_DOWN

X1CRYSTAL

FREQ=4MHz

Display

D7

14D

613

D5

12D

411

D3

10D

29

D1

8D

07

E6

RW5

RS

4

VS

S1

VD

D2

VE

E3

LCD1

LM032L

VDC

TIME_UP Time_UP

LS1SOUNDER

Sound

OSC1C2

22pF

C1

22pF

TenthTENTH

Fig. 1 An electrical schematic which shows inputs and outputs associated with the project

Software and hardware strategy (CSD know-how):

- 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.

- Remember that before attempting to code in C (or in assembler), a program flow diagram (or program flowchart) must be sketched specifying program sequence, operations and routines.

6

Page 7: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EX6: Designing a microcontroller-based one-minute timer

- Remember that the project have to be planned using phases of increased complexity until finally, all the project specifications are met, always relying in previous similar examples that could be easily adapted and modified. For instance:

o Phase I: Adapt the 5-seconds Timer from the EX5, so that the time is counted by Timer1 instead of Timer0. Study an example were the Timer1 is used in a similar fashion.

o Phase II: Add LCD routines so that “Time_Value” and remaining time are displayed on the screen.

o Phase III: Modify the state diagram to add the setting of the Time_Value” variable using both buttons “Time_Up” and “Time_Down”

o Phase IV: Modify the state diagram to add the sound alarm using again the Timer1 to generate the square wave.

a) Invent a state diagram for the one-minute timer as if it were to be designed in Chapter III as a dedicated processor using VHDL, thus, considering a control unit and a datapath. First, list the combinational and sequential components that will be involved in the project: one-second time base, BCD up and down counter, registers, code converters, etc… Then, annotate all signals and try to deduce the FSM state diagram.

b) Check the peripherals and other hardware resources available in the PIC16F877A architecture, and the hardware available at the PICDEM 2 Plus board. Decide the way you are going to implement every single component in the one-time block diagram proposed in a) (which blocks are going to be hardware peripherals? Which blocks are going to be solved by software?

1.5.2 Phase I: Interfacing Timer1 by interrupts

c) Explain schematic in Fig. 2 to handle interrupts from peripherals like the Timer1 to the single PIC interrupt vector. Explain the interrupt service routine, and draw a program flow diagram if it has to attend interrupts from several peripherals like Timer0 and Timer1.

d) Copy and paste the Timer1 hardware schematic from the corresponding chapter in the datasheet and explain its features. Name and show all the configurations registers involved in its control. Infer the way the registers have to be programmed to suit the problem (counting pulses from the Picdem2 Plus 32.768 kHz crystal). Deduce from the datasheet, books and web portal the way to interface the Timer1 so that it can be used in your One Minute Timer application to count seconds in real time.

e) Debug the project until it works in the Picdem 2 Plus virtual board. Use step by step execution and watch variables and CPU registers. Then program the chip on the PicDem2 board using for example, the ICD2 device.

7

Page 8: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EPSC – CSD: Digital Circuits and Systems

1.5.3 Phase II: Adding the LCD

f) Show timer information in a LCD display. Include a LCD display into the project and debug until it works in the PICDEM 2 Plus virtual board. Then program the chip using, for example, the ICD2 device.

Fig. 2 Interruption scheme for PIC16F87X microcontrollers

1.5.4 Phase III: Set timer’s time using buttons

Include the buttons to set the timer’s time.

g) Connect the necessary buttons and LED’s to the basic project so that it can be commanded as specified. Debug the project until it works in the PICDEM 2 Plus virtual board. Then, program the chip using, for example, the ICD2 device. A convenient strategy in this section may be to add set-time buttons in two steps: (A) add Time_UP and Time_DOWN buttons to set the seconds (a range from 0 to 59); and (B), add the Tenth switch to be able to set tenths of seconds (a range from 0 to 9).

1.5.5 Phase IV: Adding a sound alarm

h) Discuss the way to generate a sound waveform which has to be on for a few seconds once the timer period ends. Implement your solution.

8

Page 9: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EX6: Designing a microcontroller-based one-minute timer

i) Characterise the prototype using laboratory instrumentation (timing period precision, power supply dissipation and energy consumption, etc.)

-------------------------------------------------------------------------------

We will leave for your next application project (AP), the study and use of other microcontroller peripherals such as Timer 2, PWM, CCP, A/D, UART, Data EEPROM, I2C, etc..

Do not modify the text from page 3 to page 6

9

Page 10: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EPSC – CSD: Digital Circuits and Systems

1.6 Problem solution (títol 2)1.6.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. 3 (é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. 3. 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.

10

Page 11: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EX6: Designing a microcontroller-based one-minute timer

Fig. 3 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.7 References Modify or add new references to this section. Follow the same format.

[1] http://digsys.upc.es . Comment: Course wed page where to find a lot of resources for the course. Slides on the use of the Timer 1 at Unit http://digsys.upc.es/ed//CSD/units/Ch4/U4_12/Unit4_12.html [Retrieved 12/2009]

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

11

Page 12: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EPSC – CSD: Digital Circuits and Systems

1.8 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.

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

12

Page 13: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EX6: Designing a microcontroller-based one-minute timer

1.9 Topics and activities checklist

Topics Activities

Group member in

charge Comments

1 2 3

1. Plan and develop through the microcontroller’s design flow an application such as a one minute digital timer using C and the PIC16F877A using the FSM programming style.

a), b), c)

2. Develop a complex project through the planning of consecutive phases in which only a limited number of specifications are met each time.

a), b), c)

3. Use the virtual laboratory Proteus-VSM to simulate microcontroller-based applications.

d), e), f), g), h)

4. Use the “virtual” and real Picdem 2 Plus board to simulate, debug and prototype designs.

d), e), f), g), h)

5. Use the “step” mode and “watch” variables and registers and other CPU information to debug the program

d), e), f), g), h)

6. Explain the main characteristics of a peripheral like the LCD display and how to program it.

f)

7. Explain the block diagram of the Timer1 peripheral, the configuration registers and bits, how to program it using interrupts.

c), d), e)

8. (extra) Explain the USART port and program it to communicate the one-minute timer to a PC.

9. Use laboratory instruments to characterise time domain specifications and measure design’s performance.

i)

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

Phase I Phase II Phase III Phase IV Tota

13

Page 14: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EPSC – CSD: Digital Circuits and Systems

The Timer 1

The LCD The set-time buttons

The sound alarm

l

Scores 2p 2p 3p 3p

Self-assessment

Instructor’s grades

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

14

Page 15: EX1 - UPC Universitat Politècnica de Catalunyadigsys.upc.es/ed/CSD/terms/00_old/1011Q1/EX/EX6/CS…  · Web viewExplain here the most significant developments, results or conclusions

EX6: Designing a microcontroller-based one-minute timer

1.11 Questions in solving EX 6Write 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…

15