Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

ELECTRICAL ENGINEERING DEPARTMENT

PRACTICAL WORK 3

COURSE CODE &


NAME DEC 40053: EMBEDDED SYSTEM APPLICATIONS
TITLE PIC TIMER PROGRAMMING
PRACTICAL WORK DEC40053 / PW03 / REV00 / 16JAN2023
NO.
LECTURER’S NAME MADAM ROSMAWATI BINTI OTHMAN
GROUP NO. 2 / DEP4A S2
NAME / 1. RATINESWARY A/P THANARAJU
REGISTRATION [07DEP21F1008]
2. HAFIZULZAIDEE BIN MD RASBIDEE
[07DEP21F1034]
3. NORZIANA BINTI MATIM
[07DEP21F1036]

ACTION NAME & DESIGNATION SIGNATURE DATE

16 JAN 2023
Course
Prepared by: Coordinator
Head of Programme /Head of Dept. 6 FEB 2023

Verified by:
PW3: PIC TIMER PROGRAMMING

INSTRUCTIONS:
i. Implementation in groups (max. 4 students) ii. Each student must
answer the questions that have been prepared in their respective
sections.
iii. Make a group discussion to produce and share ideas to solve
the question.
iv. Conclusion and discussion must be written as a group v. All
program code must be written in handwriting.
vi. Groups need to submit this practical work along with the cover sheet,
answers, and rubric ONLY to the lecturer before the due date.
LEARNING OUTCOMES (LO):

Upon completion of this course, students should be able to:


Construct and simulate real-time embedded system application based on
PIC16F/PIC18F microcontroller effectively. (P4, PLO5, CLO3)

OBJECTIVES
Upon completion of this course, students should be able to:
i. Write C program for PIC timer and counter.
ii. Draw and simulate PIC timer and counter in Proteus.
iii. Build timer and counter hardware circuit.

EQUIPMENT / TOOLS

i. PC installed software: ii. MPLAB X IDE


integrates with XC8 compiler.
iii. PROTEUS 8 Professional

SAFETY PRECAUTIONS

The following safety precaution shoul be taken when using equipment. Precaution
are most important for safety from accident :

i. Students must obey the lecturer's instructions.

DEE40053/PW3/REV00/16JAN2023 Page 2 of 23
PW3: PIC TIMER PROGRAMMING

ii. Keep proper discipline in the laboratory. iii. Turn off the electricity when
not in use, especially the computer. iv. In the event of any
emergency/circuit leakage, please inform the lecturer. v. Students are
not allowed to eat or drink in laboratory. vi. Students must wear
appropriate attire when in the laboratory.

THEORY

The Timer0 module incorporates the following features:

i. Software selectable operation as a timer or counter in both 8-bit or 16-bit


modes
ii. Readable and writable registers
iii. Dedicated 8-bit, software programmable prescaler
iv. Selectable clock source (internal or external)
v. Edge select for external clock
vi. Interrupt-on-overflow

Figure 1: Data sheet of PIC18F4580

DEE40053/PW3/REV00/16JAN2023 Page 3 of 23
PW3: PIC TIMER PROGRAMMING

TUTORIAL

Tutorial 1: (Timer as a time delay)


Using Appendix 1 as reference, find the value for T0CON for creating
time delays using setting as below:
i. Timer0 OFF
ii. Timer0 is configured as a 16-bit timer/counter
iii. Internal instruction cycle clock
iv. Increment on low-to-high transition on T0CKI pin
v. Timer0 prescaler is assigned
vi. 1:256 Prescale value

T0CON = 0b________;

Find values to be loaded into TMR0H and TMR0L for creating 500 mili-second
delay using steps below.

Step 1
Time for 1 cycle,
𝟏
𝟏𝑻𝒄𝒚 =
𝑭𝒐𝒔𝒄 𝒙 𝟒 𝒙 𝒑𝒓𝒆𝒔𝒄𝒂𝒍𝒂𝒓
Step 2
Get the number of counts by Dividing the desired time delay by 1Tcy

𝑫𝒆𝒔𝒊𝒓𝒆 𝒕𝒊𝒎𝒆 𝒅𝒆𝒍𝒂𝒚


𝑵𝑶𝑪 =
𝟏𝑻𝒄𝒚

Step 3
Perform 65,536 - n, where n is the decimal value we got in Step 2.

𝒙𝒙𝒚𝒚 = 𝟔𝟓, 𝟓𝟑𝟓 − 𝑵𝑶𝑪 + 𝟏

Step 4
Convert the result of Step 3 to hex, where yyxx is the initial hex value to be loaded
into the timer’s registers.

xxyy10 → xxyy16

DEE40053/PW3/REV00/16JAN2023 Page 4 of 23
PW3: PIC TIMER PROGRAMMING

Step 5
Set TMR0H = yy16 and TMR0L = xx16
Tutorial 2: (Timer as a time delay)
Create a new file. Write a program in Figure 2 into your Untitled window. Fill the red
box using suitable instructions. Then build the program until successful. If any error
occurs, fix it.

Figure 2: source code

DEE40053/PW3/REV00/16JAN2023 Page 5 of 23
PW3: PIC TIMER PROGRAMMING

Tutorial 3: (Timer as a counter)


Using Appendix 1 as reference, find the value for T0CON as a counter using setting
as below:

• Timer0 OFF
• Timer0 is configured as a 8-bit timer/counter
• Transition on T0CKI pin
• Increment on low-to-high transition on T0CKI pin
• Timer0 prescaler is NOT assigned
• 1:2 Prescale value

T0CON =

Tutorial 4: (Timer as a counter)


Create a new file. Write a program in Figure 3 into your Untitled window. Fill the red
box using suitable instructions. Then build the program until successful. If any error
occurs, fix it.

DEE40053/PW3/REV00/16JAN2023 Page 6 of 23
PW3: PIC TIMER PROGRAMMING

S1 NAME:
S1 ID:
S1 QUESTION: Find values to be loaded into TMR0H and TMR0L for creating
100 millisecond delay using steps below.

S1 ANSWER: (Write your calculation values of TMR0H and TMR0L here)

DEE40053/PW3/REV00/16JAN2023 Page 7 of 23
PW3: PIC TIMER PROGRAMMING

S1 ANSWER:
(using proteus simulation capture dan observing the simulation result for each changing process
changing in Tutorial 2)

BEFORE

AFTER

DEE40053/PW3/REV00/16JAN2023 Page 8 of 23
PW3: PIC TIMER PROGRAMMING

DEE40053/PW3/REV00/16JAN2023 Page 9 of 23
PW3: PIC TIMER PROGRAMMING

S2 NAME:
S2 ID:
S2 QUESTION: Find values to be loaded into TMR0H and TMR0L for creating
200 millisecond delay using steps below.
S2 ANSWER: (Write your calculation values of TMR0H and TMR0L here)

DEE40053/PW3/REV00/16JAN2023 Page 10 of 23
PW3: PIC TIMER PROGRAMMING

DEE40053/PW3/REV00/16JAN2023 Page 11 of 23
PW3: PIC TIMER PROGRAMMING

S2 ANSWER:
(using proteus simulation capture dan observing the simulation result for each changing process
changing in Tutorial 2)

BEFORE

AFTER

DEE40053/PW3/REV00/16JAN2023 Page 12 of 23
PW3: PIC TIMER PROGRAMMING

DEE40053/PW3/REV00/16JAN2023 Page 13 of 23
PW3: PIC TIMER PROGRAMMING

S3 NAME:
S3 ID:
S3 QUESTION: Find values to be loaded into TMR0H and TMR0L for creating
300 millisecond delay using steps below.
S3 ANSWER: (Write your calculation values of TMR0H and TMR0L here)

DEE40053/PW3/REV00/16JAN2023 Page 14 of 23
PW3: PIC TIMER PROGRAMMING

S3 ANSWER:
(using proteus simulation capture dan observing the simulation result for each changing process
changing in Tutorial 3)

DEE40053/PW3/REV00/16JAN2023 Page 15 of 23
PW3: PIC TIMER PROGRAMMING

DEE40053/PW3/REV00/16JAN2023 Page 16 of 23
PW3: PIC TIMER PROGRAMMING

S4 NAME:
S4 ID:
S4 QUESTION: Find values to be loaded into TMR0H and TMR0L for creating
300 millisecond delay using steps below.
S4 ANSWER: (Write your calculation values of TMR0H and TMR0L here)

DEE40053/PW3/REV00/16JAN2023 17 of 23
PW3: PIC TIMER PROGRAMMING

S4 ANSWER:
(using proteus simulation capture dan observing the simulation result for each changing process
changing in Tutorial 3)

DEE40053/PW3/REV00/16JAN2023 18 of 23
PW3: PIC TIMER PROGRAMMING

DISCUSSION:
(Discussion refers to the findings of practical work through observation, problems
encountered during performance practical work and suggestions for improvement)

In this practical, we use timer0. Timer0 can operate as either a timer or


a counter; the mode is selected with the TOCS bit of the T0CON register. In
timer mode (TOCS=0),the module increments on every clock by default
unless a different prescaler value is selected. Timer0 incrementing is
inhibited for two instruction cycles following a TMR0 register write. The user
can work around this by adjusting the value written to the TMR0 register to
compensate for the anticipated missing increments.

CONCLUSION:
(Write a conclusion based on the objective of the practical work that has been done)

The conclusion that I can make from this practical work are I can write
C program for PIC timer and counter. After that, I can draw and stimulate
PIC timer and counter in proteus.Lastly, I can build timer and counter
hardware circuit.

DEE40053/PW3/REV00/16JAN2023 19 of 23
PW3: PIC TIMER PROGRAMMING

DEE40053/PW3/REV00/16JAN2023 20 of 23
PW3: PIC TIMER PROGRAMMING

DEC 40053 – EMBEDDED SYSTEM APPLICATIONS


PRACTICAL WORK 1 / 2 / 3 / 4 / 5 / 6
PRACTICAL SKILL ASSESSMENT RUBRIC CLO 3:
Construct and simulate real-time embedded system application based on PIC18F microcontroller effectively. (P4, PLO5)

CRITERIA 1 2 3 4 5 weight S1 S2 S3 S4
Average Excellent
Weak Satisfactory Good

Write Program Unable to type a Able to type Able to type all Able to type all Able to type all
program program but totally parts of the parts of the parts of the
)
06 %

using MPLAB are incorrect. program, but less program, but less program correctly. x5
X IDE than 60% of the than 80% of the
PRACTICAL SKILL (

program is correct. program is correct.

Compile Student cannot Student cannot fix Student cannot fix Student cannot fix Execute all
program using fix the error after the error after being the error after the error after program
MPLAB X IDE being assisted by assisted by lecturer being assisted by being assisted by successfully without x5
lecturer many 3 times. lecturer 2 times. lecturer 1 time assistance
times.

Student cannot Student cannot fix Student cannot fix Student cannot fix Student can sketch
Construct fix the circuit the circuit the circuit the circuit all connection of
circuit using connection by connection by itself connection by connection by circuit correctly x4
hardware or itself after being after being assisted itself after being itself after being without
software assisted by by lecturer 3 times. assisted by assisted by assistance.
Proteus lecturer many lecturer 2 times. lecturer 1 time.
simulation. times.

DEE40053/PW3/REV00/16JAN2023 Page 12 of 13 PW3: PIC TIMER


PROGRAMMING
DEC 40053 – EMBEDDED SYSTEM APPLICATIONS
PRACTICAL WORK 1 / 2 / 3 / 4 / 5 / 6
PRACTICAL SKILL ASSESSMENT RUBRIC CLO 3:
Construct and simulate real-time embedded system application based on PIC18F microcontroller effectively. (P4, PLO5)

CRITERIA 1 2 3 4 5 weight S1 S2 S3 S4
Average Excellent
Weak Satisfactory Good

Handwritten Unable to write a Able to write program Able to write all parts Able to write all parts Able to write all parts
coding program but totally are of the program, but of the program, but of the program
)
0%

incorrect. less than 80% of the less than 80% of the correctly. x2
REPORT (4

program is correct. program is correct.

Observation The changing Student can display Student can display Student can display Student can show all
process of or prove less than or prove less than or prove less than of the simulation’s
simulation cannot 30% of the 50% of the 80% of the changing processes
be displayed by the simulation’s changing simulation’s simulation’s correctly.
student. process. changing process. changing process.
x2
Very incomplete or Some of the results Almost of the results Almost all the results All-important trends x1
incorrect have been correctly have been correctly have been correctly and data comparisons
Discussion
interpretation of interpreted and interpreted and interpreted and have been interpreted
trends and discussed; partial but discussed, only discussed, only correctly and
comparison of data incomplete minor improvements minor improvements discussed; good
indicating a lack of understanding of are needed are needed understanding of
understanding of results is still evident results is conveyed
results

Conclusion No conclusion was A statement of the A statement of the Accurate statement Accurate statement of x1
included or shows results is incomplete results of the lab of the results of the the results of lab
little effort and with little reflection on indicates whether lab indicates indicates whether
reflection on the lab the lab results support the whether results results support
hypothesis support the hypothesis. Possible
hypothesis Possible sources of error and
sources of error what was learned
identified from the lab discussed

Total 100
DEE40053/PW3/REV00/16JAN2023 Page 13 of 13

You might also like