Showing posts with label counter. Show all posts
Showing posts with label counter. Show all posts

Tuesday, July 9, 2013


TIMING 

  • If a counter is programmed to be a timer, it will count the internal clock frequency of the 8051 oscillator divided by 12d. 
  • As an example, if the crystal frequency is 6.0 megahertz, then the timer clock will have a frequency of 500 kilohertz.
  • The resultant timer clock is gated to the timer by means of the circuit shown in Figure. 
  • In order for oscillator clock pulses to reach the timer, the C/(T)' bit in the TMOD register must be set to 0 (timer operation). 
  • Bit TRX in the TCON register must be set to 1 (timer run), and the gate bit in the TMOD register must be 0, or external pin (INTX)' must he a 1. 
  • In other words, the counter is configured as a timer, then the timer pulses are gated to the counter by the run bit and the gate bit or the external input bits (INTX)'

 

COUNTING

  • The only difference between counting and timing is the source of the clock pulses to the counters. When used as a timer, the clock pulses are sourced from the oscillator through the divide-by-12d circuit.
  • When used as a counter, pin T0 (P3.4) supplies pulses to counter 0. and pin T1 (P3.5) to counter 1.
  • The C/(T)' bit in TMOD must be set to 1 to enable pulses from the TX pin to reach the control circuit shown in above Figure .
  • The input pulse on TX is sampled during P2 of state 5 every machine cycle. A change on the input from high to low between samples will increment the counter.
  • Each high and low state of the input pulse must thus be held constant for at least one machine cycle to ensure reliable counting. Since this takes 24 pulses, the maximum input frequency that can be accurately counted is the oscillator frequency divided by 24. for our 6 megahertz crystal. the calculation yields a maximum external frequency of 250 kilohertz.





Monday, July 8, 2013

Counters and Timers

Many microcontroller applications require the counting of external events, such as the frequency of a pulse train, or the generation of precise internal time delays between com­puter actions. Both of these tasks can be accomplished using software techniques, but software loops for counting or timing keep the processor occupied so that other, perhaps more important, functions are not done. To relieve the processor of this burden, two 16-bit up counters, named T0 and T1, are provided for the general use of the programmer. Each counter may be programmed to count internal clock pulses, acting as a timer, or pro­grammed to count external pulses as a counter. 


 

TCON(TIMER/COUNTER CONTROL REGISTER)
  1. To control the timer/counter we need TCON register.
  2. its bit addressable
  3. address:88h
 

TMOD(THE TIMER MODE CONTROL REGISTER)
  1. it dedicated two timer.
  2. it is byte addressable
  3. address:89h
 

Timer Mode
The timers may operate in anyone of four modes that are determined by the mode bits, M I and MO, in the TMOD register. Figure 12 shows the four timer modes.

Timer Mode 0

  • Setting timer X mode bits to 00b in the TMOD register.
  • theTHX register as an 8-bit counter and TLX as a 5-bit counter.
  • As an example, the 6 megahertz oscillator frequency would result in a final frequency to TH of 15625 hertz. 
  • The timer flag is set whenever THX goes from FFh to 00h

Timer Mode 1

  • the mode bits are set to 0lb in TMOD
  • Mode 1 is similar to mode 0 except TLX is configured as a full 8-bit counter when .

Timer Mode 2

  • Setting the mode bits to l0b in TMOD configures.
  • the timer to use only the TLX counter as an 8-bit counter. 
  • THX is used to hold a value that is loaded into TLX every time TLX overflows from FFh to 00h. The timer flag is also set when TLX overflows.
  • This mode exhibits an auto-reload feature: TLX will count up from the number in THX. overflow. and be initialized again with the contents of THX.

Timer Mode 3

    • Timer 1 in mode-3 simply holds its count. The effect is same as setting TR1=0. Timer0 in mode-3 establishes TL0 and TH0 as two separate counters.
    • Control bits TR1 and TF1 are used by Timer-0 (higher 8 bits) (TH0) in Mode-3 while TR0 and TF0 are available to Timer-0 lower 8 bits(TL0). 
      figure of Timer Modes
      Related Posts Plugin for WordPress, Blogger...
      Subscribe to RSS Feed Follow me on Twitter!