Topic: Timer and Counter of Dspic30F4011
Topic: Timer and Counter of Dspic30F4011
Topic: Timer and Counter of Dspic30F4011
Group 2
Members:
1.Nguyn Vit Hng
2.Phm Quang i
3.Phm Vn Hiu
4.Ng Trng Linh
1. Introduction
The 16-bit timers are classified into three types to account for their
functional differences:
Type A time base
Type B time base
Type C time base
Each timer module also has the associated bits for interrupt control:
Interrupt Enable Control bit (TxIE)
Interrupt Flag Status bit (TxIF)
Interrupt Priority Control bits (TxIP<2:0>)
2.Timer 16 bits:
Type A Timer:
A Type A timer has the following unique features over other types:
can be operated from the device Low Power 32 kHz Oscillator.
Low-Power 32 kHz Crystal Oscillator
The LP or Secondary oscillator is designed specifically for low power operation
with a 32 kHz crystal. The LP oscillator is located on the SOSCO and SOSCI
device pins and serves as a secondary crystal clock source for low power
operation. The LP oscillator can also drive Timer1
for a real-time clock application.
2.3.Modes of Operation
Timer A module can operate in one of the following modes:
As a synchronous timer
As a synchronous counter
As a gated timer
As an asynchronous counter (Type A time base only)
In Timer mode, the input clock to the timer is provided from the internal
system clock (FOSC/4). In the 16-bit Timer mode, the timer increments
on every instruction cycle up to a match value, preloaded into the period
register PR1, then resets to 0 and continues to count.
When the TCS control bit (TxCON<1>) is set, the clock source for the
timer is provided externally and the selected timer increments on every
rising edge of clock input on the TxCK pin which is synchronized with
the internal phase clocks.
The Gated Time Accumulation mode allows the internal timer register to
increment based upon the duration of the high time applied to the TxCK
pin. In the Gated Time Accumulation mode, the timer clock source is
derived from the internal system clock.
3. Timer 32 bit
Timer 2/3 module:
A 32-bit timer module can be formed by combining a Type B and a
Type C 16-bit timer module.
The Type C time base becomes the MSWord of the combined timer and
the Type B time base is the LSWord.
The control bits for the Type B time base control the operation of the 32bit timer.
For interrupt control, the combined 32-bit timer uses the interrupt
enable, interrupt flag and interrupt priority control bits of the Type C
time base.
4. Input capture:
The Input Capture module has multiple Operating modes, which are
selected via the ICxCON register. The Operating modes include:
Capture timer value on every falling edge of input applied at the ICx
pin
Capture timer value on every rising edge of input applied at the ICx pin
Capture timer value on every fourth rising edge of input applied at the
ICx pin
Capture timer value on every 16th rising edge of input applied at the
ICx pin
Capture timer value on every rising and every falling edge of input
applied at the ICx pin
The Input Capture module has a four-level FIFO buffer. The number of
capture events required to generate a CPU interrupt can be selected by
the user.
5. Output compare:
The Output Compare module has the ability to compare the value of a
selected time base with the value of one or two compare registers
(depending on the Operation mode selected). Furthermore, it has the
ability to generate a single output pulse, or a train of output pulses, on a
compare match event. Like most dsPIC peripherals, it also has the ability
to generate interrupts-on- compare match events.
001= Initialize OCx pin low, compare event forces OCx pin high
000= Output compare channel is disabled.
Homeworks:
1. Write an initialization code for timer 2 functioning in Gated Time
Accumulation Mode.
2. Write a program using timer/counter for toggling a led 0.7s on
0.3s off.
3. Write a program varying the brightness of led using timer/counter.