0% found this document useful (0 votes)
89 views36 pages

Advanced Microcontrollers and Interfacing

course book

Uploaded by

tkn5520
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
89 views36 pages

Advanced Microcontrollers and Interfacing

course book

Uploaded by

tkn5520
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 36

Department of Engineering

DEE722 (v1)
Advanced Microcontrollers and
Interfacing

Assessment #1: Workbook


(DEE722-A1-V1 Workbook)
Time Allowed for Exam: Daily

Final Weighting: 40%


Lecturer: Latha Murugesan

Name of Student: Student ID:

LO No. Question No. Marks Marks Awarded


1B,C 1-18 18
1E 19-27,29 12
1D 28,30 4
2A-D 31-37 7
3C 38-40 3
1D 41-47 7
2A 48-74 27
2C 75-96 23
1E 97-107 11
1A 108-109 2
1B 110-113 4
2B,D 114-115 2

TOTAL = 120
Final % = %

© International College of Auckland DEE722-A1-V1 Workbook 1


Department of Engineering

Please Note:

1. This closed-book Test is a part of the final mark of this paper. Student must complete
this closed-book test if you wish to be eligible to pass this paper.
2. ENSURE THAT THIS COVER SHEET IS FILLED IN AND ATTACHED TO YOUR COMPLETED CLOSED-BOOK TEST.
3. You are required to answer ALL questions in this closed-book Test.
4. Write your answers on answer sheets attached with this test. Any extra sheet, you
need will be provided by the examiner during exam.
5. Your handwriting must be neat and legible; otherwise you will not receive the marks
allocated for the question(s) which are not legible.
6. Cheating. Students caught cheating during the exam will receive ZERO marks with no
possibility for re-sits.
7. Appeal. If you are not satisfied with the marks received for this Assessment, you may
appeal for reconsideration by completing the ASSESSMENT APPEAL form (Form 7.3).
All Appeals must be submitted through your lecturer WITHIN 3 DAYS from the receipt
of your assessment result.
8. Refer to your student Handbook for regulations relating To
Resubmission/Reassessment/Retest. These must be applied for WITHIN 3 DAYS from the date
Assessment Feedback is provided by the lecturer. All applications are to be submitted to your
lecturer.

Assessment Instructions:

1. Enter your Student ID number in the space provided Above.


2. Write your student ID and the question number on each extra page, including graph
paper, and enclose it in the book adjacent to the relevant question.
3. CROSS OUT any work that you do not wish to have marked.
4. Show ALL working in calculations to obtain full marks. In any question that does not
ask for numerical answers to a specified accuracy, answers should be rounded
appropriately.
5. Use of Scientific calculators are allowed for this exam.

© International College of Auckland DEE722-A1-V1 Workbook 2


Department of Engineering

1. List the three major components of a computer system.

2. What does RAM stands for? How is it used in computer systems?

3. What does ROM stands for? How is it used in computer systems?

4. Why is RAM called volatile memory?

5. What does CPU stands for? Explain its function in a computer.

6. What does ALU stands for? What is its purpose?

7. Ms. Karrie would like to store some temporary data values in microcontroller. Which memory
can she prefer? RAM/ROM?
8. Ms. Tessa would like to store program instructions in microcontroller. Which memory can she
prefer? RAM/ROM?

Microcontroller Basics:

9. True or false: Microcontrollers are normally less expensive than microprocessors.


10. When comparing a system board based on a microcontroller and a general purpose
microprocessor, which one is cheaper?
11. A microcontroller has which of the following devices on-chip?
a. RAM b. ROM c. I/O b. All of the above
12. A general purpose microprocessor normally needs which of the following devices to be attached
to it?
b. RAM b. ROM c. I/O b. All of the above
13. Explain the main difference between microprocessor and microcontroller.

14. What are the three types of buses in every CPU?

15. Explain the use of three buses with the diagram below.

© International College of Auckland DEE722-A1-V1 Workbook 3


Department of Engineering

16. Is data bus in CPU unidirectional or bidirectional? Why?

17. Ms. Lim’s computer (CPU) has a 16-bit data bus, where as Mr. Lee’s computer (CPU) has a 32-bit
data bus.
a. Which CPU is better/faster in transferring the data? Why?

b. How faster is the fastest computer over the other?

18. Which of the following is not a bus in most computer architectures?


a. Data b. Control c. Operation d. Address

PIC16F887
Pin configuration Sheet

© International College of Auckland DEE722-A1-V1 Workbook 4


Department of Engineering

© International College of Auckland DEE722-A1-V1 Workbook 5


Department of Engineering

© International College of Auckland DEE722-A1-V1 Workbook 6


Department of Engineering

Understanding the PIC16F887

19. Consider that a LED is connected to pin 19. What are the SFRs that need to be configured? Provide
their required value.

20. Consider that a LED is connected to pin 34. What are the SFRs that need to be configured? Provide
their required value.

21. If two push buttons bt1 and bt2 are connected to pin number 5 and 8 respectively, which other
SFRs need to be configured? Provide their required value.

© International College of Auckland DEE722-A1-V1 Workbook 7


Department of Engineering

22. Consider that three analog temperature and humidity sensors are connected to pin 3, 4, and 38.
In this case which other SFRs are required to be configured? Provide their value as well.

23. Consider that a LED is connected to pin 31. Write the SFR and its value to make the LED glow.

24. Consider that a LED is connected to pin 40. Write the SFR and its value to make the LED glow.

25. How many interfaces are available in PIC16F887 for PORTA, PORTB, PORTC, PORTD, PORTE. Name
them and its corresponding pins.

26. Why do we have 2 Vdd and Vss?

© International College of Auckland DEE722-A1-V1 Workbook 8


Department of Engineering

Circuit Design
27. Draw a design circuit diagram with PIC16F887 microcontroller which glows 4 LEDs when the push
button is pressed. Note: PIC16F887 pin diagram is shown below.

© International College of Auckland DEE722-A1-V1 Workbook 9


Department of Engineering

28. Write the MPLABX XC8 program to glow 4 LEDs when the push button is pressed.

29. Draw a design circuit diagram with PIC16F887 microcontroller with 2 LED (L1, L2) and 2 push
buttons (P1, P2). If P1 is pressed, L1 should glow. If P2 is pressed, L2 should grow. If both are not
pressed, no LED should glow.

© International College of Auckland DEE722-A1-V1 Workbook 10


Department of Engineering

30. Write the MPLABX XC8 program to accomplish the task given in Q29.

© International College of Auckland DEE722-A1-V1 Workbook 11


Department of Engineering

Modules in Microcontroller: Brief discussion

Write a brief explanation of uses of the following modules present in the microcontroller.

31. Timer

32. ADC and DAC

33. CCP Modules

34. Serial Synchronous and asynchronous modules

35. CAN interface module

36. Ethernet interface module

37. Parallel ports

© International College of Auckland DEE722-A1-V1 Workbook 12


Department of Engineering

Microcontroller with DC motor

38. Draw a design circuit diagram which rotates the DC motor in one direction when a push button is
pressed. Use PIC16F887 microcontroller for this purpose.

39. Explain the use of BJT in the above circuit

© International College of Auckland DEE722-A1-V1 Workbook 13


Department of Engineering

40. Write a MPLABX XC8 program to accomplish the above task.

© International College of Auckland DEE722-A1-V1 Workbook 14


Department of Engineering

Computer Mathematics Basics:

41. Convert the following decimal numbers to binary:


(a) 12 (b) 123 (c) 3724 (d) 1000

Ans: ________________ __________________ __________________ ________________

42. Convert the following numbers from binary to decimal:


(a) 100100 (b) 111011 (c) 1000100

Ans: _____________________ _______________________ ____________________

Programming basics:

43. Instead of assigning values to each of the SFRs RB0 to RB7, how would you specify using PORTB
SFR?

44. Find the output of the following program.


#include <xc.h>
void main ()
{ Output:
int x=5, y=10;
if(x<y);
printf(“x is less than y”);
}

What is the inference of the above program?

© International College of Auckland DEE722-A1-V1 Workbook 15


Department of Engineering

45. Correct the following program to render the expected output:


#include <xc.h>
Write the correct program here
void main()
{
int i;
for(i=0;i<n;i++)
{
PORTC=i;
}
}
Expected Output in LED

1
1.5
2
2.5
3
3.5
4

46. Write MPLABX XC8 program to print the first 10 integers in 8 LEDs connected to PORTD. Note:
Use ‘for’ loop.

47. List atleast 5 SFRs you have come across in programming the microcontroller.

© International College of Auckland DEE722-A1-V1 Workbook 16


Department of Engineering

PIC16F887 Timers

48. How many timers are there in the PIC16F887?


49. What is the use of timer and counter? Give a real world example.

50. How many bits are there in each timer register in PIC16F887?

51. What is the maximum value that can be represented in the timer register? Explain.

52. What is the frequency of oscillator if the frequency of the timer is 4 MHz?

53. Mr. Rob wants to increase the timer values, but he did not want to compromise/decrease the
frequency of the oscillator. What should he do?

54. Mr. Sam wants to configure his microcontroller as timer instead of counter. How does he do it in
the MPLAB C program?

55. How do you configure the prescalars to be assigned either to ‘TMR0’ or ‘WDT’?

56. What are the possible values that can be chosen as prescalars? What is the maximum value?

57. How does one represent the prescalar value, say 8 in programming the PIC16F887 using Hi-Tech
C Code?

58. What do you do when the prescalar value is above 256?

59. What is the elapsed time when the start of the timer register is 123 with the oscillator
frequency as 16 MHz (no prescalars)?

60. What is the start value of the register when the FOSC is 8 MHz and the elapsed time is 10 μs (no
prescalars)?

© International College of Auckland DEE722-A1-V1 Workbook 17


Department of Engineering

61. Ms. Sim wants to measure the elapsed time of 10 ms with the microcontroller oscillator
frequency 12 MHz. What is the prescalar value that needs to be used?

62. Find the start value of the timer register with the following information. Prescalar (N) = 128,
elapsed time = 13 ms, frequency of oscillator = 10 MHz.

63. Consider the case in which your microcontroller is connected to 10MHz external oscillator. Design
a digital counter that should count from 0 to 60 in 1 min, i.e. every increment should be after 1
second, using PIC16F887 and timer0 module for this purpose. Use a push button to start this
counter and show the values of 0 to 60 by use of 8 LEDs connected to PORT D.

a. What is the frequency of the oscillator in the above question?


b. What is the frequency of the timer?

c. What is the value of Time TOSC?

d. What is the elapsed time from the above question?

e. What is the prescalar (N) required for this code?

f. The prescalar value from the previous question is clearly above 256. What is required to
avoid inaccuracy in the code?

g. Counters: How many counters are required for this operation?

© International College of Auckland DEE722-A1-V1 Workbook 18


Department of Engineering

h. What is the name of the input and output port from the above question?

i. What do you connect to in the input and output port?

j. What is the start value of the timer register TMR0?

k. How do you represent the start of the timer in the XC8 code?

PIC16F887 Timers Formulae and Examples


Formulae:

Step 1: Find the frequency of timer, ftimer

𝑓𝑜𝑠𝑐
𝑓𝑡𝑖𝑚𝑒𝑟 = 4

Step 2: Find the value of time, Ttimer

1
𝑇𝑡𝑖𝑚𝑒𝑟 =
𝑓𝑡𝑖𝑚𝑒𝑟

Step 3: Find the value of prescalar, N

Elapsed Time = N ∗ (B − A + 1) ∗ 𝑇𝑡𝑖𝑚𝑒𝑟

Elapsed time would be given in the question. The value of A is 0 and the value of B is 255.

If the value of N is > 256, then take N = 256.

Step 4: Calculate extra counter, if needed.


(A) If the value of N is less than or equal to 256 (N <= 256), go to step 5
(B) If the value of N is greater than 256, we need an extra counter.

𝑂𝑟𝑖𝑔𝑖𝑛𝑎𝑙 𝑁 𝑣𝑎𝑙𝑢𝑒
𝐸𝑥𝑡𝑟𝑎 𝑐𝑜𝑢𝑛𝑡𝑒𝑟 =
256

Step 5: Tune the timer to exact initial value


(A) If there are NO extra counters, use the following formula to find A.

Elapsed Time = N ∗ (B − A + 1) ∗ 𝑇𝑡𝑖𝑚𝑒𝑟

(B) If there are extra counters, use the following formula to find A.

Elapsed Time = N ∗ C ∗ (B − A + 1) ∗ 𝑇𝑡𝑖𝑚𝑒𝑟

Now the values A, N are found using the above formulae.

© International College of Auckland DEE722-A1-V1 Workbook 19


Department of Engineering

Basic Information:

Timer Timer
0 0
PSA T0CS
1 WDT 1 Counter

Basic Timer Exercises


64. What is the value of PS0, PS1, PS2 if the value of N=128?

65. What is the value of PS0, PS1, PS2 if the value of N=35?

66. How do you assign prescalar to timer rather than watch dog timer? (Note: Use ‘PSA’)

67. How do you choose timer in the circuit rather than a counter? (Note: Use ‘T0CS’)

68. What is T0IF? When is it set?

69. How do you represent the start value of the timer? What value is assigned to it? A or B?

70. How do you choose counter in the circuit rather than a timer? (Note: Use ‘T0CS’)

71. How do you assign prescalar to watch dog timer rather than timer? (Note: Use ‘PSA’)

© International College of Auckland DEE722-A1-V1 Workbook 20


Department of Engineering

Timer Example 1: (without extra counters)

Write a MPLAB Hi-Tech C Program to show the pattern of “OFF OFF OFF OFF OFF OFF OFF OFF” on 8
LEDs connected to PORTC which gets reverse every 13ms. The frequency of the oscillator is 10 MHz.
(Note: Use Timer. Don’t use __delay_ms)

Solution:

fosc= 10 MHz

ftim = fosc/4= 2.5MHz used for Timer0

Ttim= 1/2.5MHz= 0.4us

Elapsed Time= (B – A + 1) * Prescaler * Ttim

=> 13ms = 256 * Prescaler * 0.4us

Prescaler= 126.95 => Prescaler values are discrete values therefore we can select 128

If we want to tune the timer and make it even more accurate we can change the initial value so
that:

13ms=TMR0 x 128 x 0.4us => TMR0= 253.9 => if we choose the initial value of 256-254=2 then
timer would work even more accurate. The last part regarding the accurate calculation is not
expected from the students, however if it is done, shows their better understanding.

© International College of Auckland DEE722-A1-V1 Workbook 21


Department of Engineering

Timer Example 2: (with extra counters)

Write a MPLAB Hi-Tech C Program to show the pattern of “ON ON ON ON ON ON ON ON” on 8 LEDs
connected to PORTD which gets reverse every 1 second. The frequency of the oscillator is 10 MHz.
(Note: Use Timer. Don’t use __delay_ms)

Solution:

The next step is configuring the Timer0 so that it can signal the elapsed time of 1sec. As known
Timer0 works on fosc/4 resulting in

fosc= 10 MHz

ftim = fosc/4= 2.5 MHz

Ttim= 1/2.5MHz= 0.4us

Elapsed Time= (B – A + 1) * Prescaler * Ttim => 1 sec= 256 * Prescaler * 0.4us

Prescaler= 9765.625 => Prescaler values are discrete values and the maximum is 256 therefore
we can select 256 for the prescaler and we need extra counter as well;

Extra Counter= 9765.625/256= 38.14 => Extra Counter=38

If we want to tune the timer and make it even more accurate we can change the initial value so
that:

1sec=(B – A + 1) * 256 * 38 * 0.4us => (B – A + 1) = 256.99 => if we choose the initial value of
0 then timer would work accurate enough.

© International College of Auckland DEE722-A1-V1 Workbook 22


Department of Engineering

Timer Exercises

72. Write a MPLABX XC8 program to show the pattern of “ON OFF ON OFF ON OFF ON OFF” on 8
LEDs connected to PORT C which gets reverse every 250ms. In other words after each 250ms, the
LEDs which were on should get off and vice versa. The frequency of the oscillator is 8 MHz. Show
all the calculations. (Note: Use Timer. Don’t use __delay_ms)

© International College of Auckland DEE722-A1-V1 Workbook 23


Department of Engineering

73. Write a MPLABX XC8 program to show the pattern of “ON OFF OFF OFF ON OFF OFF OFF” on 8
LEDs connected to PORT C which gets reverse every 40ms. In other words after each 40ms, the
LEDs which were on should get off and vice versa. The frequency of the oscillator is 8 MHz. Show
all the calculations. (Note: Use Timer. Don’t use __delay_ms)

© International College of Auckland DEE722-A1-V1 Workbook 24


Department of Engineering

74. Draw a circuit diagram with PIC16F887 to accomplish the following task: 8 LEDs show the pattern
of “ON OFF OFF OFF ON OFF OFF OFF” connected to PORT C which gets reverse every 40ms.

PIC16F887 – Analog to Digital Conversion

Preview Questions:

75. Where does the result of ADC get stored?

76. What is the length (in bits) of the output of analog to digital conversion?

77. What is the value of ADFM if the ADRESH, ADRESL values to be


a. Right Justified?
b. Left Justified
78. What is the value of ADCS1, ADCS0, if the clock frequency is Fosc/2?

79. What is the value of ADCS1, ADCS0, if the clock frequency is Fosc/32?

80. What is the value of CHS3 – CHS0 if the analog channel 7 is used?

© International College of Auckland DEE722-A1-V1 Workbook 25


Department of Engineering

81. What is the value of CHS3 – CHS0 if the analog channel 12 is used?

82. How many analog channels are available in PIC16F887?

83. What is the value of ANSEL, ANSELH if the ADC uses analog channel 10?

84. What is the value of ANSEL, ANSELH if the ADC uses analog channel 13?

85. What is the use of ADON bit?

86. What is the value of ADCON0 register if the clock frequency is Fosc/32 and uses analog channel 9?

87. What is the value of ADCON0 register if the clock frequency is Fosc/8 and uses analog channel 6?

88. What is the value of ADCON1 register if the conversion result is right justified?

89. What is the value of ADCON1 register if the conversion result is left justified?

90. The output of my ADC is 0b1101100010. What is the value of ADRESH and ADRESL, if the values
are right justified?

91. The output of my ADC is 0b1100111011. What is the value of ADRESH and ADRESL, if the values
are left justified?

92. Explain the following


c. ADIF
d. ADIE
e. PEIE
f. GIE

93. When is the value of ADIF set to 1?

© International College of Auckland DEE722-A1-V1 Workbook 26


Department of Engineering

Example ADC Program


94. Write a MPLAB Hi-Tech C Program to convert the values of potentiometer from analog to digital.
Use the jumpers on PIC16F887 development kit so that potentiometer is connected to AN0
channel. The clock frequency is Fosc/32. The frequency of the oscillator is 10MHz. Burn the code
on the microcontroller and show your progress to the instructor. Write a summary of the steps
required for that purpose. (Note: Use the lecture notes to understand the 7 steps involved in ADC
module).

#include <htc.h>
__CONFIG(WDTE_OFF & CP_OFF & MCLRE_OFF & LVP_OFF);
#define _XTAL_FREQ 10000000

void main()
{
ANSEL = 0b00000001;
ANSELH = 0;
TRISA=0x1;
TRISB = 0x0;
TRISC = 0x0;
ADCON0=0b10000001; //ADON=1, CH=0
ADCON1=0b10000000; //ADFM=1, VCFG0=0, VCFG1=0
ADIE = 1;
ADIF = 0;
PEIE = 1;
GIE = 1;

while(1)
{
__delay_us(20);
GODONE=1;
}
}

void interrupt ISR()


{
if (ADIF = = 1) //GODONE=0
{
PORTB=~ADRESL;
PORTC=~ADRESH;
ADIF=0;
}
}

Notes:

© International College of Auckland DEE722-A1-V1 Workbook 27


Department of Engineering

95. Draw a circuit diagram to accomplish the task given in Question 1

ADC Programming - Exercise


96. Write a MPLAB Hi-Tech C Program to convert the values of potentiometer from analog to digital.
Use the jumpers on PIC16F887 development kit so that potentiometer is connected to AN3
channel. The clock frequency is Fosc/8. The frequency of the oscillator is 8MHz. Burn the code on
the microcontroller and show your progress to the instructor. Write a summary of the steps
required for that purpose.

© International College of Auckland DEE722-A1-V1 Workbook 28


Department of Engineering

© International College of Auckland DEE722-A1-V1 Workbook 29


Department of Engineering

Understanding the PIC16F887 Datasheet (Beginner)

97. What is the EEPROM and flash endurance of PIC16F887?

98. All PIC microcontrollers use Harvard architecture. True or False?


99. Function of each PORTA pin can be changed using TRISA register in PIC16F887. True or False?
100. The data memory in PIC16F887 is partitioned into ________ banks
101. How many I/O pins are available in PIC16F887? Compare it to PIC16F882/883/884/886.

102. What is the name of the module used to convert the digital to analog signal?

103. List the bits of INTCON register in PIC16F887 and its uses.

104. List the bits in the TRISB – PORTB Tri-state register.

105. What are the 8 modes in which the Oscillator be configured to?

© International College of Auckland DEE722-A1-V1 Workbook 30


Department of Engineering

106. Explain the differences between TMR0 and TMR1 interms of bits, prescalar, clock source,
etc.

TMR0 TMR1

107. Explain the differences between TMR0 and TMR2 interms of bits, prescalar, clock source,
etc.

TMR0 TMR2

© International College of Auckland DEE722-A1-V1 Workbook 31


Department of Engineering

108. Compare RISC and CISC along with an example for each.
RISC CISC

109. Please find below two CPU architectures, ‘a’ and ‘b’. Please specify the advantages and its
disadvantages.

Name: Von Neumann Architecture Harvard Architecture

Advantages: Advantages:

Disadvantages: Disadvantages:

© International College of Auckland DEE722-A1-V1 Workbook 32


Department of Engineering Student ID:

110. Explain the use of control unit.

111. Explain the difference between pipelined and non-pipelined instruction based on the figure
shown below.

112. Explain the multi-core processing or the multi-core technology.

113. Explain the concept of simultaneous multithreading

© International College of Auckland DEE722-A1-V1 TEST 1 33


Department of Engineering Student ID:

114. Compare the following three communication modules: parallel ports, serial synchronous and
asynchronous modules in PIC16F887 and PIC16F877

115. Compare the following three special function modules: serial peripheral ports, CAN interface
and Ethernet interface module in PIC16F887 and PIC16F877

© International College of Auckland DEE722-A1-V1 TEST 1 34


Department of Engineering Student ID:

Post Assessment Feedback Form


Student Name Student ID

Intake Month
Paper
and Year

Marks / Grade awarded

Assessor Comments

Assessor Name Date:

I confirm that the Assessor: Yes No

Ensured the resources , required for the assessment

Ensured that Health and Safety requirements are fulfilled

Provided and explained results to me appropriately

 I understand that I have three working days from the date I sign this form to apply to my lecturer
/ assessor for a recount/reconsideration OR a resit / resubmission, and that my eligibility to apply
for this is subject to the regulations of the programme / paper / unit standard I am enrolled into.
(Refer to relevant Course Outline and student handbook).
 I understand that I am not entitled to a resit for a Final Exam.
 I understand that I may be contacted in relation to this assessment, and that this assessment may
be used for external post-assessment moderation purposes.
 I understand that my results are not final until post-assessment moderation and ratification
processes are completed.

Student Signature: Date:

© International College of Auckland DEE722-A1-V1 TEST 1 35


Department of Engineering Student ID:

© International College of Auckland DEE722-A1-V1 TEST 1 36

You might also like