0% found this document useful (0 votes)
22 views

LAB6 Timer

This document contains a lab assignment on timer interrupts for an electrical engineering course. It includes 4 questions: 1) how to compute the delay generated by a timer, 2) explaining the registers associated with Timers 0-3, 3) writing a program to count from 0-9 using Timer0 interrupts every 4 button presses, and 4) generating a delay on an LED output using Timer0. Code snippets and diagrams are provided as part of the answers.

Uploaded by

Malak Al-Ashi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

LAB6 Timer

This document contains a lab assignment on timer interrupts for an electrical engineering course. It includes 4 questions: 1) how to compute the delay generated by a timer, 2) explaining the registers associated with Timers 0-3, 3) writing a program to count from 0-9 using Timer0 interrupts every 4 button presses, and 4) generating a delay on an LED output using Timer0. Code snippets and diagrams are provided as part of the answers.

Uploaded by

Malak Al-Ashi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Islamic University of Gaza

Faculty of Engineering
Electrical Engineering Department
PIC Lab (EELE- 4115)

Lab # 5

Timer Interrupt

BY

Malak Ehab Al-Ashi 220150622

Submitted for

Eng. Salwa M. Mughessib

Sec. Time

8:00 – 10:00 am , Saturday

Gaza, Palestine
Thursday
December 13, 2018
Objective :
To be familiar with Timer and know the important registers .

Labwork :
Q1 : Using the references I gave you explain How to Compute the delay
duration Generated By the timer ?

𝐼𝑛𝑡𝑒𝑟𝑟𝑢𝑝𝑡𝑃𝑒𝑟𝑖𝑜𝑑 = Pulse counter * Pulse Period


= Pulse counter / Pulse frequency
= 65536 / (48000000/4/Prescaler) Seconds
If the counter register is preloaded with initial value TMRinit then
𝐼𝑛𝑡𝑒𝑟𝑟𝑢𝑝𝑡𝑃𝑒𝑟𝑖𝑜𝑑 = (65536 – TMRinit)/ (48000000/4/Prescaler)
TMRinit= 65536 –interruptPeriod*48000000/4/Prescaler

Q2 Refer to the documentation on pic 18F4550 data sheet (p127)What is the


Registers associated with Timer0, Timer1, Timer2 and Timer3 and explain in a
neat way what they do?

Registers associated with Timer0

Figure 1

1- TMR0L Timer0 Register Low Byte


2- TMR0H Timer0 Register High Byte
3- INTCON Register :
o GIE/GIEH : enable global interrupts
o PEIE/GIEL : enable peripheral interrupts
o TMR0IE : Timer 0 enable
o TMR0IF : Timer 0 flag
4- T0CON (Timer0 control register) :
o TMR0ON: Timer0 On/Off Control bit
o T08BIT: Timer0 8-Bit/16-Bit Control bit

2
o T0CS: Timer0 Clock Source Select bit (External or Internal)
o T0SE: Timer0 Source Edge Select bit (high-to-low transition or low-
to-high transition on T0CKI pin)
o PSA: Timer0 Prescaler Assignment bit (bypasses prescaler or no)
o T0PS2:T0PS0: Timer0 Prescaler Select bits
▪ 111 = 1:256 Prescale value
▪ 110 = 1:128 Prescale value
▪ 101 = 1:64 Prescale value
▪ 100 = 1:32 Prescale value
▪ 011 = 1:16 Prescale value
▪ 010 = 1:8 Prescale value
▪ 001 = 1:4 Prescale value
▪ 000 = 1:2 Prescale value

Registers associated with Timer1

Figure 2

1- INTCON Register :
o GIE/GIEH : enable global interrupts
o PEIE/GIEL : enable peripheral interrupts
2- TMR1L Timer1 Register Low Byte
3- TMR1H Timer1 Register High Byte
4- PIR1 Register :TMR1IF Timer 1 flag
5- PIE1 Register :TMR1IE Timer 1 enable
6- IPR1 Register :TMR1IP Timer 1 priority
7- T1CON: Timer1 control register:
o RD16: 16-Bit Read/Write Mode Enable bit
o T1RUN: Timer1 System Clock Status bit (from Timer1 oscillator or
another source)
o T1CKPS1:T1CKPS0: Timer1 Input Clock Prescale Select bits
o T1OSCEN: Timer1 Oscillator Enable bit
o T1SYNC: Timer1 External Clock Input Synchronization Select bit
o When TMR1CS = 1:
o 1 = Do not synchronize external clock input
o 0 = Synchronize external clock input
o When TMR1CS = 0:
o This bit is ignored. Timer1 uses the internal clock when TMR1CS = 0.

3
o TMR1CS: Timer1 Clock Source Select bit (External from
RC0/T1OSO/T13CKI pin or internal )
o TMR1ON: Timer1 On bit

Registers associated with Timer2

Figure 3

1- INTCON Register:
o GIE/GIEH : enable global interrupts
o PEIE/GIEL : enable peripheral interrupts

2- TMR2 Register: Timer2 Register Low Byte


3- PIR1 Register :TMR2IF Timer 2 flag
4- PIE1 Register :TMR2IE Timer 2 enable
5- IPR1 Register :TMR2IP Timer 2 priority

6- T2CON: Timer2 control register

o bit 7 Unimplemented: Read as ‘0’


o bit 6-3 T2OUTPS3:T2OUTPS0: Timer2 Output Postscale Select bits
▪ 0000 = 1:1 Postscale
▪ 0001 = 1:2 Postscale
▪ 1111 = 1:16 Postscale
o bit 2 TMR2ON: Timer2 On bit
o bit 1-0 T2CKPS1:T2CKPS0: Timer2 Clock Prescale Select bits
▪ 00 = Prescaler is 1
▪ 01 = Prescaler is 4
▪ 1x = Prescaler is 16

7- PR2 Register: Timer2 Period Register

4
Registers associated with Timer3

Figure 4

1- INTCON Register:
o GIE/GIEH : enable global interrupts
o PEIE/GIEL : enable peripheral interrupts

2- TMR3L Timer3 Register Low Byte


3- TMR3H Timer3 Register High Byte
4- PIR2 Register :TMR3IF Timer 3 flag
5- PIE2 Register :TMR3IE Timer 3 enable
6- IPR2 Register :TMR3IP Timer 3 priority
7- T1CON : RD16: 16-Bit Read/Write Mode Enable bit
8- T3CON: Timer3 control register:
o bit 7 RD16: 16-Bit Read/Write Mode Enable bit
o bit 6, 3 T3CCP2:T3CCP1: Timer3 and Timer1 to CCPx Enable bits
▪ 1x = Timer3 is the capture/compare clock source for both CCP
modules
▪ 01 = Timer3 is the capture/compare clock source for CCP2;
▪ Timer1 is the capture/compare clock source for CCP1
▪ 00 = Timer1 is the capture/compare clock source for both CCP
modules
o bit 5-4 T3CKPS1:T3CKPS0: Timer3 Input Clock Prescale Select bits
▪ 11 = 1:8 Prescale value
▪ 10 = 1:4 Prescale value
▪ 01 = 1:2 Prescale value
▪ 00 = 1:1 Prescale value
o bit 2 T3SYNC: Timer3 External Clock Input Synchronization Control
bit
o bit 1 TMR3CS: Timer3 Clock Source Select bit
o bit 0 TMR3ON: Timer3 On bit

5
Q3 Using Timer0 write a program that count from 0 to 9 every 4 bush button
(with code Comments).

Figure 5

Figure 6

6
Q4 Generate delay using timer0 on led output (simple flasher).

Figure 7

Figure 8

7
Figure 9

The End

You might also like