1

EX6: Designing a microcontroller-based one-minute timer

EX 6 DIGITAL CIRCUITS AND SYSTEMS

A one-minute timer

1.1Cooperative group

TEAM 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 membersRoles: (reporter, simulator, etc.)

(1)______

(2)______

(3)______

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

(1)______

(2)______

1.2Abstract

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

CONTENT

A one-minute timer

1.1Cooperative group

1.2Abstract

1.3Description

1.4Topics

1.5Design strategy

1.5.1Block diagram and specifications for the one-minute timer

1.5.2Phase I: Interfacing Timer1 by interrupts

1.5.3Phase II: Adding the LCD

1.5.4Phase III: Set timer’s time using buttons

1.5.5Phase IV: Adding a sound alarm

1.6Problem solution (títol 2)

1.6.1Part 1 (títol 3)

1.7References

1.8Study plan to solve the exercise

1.9Topics and activities checklist

1.10Grading grid

1.11Questions in solving EX 6

1.3Description

This 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 PICDEM2 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.4Topics

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 aC-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 Picdem2 Plus boardto 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.5Designstrategy

1.5.1Block 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 timingperiod 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, whichwas 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 HD44780chip) 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.

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

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

Software and hardware strategy (CSDknow-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.

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

  • Phase I: Adapt the 5-secondsTimer 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.
  • Phase II: Add LCD routines so that “Time_Value” and remaining time are displayed on the screen.
  • Phase III: Modify the state diagram to add the setting of the Time_Value” variable using both buttons “Time_Up” and “Time_Down”
  • 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.2Phase I: Interfacing Timer1 by interrupts

c)Explain schematic in Fig. 2 to handle interrupts from peripherals like the Timer1to 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.

1.5.3Phase 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.4Phase 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.5Phase 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.

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

1.6Problem solution (títol2)

1.6.1Part 1 (títol3)

Part 1.1(títol 4)

Ésnecessari que seguiuaquestesindicacions per qualsevoldelsvostresdocuments en aquestaassignatura. Aprendre-les forma part de la competència de comunicació escrita. Adapteuelsvostresdocuments al formatsubministrat per aquesta plantilla.

Si alguna indicació o format no l’acabeud’entendrebé, pregunteu-nos-ho o aclariuelsdubtes, peròno lliureumai res que nocompleixiaquestesindicacionsperquè no ushocorregirem i perdreu el temps.

Afegiu aquí el vostretext(estil normal)encapçalatambtítols (Títol2 i 3 i 4), amb figures (estil “llegenda” o “epígrafe”) i referènciescreuades en el textcomaquestaFig. 3(és una referènciacreuada a la llegenda, veureu que surt en color gris quan la cliqueu)a les figures que inseriu. Fixeu-vos que la primera vegada que obrireuaquestdocument en Word 2007, no ussortiràaquestallegenda “Fig.”, així que haureu de crear-ne una, i després, encara que la esborreu,jausquedarà la referència. Veureu també que la numeració de les figures és un paràmetreautomàtic. Si seleccioneutot el document, i premeu “F9” actualitzareu tota la numeració.

També l’índex de la pag. 2 éscompletamentautomà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” haventseleccionattot el text de document. Éspossible que la primera vegada que l’actualitzeudesaparegui. 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’estarcentrades i alineadesamb el text. Si voleu posar un parelld’imatges a la mateixalínia, inseriu primer una taula d’unparell de columnes i totseguitfeu invisibles les vores. El millor que podeuferés “cut & paste” dela pròpia taula que veieu, i, canviar les figures per les vostres.

Feureferència també en el text a les fontsbibliogràfiques o de web que consulteud’aquesta manera [1] (és una referènciacreuada a l’elementnumerat [1]). Expliqueuperquè les heu consultat i quinainformacióútil heu trobat.

Per corregir la primera versió del vostretreball, no imprimiu ni lliureu des de les pàgines 3 a la 5. Ésl’enunciat del problema. Solscal que imprimiules 2 primerespàginesque contenenelsdetallspersonals, el resum i l’índex, i a partir d’aquestamateixapàgina6. Peròfeu-hoamb la numeració correcta. És a dir, treballeusempre sobre aquestdocument, i en tot cas, importeualtres textos que tingueucap a aquestmateixdocument i formateu-los correctament.

Insistim sobre aixòmateix: treballeusempre sobre aquestmateixfitxer per preparar la vostrasolució. Aixíusareutots els estils i formats que ja té predefinitsaquest document.

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 mentreescriviu. Si treballeuaixòestalviareumoltafeinaalsvostrescompanys i instructors.

1.7References

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

[1] Comment: Course wed page where to find a lot of resources for the course. Slides on the use of the Timer 1 at Unit 12/2009]

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

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

1.9Topics 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)
  1. 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)
  1. Use the virtual laboratory Proteus-VSM to simulate microcontroller-based applications.
/ d), e), f), g), h)
  1. Use the “virtual” and real Picdem 2 Plus board to simulate, debug and prototype designs.
/ d), e), f), g), h)
  1. Use the “step” mode and “watch” variables and registers and other CPU information to debug the program
/ d), e), f), g), h)
  1. Explain the main characteristics of a peripheral like the LCD display and how to program it.
/ f)
  1. Explain the block diagram of the Timer1 peripheral, the configuration registers and bits, how to program it using interrupts.
/ c), d), e)
  1. (extra) Explain the USART port and program it to communicate the one-minute timer to a PC.

  1. Use laboratory instruments to characterise time domain specifications and measure design’s performance.
/ i)

1.10Grading grid

Here you are the way the exercise could be grades.

Phase I
The Timer 1 / Phase II
The LCD / Phase III
The set-time buttons / Phase IV
The sound alarm / Total
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.

1.11Questions in solving EX 6

Write 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…

[1]