upc eetac_1


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.  


Fig 1. Project symbol.

Learning materials and tutorials:

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.

- LAB#12. This is a tutorial on a fixed-time Timer_TMR0_LCD for the PIC18F4520 including in its design phase #2 the LCD from P11.

- The same example Timer XLCD using extended libraries for the LCD. Find which eXtended libraries are required for commanding the TMR0 and replace the low-level code in the previous example.

Examples for other μC:

- Here is the same example that you saw in P11 for the Atmel ATmega 8535. A swith Timer0_ON_OFF  allows selecting the time-base for the datapath: external CLK or TMR0.

- This is the P8 programmable timer HHMM complete project solved using a µC ATmega8535.

- This is the fixed-time timer for the PIC16F877A.

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.


2. Planning

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.

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. For example, this is another tutorial on the design of a bicycle speed meter (20" tyre) using the TMR2 as the time base for the gate-time and the TMR3 for counting the external pulses from the magnetic sensor. Ideas on planning the application + Proteus hardware + C code project.

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


Other materials of interest

This is example of reseach paper in the area of microcontrollers and peripherals on the topic of low power consumption, leaded by prof. Ferran Reverter of the dept. of Electronic Engineering

Reverter, F., €œToward Non-CPU Activity in Low-Power MCU-Based Measurement Systems€, IEEE Transactions on Instrumentation and Measurement ( Volume: 69 , Issue: 1 , Jan. 2020 ). DOI: 10.1109/TIM.2019.2953374.

Abstract: This article evaluates the benefits of having peripheral-triggered peripherals in a microcontroller unit (MCU) intended for low-power sensor applications. In such an architecture, the functionality is moved from the central processing unit (CPU) to the peripherals so that a peripheral is able to trigger another peripheral with non-CPU intervention. For the sensor data logging application under study, both energy consumption and measuring time are reduced by a factor of 2 with respect to the case of applying an interrupt-based approach that requires the CPU intervention.

Download the full paper logging in the UPC intranet.


Examples of bachelor thesis (TFG) on the subject:

- Alberto Gómez Blázquez, A., "Autonomous low-power wireless sensor for a remote weather monitoring station", 2016, (1) (2).  

Wheater station

Fig 3. Weather station representation and its final prototype.

- García Moreno, A. "Autonomous low-power wireless sensor for greenhouse irrigation, 2016, (1)