Lecture 22 - Time Keeping II - Recap - Do demonstration - Explain connectivity - Explain board - Input capture - Interrupt 10:10 Recap We are discussing Timer_A modules, with input capture and output compare. - 16-bit Timer_A module Programmable divider Programmable counting mode (up/updown/continuous) TA0 .. TA3 - Input Capture/Output Compare channels TAxCCRy capture-compare register TAxCCR0 is special purpose; serves as period register in up/updown counting modes, as well as for output compare. TAxCCR1,2,3,4 are additional capture-compare registers - Connectivity The timer IC/OC channels are marked as TAx.y Check the data sheet pin for port 2.6 -> TA0.3 This means that GPIO 2.6 is multiplexed with TA0/3 (IC/OC) So this pin can serve: - as GPIO input - as GPIO output - as IC channel for TA0CCR3 - as OC channel for TA0CCR3 Question: What is the TA IC/OC channel for the Green LED Green LED on Boost XL is P2.4 Pin P2.4 is attached to TA0.1 So green LED is driven by IC/OC channel TA0CCR1 J4.39 Red Led TA0.3 P2.6 J4.38 Green Led TA0.1 P2.4 J4.37 Blue Led TA2.1 P5.6 J4.36 not used TA2.3 P6.6 J4.35 not used TA2.4 P6.7 J4.40 Buzzer TA0.4 P2.7 Documentation needed: - Datasheet lists the pinout - BoostXL user guide and launchpad user guide explain connectivity 10:20 Output Compare events When timer When timer reaches reaches TAxCCRn TAxCCR0 Set Set / Toggle/Reset Toggle Reset Set/Reset Set Reset Toggle Toggle / Reset Reset / Toggle/Set Toggle Set Reset/Set Reset Set In continuous mode, the timer runs from 0 to FFFF. - When it hits TAxCCRn, it does the first activity - When it hits TAxCCR0, it does the second activity - Example from previous lecture: msp432-compare-0 TA0CCR0 is set at 0x8000 TA0CCR3 is set at 0x1000 Mode is SET/RESET So, timer runs from 0 to FFFF When it hits 0x1000, it is set When it hits 0x8000, it is reset +----------+ | | +-----+ +----------------+ 0x0 0x1000 0x8000 0xFFFF - Why is it useful to have multiple TAxCCRy? Because you can generate precisely related signals Example 2: msp432-compare-1 TA0CCR0 is set at 0x3FFF TA0CCR3 is set at 0x0000 TA0CCR1 is set at 0x2000 Mode is SET/RESET What waveform will we see? +---------+ | | + +-----------------------+ 0x0 0x3FFF 0xFFFF +-----+ | | +---+ +-----------------------+ 0x0 0x2000 0x3FFF 0xFFFF - We can also generate symmetrically related waveforms using the counter in updown mode Example 3: msp432-compare-2 TA0CCR0 is set at 0x8000 TA0CCR3 is set at 0x6000 TA0CCR1 is set at 0x2000 Mode is TOGGLE/SET What waveform will we see? +------:------+ | : | +---------+ : +---------------+ 0x0 0x6000 0x8000 +-----------:-----------+ | : | +----+ : +----------+ 0x0 0x2000 0x8000 10:30 Input Capture In the case of Input Capture, we copy the value of TAx into TAxCCRy The input capture event can be tied to the rising edge, falling edge, or both. The classic application of input capture is frequency measurement: Capture Capture +---------------+ +--------------+ | | | | +-----+ +---------+ +------ ||||||||||||||||||||||||||| => count number of cycles between two edges | | | | Value1 Value2 Delta = Value2 - Value1 If you know the clock period, you also know the physical time needed for Delta. Of course, you can only measure the frequency of signals that are much slower than the clock. Other applications of Input Capture are phase measurement and relative position of the upedge of one signal with respect to the next. +------------------ | Signal 1 ----------+ +--------- | Signal 2 ------------------+ ||||||||| There are two possible input capture channels per TAxCCRy: CCIA and CCIB You have to consult the data sheet to ensure that you are looking at the correct connection. The input capture example that we will discuss is attached to the blue LED. (schematic) It measures the number of clock cycles that elapse between turn-on events of the BLUE led. We are using IC channel TA2.4 To configure the input capture, we have to: - Configure timerA 2 to run in continuous mode - Configure input capture TA2.4 to capture upedge - Write an ISR tied to TA2.4 to read the input-capture value - Configure the input pins for TA2.4 in IC mode - Configure the TimerA in continous mode - Configure the input capture channel in TA2.4 Example (msp432-inputcapture-0) 10:50 Motor Control (Slides Texas Instruments Motor Compendium) PWM control of brushless DC motor