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

P11

P12: peripheral TMR0. Adapting dedicated processors

DEE


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

Highlighted project:  4-bit serial transmitter  with TMR0 (design phase #3)

or TMR2 (design phase #4)

1. Specifications Planning Dev. & test Prototype Report

Serial transmitter design phase #3: Serial_transmitter_LCD_TMR0.

Symbol

Fig. 1. Project serial_transmitter_LCD_TMR0 symbol. 

Timing diagram representing bit duration Tbit and the idea of starting to send data immediately after having detected the start transmission (ST) rising edge.

Waveforms

Fig. 2. Waveforms representing Din = "1001" and the bit duration time Tbit.

 


Other design tutorials and assignments.

 


Specifications 2. Planning Dev. & test Prototype  Report

A) Hardware

The circuit is represented in Fig. 3. It is the same as it was in Serial_transmitter_LCD without the external CLK oscillator for generating the bit rate.

Hardware circuit

Fig. 3. Hardware circuit.

Let us study the hardware of the TMR0 peripheral interpreting the datasheet diagram and configuration registers.

architecture Timer0

Fig. 3. TMR0 hardware in 8-bit mode from the PIC18F4520 datasheet. Study the TMR0 registers and configuration bits.


B) Software

We intent to generate var_CLK_flag using internal TMR0. Therefore, the project has the same conception and only minor changes are necessary. When ST interrupt is detected, TMR0 will be switched on, configured and set as the bit time Tbit source for  transmitting bits. In the last state END_message TMR0 will be switch off because it is not required.

hardware-software

Fig. 5. Software-hardware diagram when using TMR0 to generate var_CLK_flag

Design step #1. One idea is to use TMR0 in 8-bit mode. Infer N1, N2 and N3 values required in this application for generating a timing period TP = 6.66666667 ms = Tbit equivalent to 150 b/s or the nearest value.

TMR0 hardware

Fig. 6. TMR0 in 8-bit mode for generating a timing period of TP = 6.666 ms. 

The list of RAM variables required are shown in Fig. 7.

RAM variables

Fig. 6. RAM variables. Selected values allows generating 149.88 Hz (0.08% error). 

Design step #2. Is it possible to obtain more timing precision?. An alternative idea is to use the TMR0 in 16-bit mode, hence, for timing TP =  6.666 ms is not necessary to use neither the prescaler or the software postscaler, resulting in a simpler configuration because we can program var_TMR0_TC_N2 = 6666 obtaining even more precision.

TMR0_16bit_mode_of_operation

Fig. 7. TMR0 in 16-bit mode for generating a timing period of TP = 6.666 ms. In this case, the bit rate is 150.015 b/s, (error 0.01%). However, instruction execution time imposes a time overhead that do not allow to reach such precision. An alternative is to use the TMR2 to generate higher time precision due to an improved circuit with hardware parallel load.

This is how the state diagram is modified for configuring and driving the TMR0. When timing period TP = 6.666 ms is reached, var_CLK_flag is set. The main idea now is to configure and start TMR0 when the ST edge is detected at the ISR() function., thus start bit will be send immediately after the ST active edge. Start_bit state will remain until TP is elapsed.

State diagram modifications

Fig. 8. State diagram modifications.

 

We will draw only the function sections where the TMR0 parameters are set.

Symbol

Fig. 8. ISR() function flowchart.

Project location:

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

 


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

A) Developing hardware

This is the serial_transmitter_LCD_TMR0.pdsprj circuit captured in Proteus.

Circuit captured in Proteus

Fig. 10. Captured circuit.

 


B) Developing software

The XC8 compiler version is v3.0 or higher. C language standard is C99. And these LCD library files lcd.c, lcd.h has to be included in the project. The file config.h contains all the microcontroller configuration bits.

This is the serial_transmitter_LCD_TMR0.c source code.

 


C) Step-by-step testing

Fig. 11 shows Proteus running this application while at the same time watching RAM variables of interest.

Captiring signals and running

Fig. 11. Proteus running the application.

Oscilloscope results can be printed using white background colour for saving ink and easy annotation. 

Wave from Proteus

Fig. 12. Proteus oscilloscope waveforms when Din = "0101"

Measure the transmission frequency accuracy.

To study in detail this project, you can modify the design to use the TMR0 in 16 bit mode.

 


Specifications Planning Dev. & Test 5. Prototype Report

We aim to prototype the transmitter and receiver using two CSD_PICstick boards.

 


Specifications Planning Dev. & Test Prototype 6. Report

Follow this rubric for writing reports.

End of the course option: Now, that you have written many reports in paper, in case of free time once the course ended, you can edit and publish an example project report using LibreOffice word processor and editing tools or similar commercial tools from Microsoft, Google, etc.