Ees07 Msp430 Timers

61
1 Copyright 2009 Texas Instruments All Rights Reserved MSP430 Timers

Transcript of Ees07 Msp430 Timers

Page 1: Ees07 Msp430 Timers

1Copyright 2009 Texas Instruments

All Rights Reserved

MSP430 Timers

Page 2: Ees07 Msp430 Timers

What is a Timer/Counter?

A counter is a device that generates binary numbers in a specified count sequence when triggered by an incoming clock pulse.

Timers are counters that count pulses. If the pulses are “clock” pulses, then the timers count time.

Page 3: Ees07 Msp430 Timers

Difference between a Timer and a Counter

When the incoming clock frequency is known, we can generate a fixed period of time known to the designer by setting a preloaded value. This is called a “timer”.

It is also called an “interval timer” since it is measuring the time of the interval between two events.

When the incoming clock is irregular and we are only interested in the number of occurrences of the pulse, this is called a “counter”. Since we are counting events, is also known as an “event counter”.

Page 4: Ees07 Msp430 Timers

A view inside

Counter A register that goes through a predefined series of states

Counters increment or decrement by one in response to input

Ripple counters

Flip flop output serves as a source for triggering other flip flops

Synchronous counters

All flip flops triggered by a the same clock signal

Synchronous counters are more widely used in industry.

Page 5: Ees07 Msp430 Timers

Binary Ripple Counter

Reset signal sets all outputs to 0

Count signal toggles output of low-order flip flop

Low-order flip flop provides trigger for adjacent flip flop

Not all flops change value simultaneously Lower-order flops change

first

Page 6: Ees07 Msp430 Timers

Asynchronous Ripple Counter

Page 7: Ees07 Msp430 Timers

Synchronous counters

Synchronous(parallel) counters All of the FFs are triggered

simultaneously by the clock input pulses.

All FFs change at same time

Remember If J=K=0, flop maintains value

If J=K=1, flop toggles

Most counters are synchronous in computer systems.

Value increments on positive edge

Page 8: Ees07 Msp430 Timers

Synchronous UP/Down counters

Up/Down Counter can either count up or down on each clock cycle

Up counter counts from 0000 to 1111 and then changes back to 0000

Down counter counts from 1111 to 0000 and then back to 1111

Output changes occur on clock rising edge

Page 9: Ees07 Msp430 Timers

9Copyright 2009 Texas Instruments

All Rights Reserved9

Copyright 2009 Texas Instruments All Rights Reserved

Timers in MCU (1/3)

Correct system timing is a fundamental requirement for the proper operation of a real-time application;

If the timing is incorrect, the input data may be processed after the output was updated;

The clock implementations vary among devices in the MSP430 family;

Each device provides different clock sources, controls and uses;

Page 10: Ees07 Msp430 Timers

10Copyright 2009 Texas Instruments

All Rights Reserved10

Copyright 2009 Texas Instruments All Rights Reserved

Introduction (2/3)

MSP430x4xx family:

Two general purpose 16-bit or 8-bit counters and event timers: Timer_A, Timer_B;

Basic Timer 1 (MSP430x4xx devices).

MSP430x2xx family:

Also has Timer_A and Timer_B, as above;

Basic Clock Module+.

The timers may be driven from an internal or external clock;

Timer_A and Timer_B also include multiple independent capture and compare blocks, with interrupt capabilities;

The capture and compare blocks are suited to applications such as:

Time events;

Pulse Width Modulator (PWM).

Page 11: Ees07 Msp430 Timers

11Copyright 2009 Texas Instruments

All Rights Reserved11

Copyright 2009 Texas Instruments All Rights Reserved

Introduction (3/3)

The system timing is fundamental to nearly every embedded application;

The main applications of timers are to:

• Generate events of fixed time-period;

• Allow periodic wakeup from sleep of the device;

• Count transitional signal edges;

• Replacing delay loops with timer calls allows the CPU to sleep between operations, thus consuming less power.

Page 12: Ees07 Msp430 Timers

12Copyright 2009 Texas Instruments

All Rights Reserved12

Copyright 2009 Texas Instruments All Rights Reserved

Basic Timer1 (1/5)

The Basic Timer 1 module consists of two independent 8-bit timers:

Basic Timer 1 Counter 1 (BTCNT1);

Basic Timer 1 Counter 2 (BTCNT2).

These can be used in cascade to form a 16-bit timer (software selectable by BTCTL register configuration);

The main characteristics of this module are:

• Clock for a Liquid Crystal Display (LCD) module;

• Suitable for a Real-Time Clock (RTC) implementation;

• Basic interval timer;

• Simple interrupt capability.

Page 13: Ees07 Msp430 Timers

13Copyright 2009 Texas Instruments

All Rights Reserved13

Copyright 2009 Texas Instruments All Rights Reserved

Basic Timer1 (2/5)

The control registers determine the operation of the Basic Timer 1 module:

• BTCNT1 (Read/write 8 bit register) - Generate the fLCD:

– Clock source: ACLK;

– Frame frequency selectable by software (BTFRFQx):

fLCD = ACLK/x.

• BTCNT2 (Read/write 8-bit register) - Programmable frequency divider to provide periodic CPU interrupts and/or a RTC system.

– 3 possible clock sources:

» ACLK

» SMCLK

» ACLK/256 - cascaded with BTCNT1 (BTSSEL and BTDIV bits in the BTCTL register);

– Sources the Basic Timer1 interrupt, BTIFG, with interval selected by BTIPx bits.

Page 14: Ees07 Msp430 Timers

14Copyright 2009 Texas Instruments

All Rights Reserved14

Copyright 2009 Texas Instruments All Rights Reserved

Basic Timer1 (3/5)

Block diagram:

Page 15: Ees07 Msp430 Timers

15Copyright 2009 Texas Instruments

All Rights Reserved15

Copyright 2009 Texas Instruments All Rights Reserved

Basic Timer1 (4/5)

Registers:

BTCTL, Basic Timer 1 Control Register

7 6 5 4 3 2 1 0

BTSSEL BTHOLD BTDIV BTFRFQ1 BTFRFQ0 BTIP2 BTIP1 BTIP0

Bit Description

7 BTSSEL BTCNT2 clock select (together with the BTDIV bit)

6 BTHOLD Basic Timer 1 hold: BTHOLD = 0 BTCNT1 and BTCNT2 activeBTHOLD = 1 BTCNT1 hold, if BTDIV = 1

BTHOLD = 1 BTCNT1 and BTCNT2 hold

5 BTDIV Basic Timer 1 clock divider: BTSSEL BTDIV = 0 0 ACLKBTSSEL BTDIV = 0 1 ACLK/256BTSSEL BTDIV = 1 0 SMCLK

BTSSEL BTDIV = 1 1 ACLK/256

4-3 BTFRFFQx LCD frame frequency: BTFRFQ1 BTFRFQ0 = 0 0 fACLK/32BTFRFQ1 BTFRFQ0 = 0 1 fACLK/64BTFRFQ1 BTFRFQ0 = 1 0 fACLK/128

BTFRFQ1 BTFRFQ0 = 1 1 fACLK/256

2-0 BTIPX Basic Timer 1 interrupt interval: BTIP2 BTIP1 BTIP0 = 0 0 0 fCLK2 / 2BTIP2 BTIP1 BTIP0 = 0 0 1 fCLK2 / 4BTIP2 BTIP1 BTIP0 = 0 1 0 fCLK2 / 8BTIP2 BTIP1 BTIP0 = 0 1 1 fCLK2 / 16BTIP2 BTIP1 BTIP0 = 1 0 0 fCLK2 / 32BTIP2 BTIP1 BTIP0 = 1 0 1 fCLK2 / 64BTIP2 BTIP1 BTIP0 = 1 1 0 fCLK2 / 128

BTIP2 BTIP1 BTIP0 = 1 1 1 fCLK2 / 256

Page 16: Ees07 Msp430 Timers

16Copyright 2009 Texas Instruments

All Rights Reserved16

Copyright 2009 Texas Instruments All Rights Reserved

Basic Timer1 (5/5)

Registers:

IE2, Interrupt Enable Register 2

IFG2, Interrupt Flag Register 2

7 0

BTIE

Bit Description

7 BTIE Basic Timer 1 interrupt enable when BTIE = 1

7 0

BTIFG

Bit Description

7 BTIFG Basic Timer 1 interrupt flag BTIFG = 1 when interrupt pending

Page 17: Ees07 Msp430 Timers

17Copyright 2009 Texas Instruments

All Rights Reserved17

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Introduction (1/6)

Timer A and B are two general-purpose 16-bit counter/event timers;

There are slight differences between the two timers;

Features common to both timers include:

Asynchronous 16-bit timer/counter with four operating modes:

• Timer_A length: 16 bits;

• Timer_B length: programmable: 8, 10, 12, or 16 bits.

• Timer/counter register, TAR (Timer_A) or TBR (Timer_B) -from now on described as TxR- increments or decrements (depending on mode of operation) with each rising edge of the clock signal;

• The timer can generate an interrupt when it overflows;

• Wide interrupt interval range: 1/MCLK to 32 seconds.

Page 18: Ees07 Msp430 Timers

18Copyright 2009 Texas Instruments

All Rights Reserved18

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Introduction (2/6)

Choice of selectable and configurable clock source:

• ACLK;

• SMCLK;

• External - via TACLK or INCLK (TASSELx bits);

• The selected clock source may additionally be divided by 2, 4, or 8 (IDx bits configuration).

Configurable capture/compare registers:

• Timer_A has 3 or 5 capture/compare registers;

• Timer_B has 3 or 7 capture/compare registers;

• Timer_B capture/compare registers can be grouped.

Page 19: Ees07 Msp430 Timers

19Copyright 2009 Texas Instruments

All Rights Reserved19

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Introduction (3/6)

Configurable outputs and internal connections to several other modules:• Faster response; • No cycles are wasted while the Interrupt Service

Routine ( ISR) loads/executes;• Avoids CPU wakeup;• Saves power.

• Outputs capability: Pulse Width Modulation (PWM);

• Comparator_A;

• Direct Memory Access (DMA);

• Digital-to-Analogue Converter (DAC12).

Page 20: Ees07 Msp430 Timers

20Copyright 2009 Texas Instruments

All Rights Reserved20

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Introduction (4/6)

Asynchronous input and output latching:

• Timer_A Capture/Compare (Cap/Com) registers are not buffered, being updated immediately when written to;

• Timer_B Cap/Com registers are double-buffered with synchronized loading.

Interrupt vector register for fast decoding of all Timer_A and Timer_B interrupts:

• TACCR0 (or TBCCR0) interrupt vector for TACCR0 (or TBCCCR0) CCIFG;

• TAIV (or TBIV) interrupt vector for the remaining CCIFG flags and TAIFG (or TBIFG).

Page 21: Ees07 Msp430 Timers

21Copyright 2009 Texas Instruments

All Rights Reserved21

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A Block diagram

Page 22: Ees07 Msp430 Timers

22Copyright 2009 Texas Instruments

All Rights Reserved22

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Introduction (6/6)

Timers have four modes of operation:

• MCx bits (Timer_A or Timer_B Control Register)

MCx Mode Description

0 0 Stop The timer is halted

0 1 Up Up counting mode (from 0x0000 to the value in theTACCR0 or TBCCR0 register)

1 0 Continuous Continuous counting mode (from 0x0000 to 0xFFFF)

1 1 Up/down Up/down counting mode (from 0x0000 to the value in theTACCR0 or TBCCR0 register and back down to zero)

Page 23: Ees07 Msp430 Timers

23Copyright 2009 Texas Instruments

All Rights Reserved23

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B operating modes (1/3)

Up mode:

TxR counts up till it reaches the value in the TxCCR0 register;

TxR->TxCCR0: TACCR0 interrupt flag, CCIFG, is set;

TxR=TxCCR0: EQU0 = 1 (restarts counting in TxR);

TxCCR0->0: TxIFG interrupt flag is set:

• Interrupt period:

tINT = 1/[fCLK/Prescaler/(TxCCR0+1)].

Page 24: Ees07 Msp430 Timers

24Copyright 2009 Texas Instruments

All Rights Reserved24

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B operating modes (2/3)

Continuous mode:

TxR counts up till it reaches 0xFFFF (65536 counts);

TxR=0xFFFF: TxR counting from zero (next clock pulse);

0xFFFF->0: TxIFG interrupt flag is set:

• Interrupt period: tINT = 1/[fCLK/Prescaler/65536];

(Correct only for TAR; for TBR 4 different end values. See

User’s Guide for additional details).

Page 25: Ees07 Msp430 Timers

25Copyright 2009 Texas Instruments

All Rights Reserved25

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B operating modes (3/3)

Up/down mode:

TxR counts up till it reaches the value in the TxCCR0 register;

TxCCR0-1 -> TxCCR0: Interrupt flag, CCIFG, is set;

TxR=TxCCR0: Counting is inverted;

0x0001->0x0000: Interrupt flag TxIFG is set:

• Interrupt period: tINT = 1/[fCLK/Prescaler/(TxCCR02];

Page 26: Ees07 Msp430 Timers

26Copyright 2009 Texas Instruments

All Rights Reserved26

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B reset

The timers can be reset by the following actions:

Writing 0 in the TxR register;

Writing 0 in the TxCCR0 register, provided that the timer is not in continuous mode;

Setting the TxCLR bit in the Timer Control Register (TxCTL).

Page 27: Ees07 Msp430 Timers

27Copyright 2009 Texas Instruments

All Rights Reserved27

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B registers

TACTL, Timer_A Control Register

15 10 9 8

Unused TASSEL1 TASSEL0

7 6 5 4 3 2 1 0

ID1 ID0 MC1 MC0 Unused TACLR TAIE TAIFG

Bit Description

9-8 TASSELx Timer_A clock source: TASSEL1 TASSEL0 = 0 0 TACLKTASSEL1 TASSEL0 = 0 1 ACLKTASSEL1 TASSEL0 = 1 0 SMCLK

TASSEL1 TASSEL0 = 1 1 INCLK

7-6 IDx Clock signal divider: ID1 ID0 = 0 0 / 1ID1 ID0 = 0 1 / 2ID1 ID0 = 1 0 / 4ID1 ID0 = 1 1 / 8

5-4 MCx Clock timer operating mode: MC1 MC0 = 0 0 Stop modeMC1 MC0 = 0 1 Up modeMC1 MC0 = 1 0 Continuous mode

MC1 MC0 = 1 1 Up/down mode

2 TACLR Timer_A clear when TACLR = 1

1 TAIE Timer_A interrupt enable when TAIE = 1

0 TAIFG Timer_A interrupt pending when TAIFG = 1

Page 28: Ees07 Msp430 Timers

28Copyright 2009 Texas Instruments

All Rights Reserved28

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Cap/Com blocks (1/5)

Timer_A (and Timer_B) contain independent capture and compare blocks, TACCRx (or TBCCRx);

These blocks may be used to capture timer register contents, as they are at the time of an event, or to generate an event when the timer register contents correspond to the capture/compare register contents, e.g. to generate time intervals;

The setting of capture/compare is selected by the mode bit CAP in the individual Capture/Compare Control registers, TACCTLx (or TBCCTLx)

Page 29: Ees07 Msp430 Timers

29Copyright 2009 Texas Instruments

All Rights Reserved29

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Cap/Com blocks (2/5)

Capture mode:

Used to measure the period of time events with minimal CPU intervention.

Procedure:

• Set the CAP bit to select capture mode;

• Set the SCS bit to synchronize the capture with the next timer clock (recommended to avoid race conditions);

• The input signal is sampled by the CCIxA (or CCIxB) input, selected by the CCISx bits in the Capture/Compare Control Register, TACCTLx (or TBCCTLx);

Page 30: Ees07 Msp430 Timers

30Copyright 2009 Texas Instruments

All Rights Reserved30

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Cap/Com blocks (3/5)

• The capture edge of the input signal (rising, falling, or both) is selected by the CMx bits;

• When a valid edge is detected on the selected input line, the value in the Timer register is latched into the TACCRx (or TBCCRx) register, providing a time mark for the event;

• The interrupt flag CCIFG is set;

• The bit COV (=1) controls an overflow event when a second capture is performed, before the value from the first capture is read.

Page 31: Ees07 Msp430 Timers

I/O Pin used for Timers

31Copyright 2009 Texas Instruments

All Rights Reserved

Page 32: Ees07 Msp430 Timers

32Copyright 2009 Texas Instruments

All Rights Reserved32

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Cap/Com blocks (4/5)

Compare mode:

Used for pulse generation or generation of interrupts at specific time intervals (PWM output signals).

Procedure:

• Reset the CAP bit to select compare mode;

• TxR counts up to the value programmed in the TxCCRx register;

• When the timer value is equal to the value in the TxCCRx register, an interrupt is generated:

– Interrupt flag CCIFG is set;

– Internal signal EQUx = 1 (where x is the number of the CCR channel).

Page 33: Ees07 Msp430 Timers

33Copyright 2009 Texas Instruments

All Rights Reserved33

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Cap/Com blocks (5/5)

• EQUx affects the output compare signal OUTx according to the output mode (defined by the OUTMODx bits in the TxCCTL;

• The input signal CCI is latched into SCCI.

Output operating modes uses:

Modes 2, 3, 6 and 7: PWM output signals;

Mode 3: active PWM signal at low state;

Mode 7: active PWM signal at high state;

Modes 2 and 6: complementary PWM signals;

Modes 1 and 5: single event generation;

Mode 4: signal with 1/2 frequency of the timer signal.

Page 34: Ees07 Msp430 Timers

Pulse Width Modulation (PWM)

Pulse width modulation (PWM) is used to control analog circuits with a processor's digital outputs

PWM is a technique of digitally encoding analog signal levels

The duty cycle of a square wave is modulated to encode a specific analog signal level

The PWM signal is still digital because, at any given instant of time, the full DC supply is either fully on or fully off

The voltage or current source is supplied to the analog load by means of a repeating series of on and off pulses

Given a sufficient bandwidth, any analog value can be encoded with PWM.

Page 35: Ees07 Msp430 Timers

PWM – Frequency/Duty Cycle

Frequency

Duty Cycle

Page 36: Ees07 Msp430 Timers

PWM: Tones

A transducer changes electrical energy into mechanical energy (sound)

Speaker, Magnetic Buzzer, Piezo Buzzer

Sound Pressure Level (SPL)

Sound reproduction

Carefully timed pulses

Rely on a transducer’s physical filtering properties

Very low quality

Use timer cycle (frequency) for tones

Use pulse width (duty-cycle) for volume

Page 37: Ees07 Msp430 Timers

Magnetic Transponder (Buzzer)

Magnetic transducers consist of a iron core with a wound coil, a yoke plate, a permanent magnet, and a vibrating diaphragm with a movable iron piece.

The diaphragm is slightly pulled towards the top of the core by the magnet's magnetic field.

When a positive AC signal is applied, the current flowing through the excitation coil produces a fluctuating magnetic field, which causes the diaphragm to vibrate up and down, thus vibrating air.

Page 38: Ees07 Msp430 Timers

38Copyright 2009 Texas Instruments

All Rights Reserved38

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Output modes

Output examples:

Page 39: Ees07 Msp430 Timers

39Copyright 2009 Texas Instruments

All Rights Reserved39

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Output modes

Output operating modes (OUTMODx bits):

OUTMODx Mode Description

0 0 0 Output The output signal OUTx is defined by the bit OUTx

0 0 1 Set OUTx = 1 timer = TxCCRxOUTx = 0 timer = 0 or until another output mode is selected and

affects the output

0 1 0 Toggle/Reset OUTx = toggle timer = TxCCRx

OUTx = 0 timer = TxCCR0

0 1 1 Set/Reset OUTx = 1 timer = TxCCRxOUTx = 0 timer = TxCCR0

1 0 0 Toggle OUTx = toggle timer = TxCCRx

The output period is double the timer period

1 0 1 Reset OUTx = 0 timer = TxCCRx

OUTx = 1 another output mode is selected and affects the output

1 1 0 Toggle/Set OUTx = toggle timer = TxCCRxOUTx = 1 timer = TxCCR0

1 1 1 Reset/Set OUTx = 0 timer = TxCCRxOUTx = 1 timer = TxCCR0

Page 40: Ees07 Msp430 Timers

PWM to get a DAC

40Copyright 2009 Texas Instruments

All Rights Reserved

Conversion of PWM waveform to DC voltage

Page 41: Ees07 Msp430 Timers

PWM to control motors

Basic H-Bridge Motor Configuration

Page 42: Ees07 Msp430 Timers

Basic H-Bridge Motor Clockwise Configuration

Page 43: Ees07 Msp430 Timers

Basic H-Bridge Motor Counterclockwise Configuration

Page 44: Ees07 Msp430 Timers

Basic H-Bridge OOPS

Page 45: Ees07 Msp430 Timers

Pulse Width Modulation Comparison

Page 46: Ees07 Msp430 Timers

46Copyright 2009 Texas Instruments

All Rights Reserved46

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A Cap/Com registers (1/2)

TACCTLx, Timer_A Cap/Com Control Register

15 14 13 12 11 10 9 8

CM1 CM0 CCIS1 CCIS0 SCS SCCI Unused CAP

Bit Description

15-14 CMx Capture mode: CM1 CM0 = 0 0 No captureCM1 CM0 = 0 1 Capture on rising edgeCM1 CM0 = 1 0 Capture on falling edgeCM1 CM0 = 1 1 Capture on both edges

13-12 CCISx Capture/compare input select: CCIS1 CCIS0 = 0 0 CCIxACCIS1 CCIS0 = 0 1 CCIxBCCIS1 CCIS0 = 1 0 GNDCCIS1 CCIS0 = 1 1 Vcc

11 SCS Synchronize capture input signal with timer clock:SCS = 0 Asynchronous capture

SCS = 1 Synchronous capture

10 SCCI Synchronized capture/compare input

8 CAP Mode: Capture mode CAP = 1Compare mode CAP = 0

Page 47: Ees07 Msp430 Timers

47Copyright 2009 Texas Instruments

All Rights Reserved47

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A Cap/Com registers (2/2)

TACCTLx, Timer_A Cap/Com Control Register

7 6 5 4 3 2 1 0

OUTMOD2 OUTMOD1 OUTMOD0 CCIE CCI OUT COV CCIFG

Bit Description

7-5 OUTMODx Output mode: OUTMOD2 OUTMOD1 OUTMOD0 = 0 0 0 bit OUTOUTMOD2 OUTMOD1 OUTMOD0 = 0 0 1 SetOUTMOD2 OUTMOD1 OUTMOD0 = 0 1 0 Toggle/ResetOUTMOD2 OUTMOD1 OUTMOD0 = 0 1 1 Set / ResetOUTMOD2 OUTMOD1 OUTMOD0 = 1 0 0 ToggleOUTMOD2 OUTMOD1 OUTMOD0 = 1 0 1 ResetOUTMOD2 OUTMOD1 OUTMOD0 = 1 1 0 Toggle / SetOUTMOD2 OUTMOD1 OUTMOD0 = 1 1 1 Reset / Set

4 CCIE Capture/compare interrupt enable when CCIE = 1.

3 CCI Capture/compare input

2 OUT Output state

1 COV Capture overflow when COV = 1

0 CCIFG Capture/compare interrupt flag CCIFG = 1 when interrupt pending

Page 48: Ees07 Msp430 Timers

48Copyright 2009 Texas Instruments

All Rights Reserved48

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Interrupts (1/3)

Interrupt characteristics:

Capture mode:

• Any CCIFG flag is set when a timer value is captured in the associated TxCCRx register.

Compare mode:

• Any CCIFG flag is set if TxR counts up to the TxCCRx value.

• Software may also set or clear a CCIFG flag;

• All CCIFG flags request an interrupt when their corresponding CCIE bit and GIE bit are set.

Page 49: Ees07 Msp430 Timers

49Copyright 2009 Texas Instruments

All Rights Reserved49

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Interrupts (2/3)

Interrupt vectors associated with Timer_A:

TACCR0 interrupt vector for TACCR0 CCIFG:

• TACCR0 CCIFG flag has the highest priority Timer_A interrupt;

• The TACCR0 CCIFG flag is automatically reset when the TACCR0 interrupt request is serviced.

Page 50: Ees07 Msp430 Timers

50Copyright 2009 Texas Instruments

All Rights Reserved50

Copyright 2009 Texas Instruments All Rights Reserved

Timer_A and Timer_B Interrupts (3/3)

Interrupt vectors associated with Timer_A (continued):

TAIV interrupt vector for TACCR1 CCIFG to TACCR4 CCIFG and TAIFG:

• Flags are given priority and combined to source a single interrupt vector (decreasing priority);

• TAIV determines which flag requests the interrupt;

• Disabling interrupts do not affect the value in TAIV;

• Any access (read/write) of TAIV automatically resets the highest pending interrupt flag;

• If another interrupt flag is set, another interrupt is immediately generated after servicing the initial interrupt.

Page 51: Ees07 Msp430 Timers

51Copyright 2009 Texas Instruments

All Rights Reserved51

Copyright 2009 Texas Instruments All Rights Reserved

Timer_B special features

Programmable length of the TBR register (equivalent to TAR in Timer_A) to be 8, 10, 12, or 16 bits:

Configurable through selection of the CNTLx bits in TBCTL (equivalent to TACTL in Timer_A);

The maximum count value, TBR(maximum), for the selectable lengths is 0FFh, 03FFh, 0FFFh, and 0FFFFh, respectively;

Three or seven capture/compare blocks TBCCRx;

Page 52: Ees07 Msp430 Timers

52Copyright 2009 Texas Instruments

All Rights Reserved52

Copyright 2009 Texas Instruments All Rights Reserved

Timer_B registers special bits (1/2)

TBCTL, Timer_B Control Register

15 14 13 12 11 10 9 8

Unused TBCLGRP1 TBCLGRP0 CNTL1 CNTL0 Unused TBSSEL1 TBSSEL0

7 6 5 4 3 2 1 0

ID1 ID0 MC1 MC0 Unused TBCLR TBIE TBIFG

Bit Description

14-13 TBCLGRPx TBCLx group:TBCLGRP1 TBCLGRP0 = 0 0 Each TBCLx latch loads independentlyTBCLGRP1 TBCLGRP0 = 0 1 TBCL1+TBCL2 (update control: TBCCR1 CLLDx)

TBCL3+TBCL4 (update control: TBCCR3 CLLDx) TBCL5+TBCL6 (update control: TBCCR5 CLLDx) TBCL0 independent

TBCLGRP1 TBCLGRP0 = 1 0 TBCL1+TBCL2+TBCL3 (update control: TBCCR1 CLLDx) TBCL4+TBCL5+TBCL6 (update control: TBCCR4 CLLDx) TBCL0 independent

TBCLGRP1 TBCLGRP0 = 1 1 TBCL0+TBCL1+TBCL2+TBCL3+TBCL4+TBCL5+TBCL6

(update control: TBCCR1 CLLDx)

12-11 CNTLx Counter Length: CNTL1 CNTL0 = 0 0 16-bit, TBR(max) = 0FFFFhCNTL1 CNTL0 = 0 1 12-bit, TBR(max) = 0FFFhCNTL1 CNTL0 = 1 0 10-bit, TBR(max) = 03FFh

CNTL1 CNTL0 = 1 1 8-bit, TBR(max) = 0FFh

Page 53: Ees07 Msp430 Timers

53Copyright 2009 Texas Instruments

All Rights Reserved53

Copyright 2009 Texas Instruments All Rights Reserved

Timer_B registers special bits (2/2)

TBCCTLx, Timer_B Capture/Compare Control Register

15 14 13 12 11 10 9 8

CM1 CM0 CCIS1 CCIS0 SCS CLLD1 CLLD0 CAP

7 6 5 4 3 2 1 0

OUTMOD2 OUTMOD1 OUTMOD0 CCIE CCI OUT COV CCIFG

Bit Description

10-9 CLLDx Compare latch load:CLLD1 CLLD0 = 0 0 TBCLx loads on write to TBCCRxCLLD1 CLLD0 = 0 1 TBCLx loads when TBR counts to 0CLLD1 CLLD0 = 1 0 TBCLx loads when TBR counts:

- to 0 (up/continuous mode);

- to TBCL0 or to 0 (up/downmode)

CLLD1 CLLD0 = 1 1 TBCLx loads when TBR counts:

- to TBCLx

Page 54: Ees07 Msp430 Timers

54Copyright 2009 Texas Instruments

All Rights Reserved

MSP430 Comparator

Page 55: Ees07 Msp430 Timers

55Copyright 2009 Texas Instruments

All Rights Reserved55

Copyright 2009 Texas Instruments All Rights Reserved

Introduction to Comparator_A (1/2)

Comparator_A module is primary designed to support:

Low cost precision slope A/D conversions;

• Resistance measurement;

• Voltage measurement;

• Current measurement;

• Capacitance measurements..

• Requires few external components;

Battery-voltage supervision;

Monitoring of external analogue signals.

It is used on the FG4618 device (Experimenter’s board).

Page 56: Ees07 Msp430 Timers

56Copyright 2009 Texas Instruments

All Rights Reserved56

Copyright 2009 Texas Instruments All Rights Reserved

Introduction to Comparator_A (2/2)

Comparator_A block diagram:

Comparator_A is an analog voltage comparator

• Supports precision slope analog-to-digital conversions

• Supply voltage supervision, and

• Monitoring of external analog signals.

Page 57: Ees07 Msp430 Timers

57Copyright 2009 Texas Instruments

All Rights Reserved57

Copyright 2009 Texas Instruments All Rights Reserved

Comparator_A Features

Comparator_A features:

Multiplexed inverting and non-inverting inputs;

Software selectable low-pass filter (RC) for the output;

Outputs:

• Timer_A capture input;

• Interrupt (one interrupt vector with enable): CAIFG;

• External: GPIO.

Software control of the port input buffer;

Selectable references, external or internal (reference voltage generator):

VCAREF = 0.25 VCC;

VCAREF = 0.5 VCC;

VCAREF = ~0.55 V (diode);

Comparator and reference generator can be powered down.

Page 58: Ees07 Msp430 Timers

58Copyright 2009 Texas Instruments

All Rights Reserved58

Copyright 2009 Texas Instruments All Rights Reserved

Comparator_A components

Comparator:

Compares the analogue voltages at the (+) and (–) input terminals (CA0 and CA1 for a non-inverting topology);

The comparator output:

• CAOUT = 1: CA0 > CA1;

• CAOUT = 0: CA0 < CA1 and CAON = 0 (switched off).

Analogue input switches (selected with P2CAx bits):

Individually connect or disconnect the two comparator input terminals to associated port pins.

Output filter (CAF bit):

Use the internal low pass filter to reduce errors (in accuracy and resolution) associated with comparator oscillation.

Page 59: Ees07 Msp430 Timers

59Copyright 2009 Texas Instruments

All Rights Reserved59

Copyright 2009 Texas Instruments All Rights Reserved

Comparator_A interrupts

One interrupt flag, CAIFG, and one interrupt vector are associated with Comparator_A;

Condition for an interrupt:

CAIFG = 1:

• Rising or falling edge at comparator output (CAIES bits);

• Interrupt request when CAIE = 1 and GIE = 1.

CAIFG = 0:

• Interrupt request serviced;

• Reset by software.

Page 60: Ees07 Msp430 Timers

60Copyright 2009 Texas Instruments

All Rights Reserved60

Copyright 2009 Texas Instruments All Rights Reserved

Comparator_A Registers

CACTL1, Comparator_A Control Register 1

7 6 5 4 3 2 1 0

CAEX CARSEL CAREFx CAON CAIES CAIE CAIFG

Bit Description

7 CAEX Comparator_A exchange:

CAEX = 1 Exchanges the comparator inputs and inverts the comparator output.

6 CARSEL Comparator_A reference:CAEX = 0: CAEX = 1:

CARSEL = 0 VCAREF in + terminal VCAREF in - terminalCARSEL = 1 VCAREF in - terminal VCAREF in + terminal

5-4 CAREFx Comparator_A voltage reference:CAREF1 CAREF0 = 00 External (Internal reference off)CAREF1 CAREF0 = 01 VCAREF = 0.25 VCC

CAREF1 CAREF0 = 10 VCAREF = 0.5 VCC

CAREF1 CAREF0 = 11 VCAREF = 0.55 V (Diode reference)

3 CAON Comparator_A on when CAON = 1

2 CAIES Comparator_A interrupt edge:CAIES = 0 Rising edge

CAIES = 1 Falling edge

1 CAIE Comparator_A interrupt enable when CAIE = 1

0 CAIFG The Comparator_A interrupt flag, CAIFG = 1 when an interrupt is pending

Page 61: Ees07 Msp430 Timers

61Copyright 2009 Texas Instruments

All Rights Reserved

www.msp430.ubi.pt

Comparator_A (2/2)Registers

CACTL2, Comparator_A Control Register 2

CAPD, Comparator_A Port Disable Register

The 8-bit CAPD register allows individual enable or disable of each P1.x pin buffer, when the corresponding CAPDx = 0 or CAPDx = 1 values respectively are configured.

7 6 5 4 3 2 1 0

Unused P2CA1 P2CA0 CAF CAOUT

Bit Description

3 P2CA1 The pin is connected to CA1 when P2CA1 = 1 2 P2CA0 The pin is connected to CA0 when P2CA0 = 1

1 CAF Comparator_A output filter is enable when CAF = 1

0 CAOUT Comparator_A output.