Search This Blog

Monday, November 14, 2011

TMOD register

As we know there are 2 timer registers in 8051. Timer 0 and timer 1. Both of these registers use the same register called TMOD to set various timer operation modes.

TMOD is an 8 bit register, in which lower 4 bits are for Timer 0 and upper 4 bits are for Timer 1.

See table below. MSB ---- LSB
GATE
C/T
M1
M0
GATE
C/T
M1
M0
TIMER 1
TIMER 0

GATE
Gating control when set. The timer/counter is enabled only while the INTx pin is high and TRx control pin is set. When cleared, the timer is enabled whenever TRx control pin is set.
C/T
Timer or counter; 0 or  clear for timer operation.(connected to input from internal system clock). 1 or set for counter operation(connected to input from Tx input pin).
M1
Mode bit 1
M0
Mode bit 0

What the heck is M1 and M0??

M0 and M1 select the timer mode in TMOD. 4 modes as mode 0, mode 1, mode 2, mode 3. See table.
M1
M0
MODE
OPERATING MODE
0
0
MODE 0
13 bit timer mode
8-bit timer/counter THx with TLx as 5 bit prescaler
0
1
MODE 1
16 bit timer mode.
16 bit timer/counter THx and TLx are cascaded with no prescaler.
1
0
MODE 2
8 bit auto reload.
8 bit auto reload timer/counter  THx holds a value that’s to be reloaded in TLx each time it overflows.
1
1
MODE 3
Split timer mode

C/T (clock/timer) in TMOD
  •  This bit in TMOD register is used to know whether it is used as a delay generator or as an event counter. 
  •  C/T = 0, then it is used as a timer for time delay generation. The clock source for the time delay is the crystal frequency of 8051. Timer gets pulses from the crystal.
  • C/T = 1, then it is used as a counter and gets its pulses from outside the 8051. That is from pins T0 and T1 belonging to port 3. In case of timer 0, when C/T = 1 pin 3.4 provides the clock pulse and counter counts up for each clock pulse coming from that pin. Similarly for timer 1, when C/T = 1 pin 3.5 provides the clock pulse and counter counts up for each clock pulse coming from that pin.

GATE – IN-- TMOD
  • One of the bit of TMOD is GATE bit. What does this GATE thingy do or whats its purpose on this heavenly earth and in our pretty little microcontroller??
  • Every timer has means of starting and stopping. This can be achieved either by software or by hardware or by both. 8051 gives us facility of both.
  • 8051 the start and stop of timer is controlled by way of software by TR(timer start) bits TR0 and TR1, using instructions :
  • SETB TR1
  • CLR TR1
  • For timer 1 and for timer 0:
  • SETB TR0
  • CLR TR0.
  • The software start and stop is achieved when GATE = 0 in TMOD register.
  • When GATE = 1 in TMOD register it means hardware control.  Its preferable to use GATE = 0 for most of the time.

Values of TMOD to operate as timers in following mode.
Mode 1 timer 1  0001 0000 = 10h
Mode 2 timer 0, mode 2 timer 1 0010 0010 = 22h
 
Note whatever the frequency of crystal is timer will always function at 1/12 th of the crystal frequency.

Power saving modes of operation of 8051

Well this mode basically includes saving energy during idle time of processor and during power down time of processor. These are utmost importance in making power saving devices.

Idle mode
  • Idle mode or sleep mode is when core of CPU is put to sleep while all on chip peripherals are on Such as timers, serial port and interrupts.
  • In this mode oscillator continues providing clock to serial port, timer, interrupt, but no clock is provided to the CPU.
  • Notice that during this mode all the register and RAM contents remain unchanged.

Power down mode
  • In power down mode the on chip oscillator is frozen which cuts of frequency to the CPU and the Peripheral functions such as timer, serial ports and interrupts.
  • This mode brings power consumption down to an absolute minimum and the contents of RAM and registers are saved and remain unchanged.

What is embedded processor??

Embedded processors can be broken into two broad categories: ordinary microprocessors (μP) and microcontrollers (μC), which have many more peripherals on chip, reducing cost and size. Contrasting to the personal computer and server markets, a fairly large number of basic CPU architectures are used; there are Von Neumann as well as various degrees of Harvard architectures, RISC as well as non-RISC and VLIW; word lengths vary from 4-bit to 64-bits and beyond (mainly in DSP processors) although the most typical remain 8/16-bit. Most architectures come in a large number of different variants and shapes, many of which are also manufactured by several different companies.


An embedded system is a computer system designed to do one or a few dedicated and/or specific functions often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs. Embedded systems control many devices in common use today.

Embedded systems contain processing cores that are typically either microcontrollers or digital signal processors (DSP). The key characteristic, however, is being dedicated to handle a particular task. They may require very powerful processors and extensive communication, for example air traffic control systems may usefully be viewed as embedded, even though they involve mainframe computers and dedicated regional and national networks between airports and radar sites (each radar probably includes one or more embedded systems of its own).

Since the embedded system is dedicated to specific tasks, design engineers can optimize it to reduce the size and cost of the product and increase the reliability and performance. Some embedded systems are mass-produced, benefiting from economies of scale.

Physically  embedded systems range from portable devices such as digital watches and MP3 players, to large stationary installations like traffic lights, factory controllers, or the systems controlling nuclear power plants. Complexity varies from low, with a single microcontroller chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or enclosure.

In general, "embedded system" is not a strictly definable term, as most systems have some element of extensibility or programmability. For example, handheld computers share some elements with embedded systems such as the operating systems and microprocessors that power them, but they allow different applications to be loaded and peripherals to be connected. Moreover, even systems that do not expose programmability as a primary feature generally need to support software updates. On a continuum from "general purpose" to "embedded", large application systems will have subcomponents at most points even if the system as a whole is "designed to perform one or a few dedicated functions", and is thus appropriate to call "embedded".

SFR (Special function registers) and their addresses

Registers R0-R7 are part of 128 bytes of RAM in microcontroller. Similarly registers A, B, PSW and DPTR are part of group of register known as SFR(special function registers) they have their own addresses too. They are usually accessed by their name as it is much easier. For example register A has address E0h B has F0h and so on.
See the examples.
MOV  0E0H, #55H; is same as
MOV A, #55H; which means load 55H into A

2 points need to be kept in mind.
  1. First special function register have their addres between 80h to FFh. These addresses are above 80h as addresses 00h to 7Fh are addresses of RAM memory inside 8051.
  2. Second, not all addresses between 80h to FFh are used by SFR. The unused location should not be used by a programmer.

Below * means bit addressable
Special function register addresses
Symbol
Name
Address
ACC*
Accumulator
0E0h
B*
Register B
0F0h
PSW*
Program Status word
0D0h
SP
Stack Pointer
81h
DPTR
Data pointer  2 bytes

DPL
Low byte
82h
DPH
High byte
83h
P0*
Port 0
80h
P1*
Port 1
90h
P2*
Port 2
0A0h
P3*
Port 3
0B0h
IP*
Interrupt priority control
0B8h
IE*
Interrupt enable control
0A8h
TMOD
Timer/counter mode control
89h
TCON
Timer/counter control
88h
T2CON
Timer/counter 2 control
0C8h
T2MOD
Timer/counter 2  mode control
0C9h
TH0
Timer/counter 0 high byte
8Ch
TL0
Timer/counter 0 low byte
8Ah
TH1
Timer/counter 1 high byte
8Dh
TL1
Timer/counter 1 low byte
8Bh
TH2
Timer/counter 2 high byte
0CDh
TL2
Timer/counter 2 low byte
0CCh
RCAP2H
T/C 2 capture register high byte
0CBh
RCAP2L
T/C 2 capture register low byte
0CAh
SCON*
Serial control
98h
SBUF
Serial data buffer
99h
PCON
Power control
87h


Tuesday, November 8, 2011

Time, Calendar, and Alarm Data Modes—Binary Mode (DM = 1)

Time, Calendar, and Alarm Data Modes—Binary Mode (DM = 1)

Time, Calendar, and Alarm Data Modes—BCD Mode (DM = 0)Time, Calendar, and Alarm Data Modes—BCD Mode (DM = 0)

Time, Calendar, and Alarm Data Modes—BCD Mode (DM = 0)

Real Time Clock (DS12887, DS12885)

General Description

The DS12885, DS12887, and DS12C887 real-time clocks (RTCs) are designed to be direct replacements for the DS1285 and DS1287. The devices provide a real-time clock/calendar, one time-of-day alarm, three maskable interrupts with a common interrupt output, a programmable square wave, and 114 bytes of battery backed static RAM (113 bytes in the DS12C887 and DS12C887A). The DS12887 integrates a quartz crystal and lithium energy source into a 24-pin encapsulated DIP package. The DS12C887 adds a century byte at address 32h. For all devices, the date at the end of the month is automatically adjusted for months with fewer than 31 days, including correction for leap years. The devices also operate in either 24-hour or 12-hour format with an AM/PM indicator. A precision temperature-compensated circuit monitors the status of VCC. If a primary power failure is detected, the device automatically switches to a backup supply. A lithium coin-cell battery can be connected to the VBAT input pin on the DS12885 to maintain time and date operation when primary power is absent. The device is accessed through a multiplexed byte-wide interface, which supports both Intel and Motorola modes.

Application

Embedded Systems
Utility Meters
Security Systems
Network Hubs, Bridges, and Routers

More Info

The DS12885 family of RTCs provide 14 bytes of realtime clock/calendar, alarm, and control/status registers and 114 bytes (113 bytes for DS12C887 and DS12C887A) of nonvolatile, battery-backed static RAM. A time-of-day alarm, three maskable interrupts with a common interrupt output, and a programmable squarewave output are available. The devices also operate in either 24-hour or 12-hour format with an AM/PM indicator. A precision temperature-compensated circuit monitors the status of VCC. If a primary power-supply failure is detected, the devices automatically switch to a backup supply. The backup supply input supports a primary battery, such as lithium coin cell. The devices are accessed through a multiplexed address/data bus that supports Intel and Motorola modes.

Functional Diagram

Functional Diagram

Oscillator circuit

Oscillator Circuit
The DS12885 uses an external 32.768kHz crystal. The oscillator circuit does not require any external resistors or capacitors to operate. Table 1 specifies several crystal parameters for the external crystal. Figure 1 shows a functional schematic of the oscillator circuit. An enable bit in the control register controls the oscillator. Oscillator startup times are highly dependent upon crystal characteristics, PC board leakage, and layout. High ESR and excessive capacitive loads are the major contributors to long startup times. A circuit using a crystal with the recommended characteristics and proper layout usually starts within one second. An external 32.768kHz oscillator can also drive the DS12885. In this configuration, the X1 pin is connected to the external oscillator signal and the X2 pin is left unconnected.