upc eetac_1

Project P12 on the use of microcontroller TIMER 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.

- Analyse the given tutorial on how to program the timer. 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.

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

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

Symbol

Fig 1. Project symbol.

- Extra (optional), as a way to finish the course integrating most of the CSD content): Build a technology alternative to the P8 matrix keypad programmable timer using a microcontroller instead of the PLD.

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

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

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.

TMR0

Fig 2. Hardware components of the Timer0 (TMR0) of the Microchip PIC16F877A. A similar one can be found for any other peripheral timer like TMR1 or TMR2.  

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.

 

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

Books, web pages, etc.

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

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.