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.  

- The counter has to advance at a rate of 10 counts per second, thus the timer will generate an interrupt every 100 ms. This means that the TC12SQ will have a period of 1.2 s or a frequency of  8.33 Hz.

- Let's add a switch TMR2_ON to select how to run the counter: a) using the external CLK button as in P10 or P11 or instead, b) by means of interrupts form the internal Timer2 peripheral.

- Add an output to show on the oscilloscope the 10 Hz waveform generated by the Timer0 (for example, derived from the CLK_Flag signal which is the terminal count of the Timer_Post_scaler).


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.


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.


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 features at a time. For instance:

(1) Run and learn from the tutorials.

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

- This is an example checklist (1718Q2) on how to proceed with the project and the report.


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

- Extra (optional, as a way to finish the course integrating most of the CSD content):

1. Build a technology alternative to the P8 matrix keypad programmable timer using a microcontroller instead of the PLD. 

2. Implement the complete Programmable Timer (P8) based on a micrcocontroller.

3. Implement the Timer_MMSS (P8). Here you are how it looks like and operates simulated in Proteus.

A traffic light controller (P8). Etc.

Books, web pages, etc.

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

- A summary of projects proposed in this P12 to how to solve a complex design based on a FSM controlling a datapath system. These are the sample schematic (1) and the C code (2)  to develop the phase 1. This is an example schematic to start planning the next design step (3). This is another multiplexed digit system that can be used after replacing the classic internal design using TTL chips by a microcontroller.  This correction checklist can also be used to organise the project.


Other materials of interest

Books, web pages, etc.

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

- 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 HD4478 chip or liquid crystal technology. We recommend you to study some of them because as the project grow they become indispensable.

- This is a page with other project examples and bachelor thesis that you can read and analyse.    

- In this page you have some links to read more about this passionate world of microcontrollers and their myriad of  applications in all technological fields. For instance, low power circuits.

- A few links on FSM that naturally can be implemented in hardware (VHDL -PLD) or in software (mC): (1) on traffic light controllers; (2) academic; (3) sequence recogniser and vending machines; (4) an excellent table of content and web page of resources (5); (6) academic; (7) a robot that avoid obstacles; (8) hobby robotics; (9) theory from AMD; (10) a complete book; (11) All about circuits FSM & mC; (12) Software based FSM using mC (ARM paper); (13) A nuclear reactor shutdown system; (14) stepper motors; (15) Control for mobile robots; etc. etc.


Examples of final-term exams  (Exa_2)

- Exams, questions, problems and projects