Timers and Counters

The 6811 chip on the Miniboard has several timers (used to measure the passage of time obviously) and several counters (used to count events). There are a total of 8 timers or counters. The programmer chooses how many of which he/she wants to use and the sum of timers and counter can be no more than eight. Of the eight timers, three are dedicated to input-capture function, four are dedicated to output-compare function, and one can be configured to be either input-capture or output-compare. Of the eight counters (called Pulse Accumulators), all behave essentially the same except for a subtle peculiarity about pulse accumulator PA7 (Pulse Accumulator 7) which I will not mention further so don't sweat it.

A programmer would use the input capture function to record the time of an event, use the output compare to cause an event at a certain time, and the pulse accumulator to count the number of events that may occur. All of the timers and pulse accumulators are interrupt driven systems. So if you would like to be able to record the time of events, cause events after a certain time, or count the number of input events on a certain pin, then you are defiantly going to be using interrupts! There is no end of usefulness to the timers and counters so buckle down and comprehend the extra complexity of the interrupt concepts. Here follow some useful suggestions about what to do with timers and counters.

With an event counter, you could implement a shaft encoder. One pulse accumulator is necessary for each shaft encoder. A shaft encoder is a wheel with dark and light spokes on it. Here follows a crude one, make a copy and shrink/expand it to any size you wish:

ShaftEncoder.GIF
ShaftEncoder Wheel

A Robot implementor would use a shaft encoder wheel on the axle of one of the robot drive wheels. An infrared emitter/detector pair could be used to sense the white and black spokes on the wheel. By counting the passage of spokes, the robot could keep track of distance traveled. The control and status bits that implement the Pulse Accumulator functions are contained in the PACTL, PACNT, TFLG2, and TMSK2 registers.

With an output compare timer, a robot implementor could cause events to happen for specific durations of time... events like turn a motor on, or send signals out the digital port. Actually, since these timers have very small resolution times, a programmer could send very short pulses of on and off to a motor and thus implement Pulse Width modulation to DC motors. Pulse Width Modulation is a way to control the speed of a DC motor. By alternating very quickly between an on signal and an off signal for an equal amount of time to a DC motor, that motor would rotate at half speed. If you allow that the signal be on a greater percentage of time than off, but still alternate very quickly, the motor will rotate faster.

An output compare timer would also be best suited to keeping track of the absolute time. The control and status bits that implement the output compare functions are contained in the TMSK1, TMSK2, TFLG1, TFLG2, TOC[1:4], TI4/O5, TCTL1, TCNT, CFORC, FOC[1:5], OC1M, and OC1D, registers.

With an input capture timer, a robot implementor could record the time of events, the periodicity of events, or the duration of events. The control and status bits that implement the input capture functions are contained in the PACTL, TCTL2, TMSK1, and TFLG1 registers.

Interrupts and Timers are not simulated in the freeware simulators available for the Miniboard. So a programmer must leave the simulator to experiment with timers, counters and interrupts.

ieeecs@hal.elee.calpoly.edu
BackBack to Table of Contents