You are on page 1of 6

Q1-Sec-2- Assume that a microcontroller has a 24 bits

timer with Fosc = 200MHz and four pre-scalar options


(1, 32, 64, and 128). Answer the following:

1. What is the maximum time delay that can be


achieved using such a timer? [15PTS]
Fosc/2=200MHz/2 = 100MHz
Tcy =1/100MHz=0.01usec
Max period = 0.01usec * 224 = 167.77 msec
Max pre-scalar=128
Max time delay = 167.77*128=21.47456 sec

2. If the TFLY is 100 cycles and the pre-scalar is


maximum, what is the Tdelay? [15PTS]
100= T *200MHz/2/128
(100*2*128)/200MHz= 25600/200usec
= 128 usec

3. If timer PR = 65536, what is the minimum and maximum time delay that can be achieved using
this timer? [15PTS]
Minimum delay (Pre-scalar=1) = 65536*2/200MHz= 655.36 usec
Maximum delay (Pre-scalar=128) = 65536*2*128/200MHz= 83.886 msec

Q2-Sescion 2: An input signal is to be captured by Input Capture IC1 and based on the signal period
Output Compare OC2 will generate an output pulse with the same value. Assume that the
microcontroller has a 16 bits timer system. The Initialize reference Timer, input capturer and output
compare registers as well as buffers are shown below:

FOSC = 40MHz

PR2 = 0xFFFF IC1BUF

T2CON = 0X8020 0x3A98 0xEDCB

PR3 = 0xFFFF

T3CON = 0X8020

IC1CON = 0X20E3

OC2CON = 0X000E

OC2R = 0x0000
1. List the settings of the Input Capture IC1 module [5pts]
Discontinue in idle mode
Timer 2 based
Interrupt at the forth capture event
Capture at each rising edge

2. What is the maximum period the system can capture without a timer rollover with the given
timer settings [10pts]?

Fosc/2=40MHz/2 = 20MHz
Tcy =1/20MHz=0.05usec
Max period = 0.05usec * 216 = 3.2768 msec
Pre-scalar= 64
Max captured period = 3.2768msec*64=209.7152 msec
3. Calculate the period of the signal captured by IC1. Draw and label the captured signal [20pts].
Period in cycles=0xEDCB-0x3A98=0xB333=45875 cycles
Period in seconds=45875*2*64/40MHz= 146.8 msec

4. Calculate the period and the duty cycle of the generated signal by OC2. Draw and label the
generated signal [20pts].

Period = Maximum period with Pe-scalar =209.7125 msec

Duty cycle= 146.8/209.7125= 70%


Q1-Sec-1 : Assume that a microcontroller has a Timer1 shown in the figure below. Timer1 is set to
operate under the specified initialized condition and bits size for TMR1 and PR1 registers, calculate the
following:

 What is the maximum time delay that can be achieved by this timer with the settings shown in
the figure [15pts]?

Fosc/2=8MHz/2 = 4MHz

Tcy =1/4MHz=0.25usec

Max period = 0.25usec * 212 = 1.024 msec

Max pre-scalar=64

Max time delay =1.024m*64=65.536 msec

 If the Tfly = 1024 cycles, what is the Tdelay that can be achieved with minimum pre-scalar and
the settings shown in the figure [20pts]?

1024= T *8MHz/2/2

(1024*2*2)/8MHz= 4096/8usec

= 512 usec
 If you want to run the timer as fast as it can, which of the control bits you should change: name
them and list their setting in such case [15Pts].
TCS=0
TGATE=0
TCKPS1=1
TCKPS0=1

Q2-Sec-1:

A signal is to be generated by Output Compare OC2. Assume that the microcontroller has a 16 bits timer
system. The Initialize reference Timer, and output compare are shown below:

Fosc = 80MHz

TMR3 = 0X0000

PR3 = 0X5000

T3CON = 0X8010

PR2 = 0XFFFF

T2CON = 0X8030

OC2CON = 0X200E

OC2R = 0X0000

OC2RS = 0X1000

1. List the settings of the Output Compare OC2 module [5pts]

Discontinue in idle mode

Timer 3 based

PWM Mode

2. Calculate the period and duty cycle of the generated signal [15pts]

Period in cycles=0x5000=20480

20480= T *80MHz/2/8

(20480*2*8)/80MHz= 25600/80usec

= 4096 usec
High pulse in cycles=0x1000=4096

4096= T *80MHz/2/8

(4096*2*8)/80MHz= 65536/80usec

=819.2 usec

Duty cycle=20%

3. Draw the output signal [10pts]

4. Assume the same signal is to be captured using Input Capture 1 IC1 based on timer 2. Develop
the initialize function to read the generated signal period and duty cycle. You should use the
output specifications for the initialization [20 pts].

void nitIC(void){
IC1CON=0x0000;
IC1CONbits.ICSIDL=0;
IC1CONbits.ICTMR=0b1;
IC1CONbits.ICI=0b00;
IC1CONbits.ICM=0b001;
IPC0bits.IC1IP=1;
IFS0bits.IC1IF=0;
IEC0bits.IC1IE=1;
}

Alternative question: Assume the same signal high time (ON pulse width) is to be calculated using Input
Capture 1 IC1 with IC1CON= 0X2081. Calculate the value of IC1BUF after the first 2 capture events
assuming that both timers, IC1 and OC2 were initialized and started at the same time [20 pts].

ON pulse width= 819.2 usec

On pulse in cycles =819.2 usec *80MHz/2/256=128

IC1BUF

0x0000 0x0080

You might also like