Microcontrollers and Its Applications: Shivaum Heranjal L27+28 17BEC0315 Padmini T N
Microcontrollers and Its Applications: Shivaum Heranjal L27+28 17BEC0315 Padmini T N
Lab Task 4
Note: Calculations for time delay and the general format of the control
register used in the program should be specified.
Soln.
First we calculate the initial values for both the timers:
We use both the timers in mode 1(16-bit timer mode) where TH and TL are
cascaded.
Desired frequency of wave generated by Timer 0= 500Hz; i.e time period=1/500=2ms
Desired frequency of wave generated by Timer 1= 7kHz,
i.e time period=1/7000=0.14286ms
In mode 1,
(65535 − X + 1) * 1.085u = delay (where X is the value with which timer
will be initialised)
delay
⇒ (65535 − X + 1) = 1.085u
● TCON-8 bit register which determines when the timers 0/1 are set on/off(TR0
and TR1), also consists of timer overflow flags(TF0 and TF1) and lower 4 bits
control interrupt bits. In our program, we assign a high bit to TR0 and TR1 to
start the timers.
PROGRAM:
Result:-
Green-P1.0; Blue-P1.1
Port Desired Desired Obtained Obtained
Frequency Time Period Frequency Time Period
P1.0 500Hz 2ms 497.62Hz 2.00955ms
P1.1 7kHz 0.14286ms 6.678kHz 0.14974ms
Inference:-
Since there are other instructions which take up machine cycles to
execute, the practical delay is more than what is required. To combat
this, we can take the aforementioned extra delay into account and
tweak the initial values of the timers to get more closer to the desired
frequency square waves.