upc eetac_1

P11

Project P12 on the use of microcontroller TIMER peripherals

Low Power


Peripherals: 6-bit Johnson counter with TMR2

1. Specifications

- Enhance the Johnson counter inherited from P10 or P11 using the Timer2 (TMR2) peripheral of the microcontroller specified in the term (Atmel ATmega8535, Microchip PIC16F877A, PIC18F4520, etc.), so that the system advances automatically replacing the functionality of the external CLK or push-button.  

Symbol

Fig 1. Project symbol.

Learning materials and tutorials:

Follow the discussion in class to fully understand these specifications and be able to infer a plan. Some initial notes (do not copy them literally, but study them to generate your own documentation.

Study carefully these tutorials and run them in the simulator using debugging features such as watch variables, step by step execution, etc., to see how the system works and can be programmed taken advantage of all your previous knowledge and projects.

- Take any of these (1) or (2) P11 tutorial examples which include and operates the PIC18F4520 TMR0 for timing purposes.

- The Timer project (Microchip PIC16F877A) which is completely rebuild to make it more comprehensible following our CSD design style.

- Here is the same example that you saw in P11 for the Atmel ATmega 8535.

Because the TMR0 is a fundamental block that, with slight variations, is present in all microcontrollers devices, there is a large amount of information that you are invited to visit.

Other examples of timers in former units 4.10 (TMR0) and 4.12 (TMR1) and 4.14 (TMR2).  

 

2. Planning

Analyse the given tutorial on how to program the Timer0 (TMR0). Thus, explain in detail (diagrams, schematics, flowcharts, etc.) how the peripheral works (print the datasheet section), which is its hardware and their configuration bits, how to initialise it, to run it using interrupts, etc. Later, replace the TMR0 by the TMR2. These are some notes.

1) General discussion to understand the problem: State diagram, timing waveforms, features, etc.  use these notes.

2) Organise the hardware. Draw your circuit in a sheet of paper and discuss where to connect: Reset (CD), CLK oscillator, digital I/O and push-buttons. A good idea is to connect inputs and outputs in the free pins of a development board like the PICDEM2 Plus, in case you would like to prototype the application.

architecture Timer0

Fig 2. Hardware components (a kind of RTL view) of the Timer0 (TMR0) of the Microchip PIC16F877A. A similar one can be found for any other peripheral timer like TMR1 or TMR2 of the same family, or for similar devices like the Atmel ATmega8535 chip.

3) Organise the software. Define the RAM internal variables.

4) Plan a sequence for building and debugging the application: the idea is "plan & develop & test" step by step enhancing the initial state diagram with a new feature at a time. For instance:

(1) Run the tutorials and learn how to operate the timer. 

(2) Copy and add the TMR2 features to the P10 or P11, so that the counter advances when a TMR2_Flag is set. 

 

3. Development

1) Draw the schematic of the application in Proteus copying the P10 or P11 and modifying it. 

 

Fig. 3. 

2) Run the microcontroller's IDE to develop and compile the C code copying and adapting the previous P10 or P11 code. Do it section by section according to your plan, testing if it works before adding new code.

 

4. Testing 

 Run the Proteus simulator. Do it in step by step mode while watching variables and placing break points, specially to follow the interrupt flags.

 

Fig. 4. 

 

5. Report

This is a page with some guidelines on how to deliver an oral presentation or how to write a technical report using professional resources and a word processor.

 

6. Prototyping

You're invited to download the application to a given training board an verify that it works as expected and the same as in the simulator.

 

Other similar projects on sequential circuits

At this end point of the course, you can organise a P_Ch3 from this list of projects that will show you the possibilities of this subject to design all kind of electronic appliances.

 In this introductory project, the TMR0 has been interfaced at the bit level, thus programming the configuration bits in the corresponding RAM registers. However, like with other peripherals, all the commercial C compilers contain high-level C libraries (drivers) that can be used instead of programming at the bit level. These libraries (example from ST)  become a hardware  abstraction layer (HAL) to allow the programmer control peripherals without having to know the specific details of a given microcontroller family or vendor. Remember how you programmed the LCD display in P11 without much inside on the Hitachi HD44780 chip or liquid crystal technology. We recommend you to study some of them because as the project grow they become indispensable.

 

"Education is really aimed at helping students get to the point where they can learn on their own. . . "

Noam Chomsky

Examples of final-term exams  (Exa_2)

- Exams, questions, problems and projects