Uploaded by Utkir Hamdamov

Auxillary hardware of MC

advertisement
AUXILIARY HARDWARE OF
MICROCONTROLLERS (1)
Lecturer: Utkir Khamdamov
E-mail: utkir.hamdamov@gmail.com
Resources
• https://learn.mikroe.com/ebooks/8051programming/chapt
er/counters-and-timers/
• https://www.tutorialspoint.com/embedded_systems/es_tim
er_counter.htm
• KRISHNA KANT
• MICROPROCESSORS AND MICROCONTROLLERS:
ARCHITECTURE, PROGRAMMING AND SYSTEM
DESIGN
Microcontroller Architecture
Auxiliary Elements of Microcontrollers
• In this session, we look at some of the hardware
required to run a microprocessor
• " Generator" - Power Circuitry
• " Conductor" - Oscillators
• " Alarm Clock" - Reset Circuit
" Generator" - Power Circuitry
• Power Circuitry of a 64-Pin
RL78 Family (RL78/G14) MCU
• An MCU, like any of its various
components introduced in Digital
Circuits, needs a power supply to
drive it. So it must be connected to
an outside battery or other suitable
power source
• Pins 13 (VSS) and 14 (EVSS0) to
GND.
• Pins 15 (VDD) and 16 (EVDD0) to
power supply.
• Power voltage (VDD) must be
between 1.6 and 5.5 V.
" Conductor" - Oscillators
• Sequential circuits operate in sync with the rising or falling edge of a clock (CK)
signal. MCUs consist of sequential circuits, and so they require a CK signal.
• A crystal oscillator is connected to pins X1 and X2. The MCU includes two internal
clock oscillators that work in conjunction with the external clock signal.
• The main clock drives the CPU. The sub-clock is typically used with peripheral
circuits or as a real-time clock.
"Alarm Clock" - Reset Circuit
• The signal into the reset input pin
must remain LOW until the powersupply and clock signals stabilize
• In static start addressing mode, the
MCU always starts program execution
at the same fixed address. The
address itself is different for each
MCU model.
• If the PC value is 0, for example, then
program execution will start with the
instruction at address 0.
Timer/Counter
• A timer is a specialized type of clock which is used to measure time
intervals. A timer that counts from zero upwards for measuring time
elapsed is often called a stopwatch. It is a device that counts down
from a specified time interval and used to generate a time delay, for
example, an hourglass is a timer.
• A counter is a device that stores (and sometimes displays) the
number of times a particular event or process occurred, with respect
to a clock signal. It is used to count the events happening outside the
microcontroller. In electronics, counters can be implemented quite
easily using register-type circuits such as a flip-flop.
Difference between Timer and Counter
Timer
Counter
The register incremented for every
machine cycle.
The register is incremented
considering 1 to 0 transition at its
corresponding to an external input pin
(T0, T1).
Maximum count rate is 1/12 of the
oscillator frequency.
Maximum count rate is 1/24 of the
oscillator frequency.
A timer uses the frequency of the
internal clock, and generates delay.
A counter uses an external signal to
count pulses.
Timers of 8051 and their Associated
Registers
• The 8051 has two timers,
• Timer 0 and Timer 1
• They can be used as
• timers or as event counters.
• Both Timer 0 and Timer 1 are 16-bit wide.
• 8051 follows an 8-bit architecture, each 16 bit is
accessed as two separate registers of
• low-byte and high-byte
TIMERS / COUNTERS
- Four-SFR’s connected with TIMER/COUNTER operation
- TMOD – Timer Mode Register
- TCON – Timer Control Register
- TH0, TL0 – Timer/Counter - 0
- TH1, TL1 – Timer/Counter - 1
- Two pins of 8051 connected with Timer/counter.
• T0 – Timer 0 external input – P3.4
• T1 – Timer 1 external input – P3.5
• INT0 and INT1 are also used for controlling the
timer/counters.
Timer 0 Register
• The 16-bit register of Timer 0 is accessed as
• low-byte and high-byte
• The low-byte register  TL0 (Timer 0 low byte)
• The high-byte register  TH0 (Timer 0 high byte)
• Example: the instruction MOV TL0, #4H moves the value
into the low-byte of Timer #0.
Timer 1 Register
• The 16-bit register of Timer 1 is accessed as
• low-byte and high-byte
• The low-byte register  TL1 (Timer 0 low byte)
• The high-byte register  TH1 (Timer 0 high byte)
• Example: the instruction MOV TL1, #4H moves the value
into the low-byte of Timer #0.
TMOD (Timer Mode) Register
• Timer 0 and Timer 1 use the same register to set the various timer operation
modes.
• It is an 8-bit register in each case, the lower 2 bits are used to set the timer
mode in advance and the upper 2 bits are used to specify the location.
• Gate − When set, the timer only runs while INT(0,1) is high.
• C/T − Counter/Timer select bit.
• M1 − Mode bit 1.
• M0 − Mode bit 0.
Timer Mode (GATE)
• Every timer has a means of starting and stopping
• The start and stop of a timer is controlled by software
using the instruction
• SETB TR1 and CLR TR1 for timer 1
• SETB TR0 and CLR TR0 for timer 0
• The SETB instruction is used to start
• The CLR instruction is used to stop
• These instructions start and stop the timers as long as
GATE = 0 in the TMOD register.
• Timers can be started and stopped by an external source
by making GATE = 1 in the TMOD register.
Timer Mode (Counter/Timer) – C/T
• This bit in the TMOD register is used to decide whether a
timer is used as
• a delay generator
• or
• an event manager.
• If C/T = 0, it is used as a timer for timer delay generation.
• The clock source to create the time delay is the crystal
frequency of the 8051.
Timer Operation
• Timer Register (TH0, TL0 or TH1, TL1) incremented every m/c
cycle. Thus working at increment frequency of 1/12 of oscillator
frequency (for 12 oscillator machine cycle).
• For Example – Clock frequency = 12 MHZ
• Clock period = 1/12 µ sec
• Machine cycle time = 1 µ sec
• Thus timer register will be incremented every microsecond.
• If timer is initialized to 0000H
• Max. count = FFFFH
max. time measured = 216 µ sec
= 26 x 210 µ sec
≈ 26 millisecond
≈ 64 millisecond
= 65.5 millisecond
Counter Operation
• Counts pulses occurring at T0 pin (Timer/Counter 0)
and/or T1 pin (Timer/counter 1).
• May correspond to event like
 Passing of railway coach from a point – axle counter
 Rotation of speedometer cable – speedometer of vehicle
• T0, T1 scanned every m/c cycle
 nth m/c cycle – T1 or T0 = High
 (n+1)th m/c – T1 or T0 = Low
 Timer 0 or timer 1 incremented in (n+1)th m/c cycle
• Count frequency = min 2 m/c cycle per count
 T0- P3.4, T1- P3.5
Timer Mode (M1 / M2)
M1
M2
Mode
Description
0
0
0
13-bit timer mode.
0
1
1
16-bit timer mode.
1
0
2
8-bit auto reload mode.
1
1
3
Spilt mode.
Bits of Registers
• GATE0 enables and disables Timer 0 by means of a signal
brought to the INT0 pin (P3.3):
• 1 – Timer 0 operates only if the INT0 bit is set.
• 0 – Timer 0 operates regardless of the logic state of the INT0 bit.
• C/T1 selects pulses to be counted up by the timer/counter 1:
• 1 – Timer counts pulses brought to the T0 pin (P3.5).
• 0 – Timer counts pulses from internal oscillator.
• T0M1,T0M0 These two bits select the operational mode of the
Timer 0.
Timer Control (TCON) Register
• TF1 bit is automatically set on the Timer 1 overflow.
• TR1 bit enables the Timer 1.
• 1 – Timer 1 is enabled.
• 0 – Timer 1 is disabled.
• TF0 bit is automatically set on the Timer 0 overflow.
• TR0 bit enables the timer 0.
• 1 – Timer 0 is enabled.
• 0 – Timer 0 is disabled.
Timer 0 in mode 0 (13-bit timer)
• This mode configures timer 0 as a 13-bit timer which consists of all 8 bits of TH0 and
the lower 5 bits of TL0. As a result, the Timer 0 uses only 13 of 16 bits.
• Each coming pulse causes the lower register bits to change their states. After receiving
32 pulses, this register is loaded and automatically cleared, while the higher byte
(TH0) is incremented by 1. This process is repeated until registers count up 8192
pulses. After that, both registers are cleared and counting starts from 0.
Timer 0 in mode 1 (16-bit timer)
• Mode 1 configures timer 0 as a 16-bit timer comprising all the bits of both registers
TH0 and TL0. That’s why this is one of the most commonly used modes. Timer
operates in the same way as in mode 0, with difference that the registers count up to
65 536 as allowable by the 16 bits.
Timer 0 in mode 2 (Auto-Reload Timer)
• Mode 2 configures timer 0 as an 8-bit timer. Actually, timer 0 uses only one 8-bit
register for counting and never counts from 0, but from an arbitrary value (0-255)
stored in another (TH0) register.
Timer 0 in Mode 3 (Split Timer)
• Mode 3 configures timer 0 so that registers TL0 and TH0 operate as separate 8-bit
timers. In other words, the 16-bit timer consisting of two registers TH0 and TL0 is split
into two independent 8-bit timers. This mode is provided for applications requiring an
additional 8-bit timer or counter. The TL0 timer turns into timer 0, while the TH0 timer
turns into timer 1
Thank you for Attention !
Download