UBI >> Contents Lecture 3 Operating Modes and Timers MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis.

Slides:



Advertisements
Similar presentations
Chapter 9 Data Acquisition Comparator-Based Slope ADC
Advertisements

The 8051 Microcontroller and Embedded Systems
UBI >> Contents Chapter 7 Timers Laboratories MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar,
1 ELE271 Mon. April 7, Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
UBI >> Contents Chapter 7 Timers Description of clock signals MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT)
8051 Core Specification.
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
Instructor: Dr Aleksandar Milenkovic Lecture Notes
Chapter 11 Direct Memory Access (DMA)
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
UBI >> Contents Chapter 12 Hardware Multiplier MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar,
UBI >> Contents Chapter 15 Advanced Laboratories RF link using the eZ430-RF2500 MSP430 Teaching Materials Texas Instruments Incorporated University of.
Chung-Ta King National Tsing Hua University
Timers. Range of timers Watchdog timer: Included in all devices (watchdog timer+). Its main function is to protect the system against malfunctions but.
LAB 7: WDT+ and Low-Power Optimization
T IMERS - 2. O UTPUT U NIT Each capture/compare block contains an output unit. The output unit is used to generate output signals such as PWM signals.
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
System Clocks.
MSP430 Mixed Signal Microcontroller – Parte 2 Afonso Ferreira Miguel Source: slau056d – Texas instruments.
CPE 323 Introduction to Embedded Computer Systems: Watchdog Timer, Timer A Instructor: Dr Aleksandar Milenkovic Lecture Notes.
MICROPROCESSOR INPUT/OUTPUT
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
ECE 447 Fall 2009 Lecture 10: TI MSP430 Timers and Capture Modes.
Lecture 11: TI MSP430 Timers Compare Modes
LAB 8: Program Design Pattern and Software Architecture
UBI >> Contents Chapter 2 Software Development tools Code Composer Essentials v3: Code Debugging Texas Instruments Incorporated University of Beira Interior.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This training course provides an overview of the CPU architecture.
UBI >> Contents Lecture 6 Operating Modes, General Purpose Input/Output and LCD Controller MSP430 Teaching Materials Texas Instruments Incorporated University.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
Z80 Overview internal architecture and major elements of the Z80 CPU.
ECE 447 Fall 2009 Lecture 7: MSP430 Polling and Interrupts.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
Lecture 4 General-Purpose Input/Output NCHUEE 720A Lab Prof. Jichiang Tsai.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
ECE 382 Lesson 32 Lesson Outline Lab 6 Introduction Pulse Width Modulation Capture / Compare Example Lab 6 Tips Admin Lab#6 “prelab” due BOC lesson 33.
Recall the Container Thermometer
Lecture 10: TI MSP430 Timers and Capture Modes
Introduction Why low power?
Timers and Event Counters
ECE 3430 – Intro to Microcomputer Systems
Lecture 8: TI MSP430 Interrupts, ISRs
PWM and DC Motor Control
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
EMBEDDED SYSTEMS Unit 3.
Timer and Interrupts.
Chapter 6 General Purpose Input/Output
UNIT – Microcontroller.
ECE 3430 – Intro to Microcomputer Systems
MSP432 ARM Timer Programming
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
I/O PORTS : MSP430x5xx devices have up to 12 digital I/O ports :
Lecture 9: TI MSP430 Interrupts & Low Power Modes
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
MSP430 Clock System and Timer
Presentation transcript:

UBI >> Contents Lecture 3 Operating Modes and Timers MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar, António Espírito Santo, Bruno Ribeiro, Humberto Santos University of Beira Interior, Electromechanical Engineering Department Copyright 2009 Texas Instruments All Rights Reserved

UBI >> Contents 2 Copyright 2009 Texas Instruments All Rights Reserved Contents  Low-power operating modes Low-power operating modes  Introduction to timers Introduction to timers  Clock signals available on the hardware development kits Clock signals available on the hardware development kits  Basic Timer1 Basic Timer1  Timer_A and Timer_B: Timer_A and Timer_B  Operating modes Operating modes  Reset Reset  Registers Registers  Cap/Com blocks Cap/Com blocks  Output modes Output modes  Timer_A Cap/Com registers Timer_A Cap/Com registers  Interrupts Interrupts  Timer_B special features Timer_B special features  Timer_B register special bits Timer_B register special bits

UBI >> Contents 3 Copyright 2009 Texas Instruments All Rights Reserved Low power operating modes (1/11)  One of the main features of the MSP430 families:  Low power consumption (about 1 mW/MIPS or less);  Important in battery operated embedded systems.  Low power consumption is only accomplished:  Using low power operating modes design;  Depends on several factors such as: Clock frequency; Ambient temperature; Supply voltage; Peripheral selection; Input/output usage; Memory type;...

UBI >> Contents 4 Copyright 2009 Texas Instruments All Rights Reserved Low power operating modes (2/11)  Low power modes (LPM):  6 operating modes;  Configured by the SR bits: CPUOFF, OSCOFF, SCG1, SCG0.  Active mode (AM) - highest power consumption: Configured by disabling the SR bits described above; CPU is active; All enabled clocks are active; Current consumption: 250 A.  Software selection up to 5 LPM of operation;  Operation: An interrupt event can wake up the CPU from any LPM; Service the interrupt request; Restore back to the LPM.

UBI >> Contents 5 Copyright 2009 Texas Instruments All Rights Reserved Low power operating modes (3/11)  Low power modes (LPM):  Example: Typical current consumption (41x family).

UBI >> Contents 6 Copyright 2009 Texas Instruments All Rights Reserved Low power operating modes (4/11)  Low power modes (LPM): ModeCurrentSR bits configurationClock signalsOscillator  [A] CPUOFFOSCOFFSCG1SCG0ACLKSMCLKMCLKDCODC gen. Low-power mode 0 (LPM0) Low-power mode 1 (LPM1) * Low-power mode 2 (LPM2) Low-power mode 3 (LPM3) Low-power mode 4 (LPM4) * DCO’s DC generator is enabled if it is used by peripherals.

UBI >> Contents 7 Copyright 2009 Texas Instruments All Rights Reserved Low power operating modes (5/11)  Low power modes (LPM) characteristics:  LPM0 to LPM3: Suitable for periodic processing based on a timer interrupt; LPM0: Both DCO source signal and DCO’s DC gen.; LPM0 and LPM1: Main difference between them is the condition of enable/disable the DCO’s DC generator; LPM2: DCO’s DC generator is active and DCO is disabled; LPM3: Only the ACLK is active (< 2 μA).  LPM4: Externally generated interrupts; No clocks are active and available for peripherals. Reduced current consumption (0.1 μA).

UBI >> Contents 8 Copyright 2009 Texas Instruments All Rights Reserved Low power operating modes (6/11)  Program flow steps:  Enter Low-power mode: Enable/disable CPUOFF, OSCOFF, SCG0, SCG1 bits in SR; LPM is active after writing to SR; CPU will suspend the program execution; Disabled peripherals: –Operating with any disabled clock; –Individual control register settings. All I/O port pins and RAM/registers are unchanged; Wake up is possible through any enabled interrupt.

UBI >> Contents 9 Copyright 2009 Texas Instruments All Rights Reserved Low power operating modes (7/11)  Program flow steps:  An enabled interrupt event wakes the MSP430;  Enter ISR: The operating mode is saved on the stack during ISR; The PC and SR are stored on the stack; Interrupt vector is moved to the PC; The CPUOFF, SCG1, and OSCOFF bits are automatically reset, enabling normal CPU operation; IFG flag cleared on single source flags.  Returning from the ISR: The original SR is popped from the stack, restoring the previous operating mode; The SR bits stored in the stack are modified returning to a different operating mode after RETI instruction.

UBI >> Contents 10 Copyright 2009 Texas Instruments All Rights Reserved Low power operating modes (8/11)  Examples of applications development using the MSP430 with and without low power modes consideration: ExampleWithout low power modeWith low power mode Toggling the bit 0 of port 1 (P1.0) periodically Endless loop (100 % CPU load) LPM0 Watchdog timer interrupt UART to transmit the received message at a 9600 baud rate Polling UART receive (100 % CPU load) UART receive interrupt (0.1 % CPU load) Set/reset during a time interval, periodically, of the peripheral connected to the bit 2 of port 1 (P1.2) Endless loop (100 % CPU load) Setup output unit (Zero CPU load) Power manage external devices like Op-Amp Putting the OPA Quiescent (Average current: 1 A) Shutdown the Op-Amp between data acquisition (Average current: 0.06 A) Power manage internal devices like Comparator A Always active (Average typical current: 35 A) Disable Comparator A between data acquisition Respond to button-press interrupt in P1.0 and toggle LED on P2.1 Endless loop (100 % CPU load) Using LPMs while the LED is switch off: LPM3: 1.4 A LPM4: 0.3 A Configure unused ports in output direction P1 interrupt service routine

UBI >> Contents 11 Copyright 2009 Texas Instruments All Rights Reserved Low power operating modes (9/11)  Rules of thumb for the configuration of LP applications:  Extended ultra-low power standby mode. Maximize LPM3;  Minimum active duty cycle;  Performance on-demand;  Use interrupts to control program flow;  Replace software with on chip peripherals;  Manage the power of external devices;  Configure unused pins properly, setting them as outputs to avoid floating gate current.

UBI >> Contents 12 Copyright 2009 Texas Instruments All Rights Reserved Low power operating modes (10/11)  Rules of thumb for LP applications configuration:  Low-power efficient coding techniques: Optimize program flow; Use CPU registers for calculations and dedicated variables; Same code size for word or byte; Use word operations whenever possible; Use the optimizer to reduce code size and cycles; Use local variable (CPU registers) instead of global variables (RAM); Use bit mask instead of bit fields;

UBI >> Contents 13 Copyright 2009 Texas Instruments All Rights Reserved Low power operating modes (11/11)  Rules of thumb for LP applications configuration:  Low-power efficient coding techniques: Use unsigned data types where possible; Use pointers to access structures and unions; Use “static const” class to avoid run-time copying of structures, unions, and arrays; Avoid modulo; Avoid floating point operations; Count down “for” loops; Use short ISRs.

UBI >> Contents 14 Copyright 2009 Texas Instruments All Rights Reserved Timer Introduction (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;  Discusses the clock controls provided by the various MSP430 hardware platforms.

UBI >> Contents 15 Copyright 2009 Texas Instruments All Rights Reserved Timer 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).

UBI >> Contents 16 Copyright 2009 Texas Instruments All Rights Reserved Timer 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.

UBI >> Contents 17 Copyright 2009 Texas Instruments All Rights Reserved Clock signals  The clock signals are controlled by two sets of registers (4xx family):  The first set of registers configures the low-frequency signals for use by peripheral modules: Basic Timer Control Register (BTCTL); Basic Timer Counter 1 (BTCNT1); Basic Timer Counter 2 (BTCNT2).  The second set of registers is dedicated to the configuration of general-purpose system clocks: System Clock Control (SCFQCTL); System Clock Frequency Integrator 0 (SCFI0); System Clock Frequency Integrator 1 (SCFI1); Frequency Locked Loop control registers (FLL+CTL0, FLL+CTL1).

UBI >> Contents 18 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.

UBI >> Contents 19 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 f LCD : –Clock source: ACLK; –Frame frequency selectable by software (BTFRFQx): f LCD = 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.

UBI >> Contents 20 Copyright 2009 Texas Instruments All Rights Reserved Basic Timer1 (3/5)  Block diagram:

UBI >> Contents 21 Copyright 2009 Texas Instruments All Rights Reserved Basic Timer1 (4/5)  Registers:  BTCTL, Basic Timer 1 Control Register BTSSELBTHOLDBTDIVBTFRFQ1BTFRFQ0BTIP2BTIP1BTIP0 BitDescription 7BTSSELBTCNT2 clock select (together with the BTDIV bit) 6BTHOLD Basic Timer 1 hold:BTHOLD = 0BTCNT1 and BTCNT2 active BTHOLD = 1BTCNT1 hold, if BTDIV = 1 BTHOLD = 1BTCNT1 and BTCNT2 hold 5BTDIV Basic Timer 1 clock divider: BTSSEL BTDIV = 0 0ACLK BTSSEL BTDIV = 0 1ACLK/256 BTSSEL BTDIV = 1 0SMCLK BTSSEL BTDIV = 1 1ACLK/ BTFRFFQx LCD frame frequency:BTFRFQ1 BTFRFQ0 = 0 0f ACLK /32 BTFRFQ1 BTFRFQ0 = 0 1f ACLK /64 BTFRFQ1 BTFRFQ0 = 1 0f ACLK /128 BTFRFQ1 BTFRFQ0 = 1 1f ACLK / BTIPX Basic Timer 1 interrupt interval:BTIP2 BTIP1 BTIP0 = 0 0 0f CLK2 / 2 BTIP2 BTIP1 BTIP0 = 0 0 1f CLK2 / 4 BTIP2 BTIP1 BTIP0 = 0 1 0f CLK2 / 8 BTIP2 BTIP1 BTIP0 = 0 1 1f CLK2 / 16 BTIP2 BTIP1 BTIP0 = 1 0 0f CLK2 / 32 BTIP2 BTIP1 BTIP0 = 1 0 1f CLK2 / 64 BTIP2 BTIP1 BTIP0 = 1 1 0f CLK2 / 128 BTIP2 BTIP1 BTIP0 = 1 1 1f CLK2 / 256

UBI >> Contents 22 Copyright 2009 Texas Instruments All Rights Reserved Basic Timer1 (5/5)  Registers:  IE2, Interrupt Enable Register 2  IFG2, Interrupt Flag Register 2 70 BTIE BitDescription 7BTIEBasic Timer 1 interrupt enable when BTIE = 1 70 BTIFG BitDescription 7BTIFGBasic Timer 1 interrupt flag BTIFG = 1 when interrupt pending

UBI >> Contents 23 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.

UBI >> Contents 24 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.

UBI >> Contents 25 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).

UBI >> Contents 26 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).

UBI >> Contents 27 Copyright 2009 Texas Instruments All Rights Reserved Timer_A and Timer_B Introduction (5/6)  Block diagram (Timer_A):

UBI >> Contents 28 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) MCxModeDescription 0 StopThe timer is halted 0 1UpUp counting mode (from 0x0000 to the value in the TACCR0 or TBCCR0 register) 1 0ContinuousContinuous counting mode (from 0x0000 to 0xFFFF) 1 Up/downUp/down counting mode (from 0x0000 to the value in the TACCR0 or TBCCR0 register and back down to zero)

UBI >> Contents  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: t INT = 1/[f CLK /Prescaler/(TxCCR0+1)]. 29 Copyright 2009 Texas Instruments All Rights Reserved Timer_A and Timer_B operating modes (1/3)

UBI >> Contents 30 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: t INT = 1/[f CLK /Prescaler/65536];

UBI >> Contents 31 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: t INT = 1/[f CLK /Prescaler/(TxCCR02];

UBI >> Contents 32 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).

UBI >> Contents 33 Copyright 2009 Texas Instruments All Rights Reserved Timer_A and Timer_B registers  TACTL, Timer_A Control Register UnusedTASSEL1TASSEL ID1ID0MC1MC0UnusedTACLRTAIETAIFG BitDescription 9-8TASSELx Timer_A clock source:TASSEL1 TASSEL0 = 0 0TACLK TASSEL1 TASSEL0 = 0 1ACLK TASSEL1 TASSEL0 = 1 0SMCLK TASSEL1 TASSEL0 = 1 1INCLK 7-6IDx Clock signal divider:ID1 ID0 = 0 0/ 1 ID1 ID0 = 0 1/ 2 ID1 ID0 = 1 0/ 4 ID1 ID0 = 1 1/ 8 5-4MCx Clock timer operating mode:MC1 MC0 = 0 0Stop mode MC1 MC0 = 0 1Up mode MC1 MC0 = 1 0Continuous mode MC1 MC0 = 1 1Up/down mode 2TACLRTimer_A clear when TACLR = 1 1TAIETimer_A interrupt enable when TAIE = 1 0TAIFGTimer_A interrupt pending when TAIFG = 1

UBI >> Contents 34 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)

UBI >> Contents 35 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);

UBI >> Contents 36 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.

UBI >> Contents 37 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).

UBI >> Contents 38 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.

UBI >> Contents 39 Copyright 2009 Texas Instruments All Rights Reserved Timer_A and Timer_B Output modes (1/2)  Output operating modes (OUTMODx bits): OUTMODxModeDescription 0 0 0OutputThe output signal OUTx is defined by the bit OUTx 0 0 1Set OUTx = 1  timer = TxCCRx OUTx = 0  another output mode is selected and affects the output 0 1 0Toggle/Reset OUTx = toggle  timer = TxCCRx OUTx = 0  timer = TxCCR Set/Reset OUTx = 1  timer = TxCCRx OUTx = 0  timer = TxCCR Toggle OUTx = toggle  timer = TxCCRx The output period is double the timer period 1 0 1Reset OUTx = 0  timer = TxCCRx OUTx = 1  another output mode is selected and affects the output 1 1 0Toggle/Set OUTx = toggle  timer = TxCCRx OUTx = 1  timer = TxCCR Reset/Set OUTx = 0  timer = TxCCRx OUTx = 1  timer = TxCCR0

UBI >> Contents 40 Copyright 2009 Texas Instruments All Rights Reserved Timer_A and Timer_B Output modes (2/2)  Output examples:

UBI >> Contents 41 Copyright 2009 Texas Instruments All Rights Reserved Timer_A Cap/Com registers (1/2)  TACCTLx, Timer_A Cap/Com Control Register CM1CM0CCIS1CCIS0SCSSCCIUnusedCAP BitDescription 15-14CMx Capture mode:CM1 CM0 = 0 0No capture CM1 CM0 = 0 1Capture on rising edge CM1 CM0 = 1 0Capture on falling edge CM1 CM0 = 1 1Capture on both edges 13-12CCISx Capture/compare input select:CCIS1 CCIS0 = 0 0CCIxA CCIS1 CCIS0 = 0 1CCIxB CCIS1 CCIS0 = 1 0GND CCIS1 CCIS0 = 1 1V cc 11SCSSynchronize capture input signal with timer clock: SCS = 0Asynchronous capture SCS = 1Synchronous capture 10SCCISynchronized capture/compare input 8CAP Mode:Capture modeCAP = 1 Compare modeCAP = 0

UBI >> Contents 42 Copyright 2009 Texas Instruments All Rights Reserved Timer_A Cap/Com registers (2/2)  TACCTLx, Timer_A Cap/Com Control Register OUTMOD2OUTMOD1OUTMOD0CCIECCIOUTCOVCCIFG BitDescription 7-5OUTMODx Output mode:OUTMOD2 OUTMOD1 OUTMOD0 =  bit OUT OUTMOD2 OUTMOD1 OUTMOD0 =  Set OUTMOD2 OUTMOD1 OUTMOD0 = 0 1 0 Toggle/Reset OUTMOD2 OUTMOD1 OUTMOD0 =  Set / Reset OUTMOD2 OUTMOD1 OUTMOD0 =  Toggle OUTMOD2 OUTMOD1 OUTMOD0 =  Reset OUTMOD2 OUTMOD1 OUTMOD0 =  Toggle / Set OUTMOD2 OUTMOD1 OUTMOD0 =  Reset / Set 4CCIECapture/compare interrupt enable when CCIE = 1. 3CCICapture/compare input 2OUTOutput state 1COVCapture overflow when COV = 1 0CCIFGCapture/compare interrupt flag CCIFG = 1 when interrupt pending

UBI >> Contents 43 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.

UBI >> Contents 44 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.

UBI >> Contents 45 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.

UBI >> Contents 46 Copyright 2009 Texas Instruments All Rights Reserved Timer_B special features (1/3)  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;

UBI >> Contents 47 Copyright 2009 Texas Instruments All Rights Reserved Timer_B special features (2/3)  Double-buffered compare latches with synchronized loading:  In Timer_A, the signal generation in compare mode may cause noise during compare period updates because the TACRRx value is used directly to compare with the timer value;  To avoid this condition, the compare latches TBCLx, buffered by TBCCRx, holds the data for the comparison to the timer value in compare mode;  The CLLDx bits at the TBCCTLx register configure the timing of the transfer from TBCCRx to TBCLx.

UBI >> Contents 48 Copyright 2009 Texas Instruments All Rights Reserved Timer_B special features (3/3)  Grouping channels capability:  Multiple compare latches may be grouped together for simultaneous updates (the TBCLGRPx bits);  Two conditions are required: All TBCCRx registers must be updated; The load event controlled by the CLLDx bits must occur.  All outputs can be put into a high-impedance state:  TBOUTH = 1 puts Timer_B outputs into a high-impedance state, allowing higher security and lower delay time responding to failures.  The SCCI bit function is not implemented.

UBI >> Contents 49 Copyright 2009 Texas Instruments All Rights Reserved Timer_B registers special bits (1/2)  TBCTL, Timer_B Control Register UnusedTBCLGRP1TBCLGRP0CNTL1CNTL0UnusedTBSSEL1TBSSEL ID1ID0MC1MC0UnusedTBCLRTBIETBIFG BitDescription 14-13TBCLGRPxTBCLx group: TBCLGRP1 TBCLGRP0 = 0 0 Each TBCLx latch loads independently TBCLGRP1 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-11CNTLx Counter Length:CNTL1 CNTL0 = 0 016-bit, TBR(max) = 0FFFFh CNTL1 CNTL0 = 0 112-bit, TBR(max) = 0FFFh CNTL1 CNTL0 = 1 010-bit, TBR(max) = 03FFh CNTL1 CNTL0 = 1 18-bit, TBR(max) = 0FFh

UBI >> Contents 50 Copyright 2009 Texas Instruments All Rights Reserved Timer_B registers special bits (2/2)  TBCCTLx, Timer_B Capture/Compare Control Register CM1CM0CCIS1CCIS0SCSCLLD1CLLD0CAP OUTMOD2OUTMOD1OUTMOD0CCIECCIOUTCOVCCIFG BitDescription 10-9CLLDxCompare latch load: CLLD1 CLLD0 = 0 0TBCLx loads on write to TBCCRx CLLD1 CLLD0 = 0 1TBCLx loads when TBR counts to 0 CLLD1 CLLD0 = 1 0TBCLx loads when TBR counts: - to 0 (up/continuous mode); - to TBCL0 or to 0 (up/down mode) CLLD1 CLLD0 = 1 1TBCLx loads when TBR counts: - to TBCLx