UPC EETAC Bachelor's Degree in Telecommunications Systems and in Network Engineering EEL

 

P12: using peripheral timer TMR2

P12


Resources in lectures and labs: L12.1, Lab11, L12.2, L12.3 Project objectives

4-bit serial transmitter with LCD display and TMR2

Design phases ==> #1: Serial_TX ==> #2: Serial_TX_LCD ==> #3: Serial_TX_LCD_TMR0 ==> #4: Serial_TX_LCD_TMR2

1. Specifications Planning Dev. & test Prototype Report

Design phase#4: (Update to PIC18F46K22) This is an example of design phase #4: replace TMR0 in Serial_TX_LCD_TMR0 proposed in design phase #3, by the internal timer peripheral TMR2.

Symbol

Fig. 1. Project Serial_TX_LCD_TMR2 symbol

 


Specifications 2. Planning Dev. & test Prototype  Report

A) Planning hardware

The electronic schematic is the same as in design phase #3, we simply replace an internal peripheral by another, thus keeping the same hardware circuit.

Study how the TMR2 works. It has an architecture that implements a hardwired parallel load (LD) signal or synchronous reset that makes it ideal for truncated counting using an additional 8-bit comparator. No software overhead is necessary in ISR() for reinitiating the up counter TMR2 when reaching the same value stored in PR2 register.

TMR2 module

Fig 2. Hardware components (a kind of RTL view) of the TMR2 of the Microchip PIC18F4520.

The key idea for our application is to generate the same var_CLK_flag from TMR2 interrupts.

TMR2_application

Fig. 2. TMR2 configuration for generating a timing period TP = 6.666 ms. In this application, no extra software post-scaler variable N4 is required.

 


B) Planning software 

No changes in the state diagram from design phase #3. We simply have to configure and use TMR2 at the same states where we did it for TMR0.

Project location:

C:\CSD\P12\Serial_TX_LCD_TMR2\(files)

 


Specifications Planning 3. Dev. & 4. test Prototype Report

A) Developing hardware

Our electronic circuit "Serial_TX_LCD_TMR2.pdsprj" (update) is the same that we developed in design phase #3 because we simple replace internal peripheral TMR0 by TMR2.


B) Developing software

The LCD kit software driver, these LCD library files "lcd.c", "lcd.h" , presented in P11, has to be included in the project. The file "config.h" contains all the microcontroller configuration bits. This is the example software source code  "Serial_TX_LCD_TMR2.c" (update). Generate the executable (*.hex) and debugging file (*.cof) for Proteus simulations.

 


C) Step-by-step testing

We can run and debug the application using our usual resources and tools: breakpoints, step-mode, watching variables of interest, etc. For instance, Fig. 3 shows how to measure timing periods generated between TMR2 interrupts.

Running and debugging the application

Fig. 3. Measuring timing periods generated by TMR2 interrupts using breakpoints. There is an interrupt event every TP = 1μs · 4 · 119 · 14 = 6664 μs as expected.  (update).

 


Specifications Planning Dev. & Test 5. Prototype Report

 


Specifications Planning Dev. & Test Prototype 6. Report

Follow this rubric for writing reports.