Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 3430 – Intro to Microcomputer Systems

Similar presentations


Presentation on theme: "ECE 3430 – Intro to Microcomputer Systems"— Presentation transcript:

1 ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Introduction to Microcomputer Systems University of Colorado at Colorado Springs Lecture #16 Agenda Today Input Capture Pulse Accumulation Concept Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

2 ECE 3430 – Intro to Microcomputer Systems
Input Capture Input Capture Function - Sometimes a microcontroller needs to measure time between internally or externally generated “events”. A feature of some microcontrollers, formally called input capture, allows the timer sub-system to measure these time periods. - The MSP430 (G2553) provides 3 input capture channels per Timer_A module. Each channel has an associated input pin on the microcontroller. Internal or external events are captured through these pins. - When an event occurs on a given input pin, the value of the main timer (TAR) is latched (or sampled) into a dedicated 16-bit register. Each input capture channel has a dedicated 16-bit capture register. - If another event occurs, a new TAR value is latched in over the previous and can be compared to the first event to obtain a relative time between events. Ex) Event Event (TAR = 0x0100) (TAR = 0x0200) If TAR pre-scale factor is 1 and TAR is clocked at 1 MHz--each timer tick is worth 1us of real-time. Time Between Events = (0x x0100) (time per TAR clocks) = (0x100) (1us) = (256) (1us) = 256us Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

3 ECE 3430 – Intro to Microcomputer Systems
Input Capture Input Capture Function Details - Input capture channels each use one of the port pins. Each channel allows the programmer to pick from one of two sources (CCIxA or CCIxB). Each port pin is bi-directional—so we need to make sure P1DIR is set properly. - There are two Timer_A modules in the G2553 part—each with 3 capture channels (Timer_A3). - The mapping from CCIxA and CCIxB to pins is specific to each channel and which Timer_A module is being used (see device-specific datasheet for these mappings). - The input CCIxA or CCIxB can be selected via the CCISx bits in the TACCTLx control register. - The event captured can either be a rising or falling edge of a digital signal (or both). The edge sensitivity can be defined independently for all channels via the CMx bits in the TACCTLx control register: Bit 15 Bit Capture disabled Capture on rising edges Capture on falling edges Capture on any edge Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

4 ECE 3430 – Intro to Microcomputer Systems
Input Capture Input Capture Function Details - When the input capture triggers, the current “TAR” value is latched into dedicated 16-bit registers: Input Capture Channel 0 = TACCR Input Capture Channel 1 = TACCR1 - P1SEL (in addition to P1DIR) may additionally need to be set to select the right input. - During input capture function, these registers are treated read-only by software! - When the trigger occurs, a “flag bit” (CCIFG) will be set in the appropriate TACCTLx register This flag only indicates that an event of interest has been captured. It is set even if interrupts are disabled. - These flags can be cleared by writing a ‘0’ to the corresponding flag bit: CCIFG = 0 = flag cleared, waiting for input capture event (RESET state) CCIFG = 1 = flag set, input capture event occurred sometime in the past - When using any timer registers, the Timer_A instance number is specified. Ex) TA0CCR0 (instance 0, channel 0) , TA1CCR0 (instance 1, channel 0). - If the Timer_A instance number is not specified, the assumption is instance 0. Ex) TACCR0 == TA0CCR0 Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

5 ECE 3430 – Intro to Microcomputer Systems
Input Capture Input Capture Function (Optional Interrupt) - Just as with the timer overflow, successful capture of an event can generate an interrupt—however this is not a requirement! - Just like all MSP430 interrupts, each input capture channel has a relative priority. Input capture channel 0 has a higher priority than all the other input capture channels (see interrupt vector table in device-specific datasheet). - The timer overflow and capture channel 1 and 2 interrupts share an interrupt vector, so the source of the interrupt must be determined. The TAIV register can be used to do this expediently. TAIV is set to a distinct value based on the highest-priority, pending timer interrupt. The associated flag is automatically cleared by hardware when this register is read. - Just like many other MSP430 interrupts, there is both a global and local interrupt mask involved: Global mask = GIE flag in the SR (this is a maskable interrupt) -> OK for CPU to accept Local mask = CCIE bit in appropriate TACCTLx register -> OK for timer to generate Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

6 ECE 3430 – Intro to Microcomputer Systems
Input Capture Input Capture Function Applications Comparing Arrival Times - You can attach multiple wires to the MSP430 and monitor edges as they come in to see which is first TACCR TACCR TACCR2 Period Measurement - Measuring ‘rising edge’ to ‘rising edge’ of a signal is the definition of PERIOD. Can also do ‘falling edges’ Delta TCNT Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

7 ECE 3430 – Intro to Microcomputer Systems
Input Capture Input Capture Function Applications Pulse Width Measurements - ‘rising edge’ to ‘falling edge’ is the pulse width. Flip Flop Behavior - When an edge hits the MSP430, we will be notified. We can grab data off of any other pin when this occurs (in an ISR?) D Q Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

8 ECE 3430 – Intro to Microcomputer Systems
Input Capture Input Capture Function Applications Duty Cycle Measurements - Measure of the “high time” with respect to total period. Typically expressed as a percent. Duty Cycle % = /T T Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

9 ECE 3430 – Intro to Microcomputer Systems
Input Capture Input Capture Function Watch out for timer rollover! If TAR rolls over more than once between input capture events. Ex) Capture 1 = 0xFFF Capture 2 = 0x If required, we need to add code to track if TAR rolls over. We can use the Timer_A counter overflow for this. - The “timer overflow interrupt” will tell us when TAR rolls-over. We can add an ISR that will increment a counter every time this happens. We can read the counter each time an input capture event occurs to see if there was TAR roll-over. - It is possible to account for one or more timer overflows—but if we account for more than one timer overflow, our arithmetic will exceed 16-bit limits and we’ll have to use multi-precision arithmetic in the MSP430. Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

10 ECE 3430 – Intro to Microcomputer Systems
Input Capture Input Capture Function Software needs to be fast enough! If trying to take measurements between multiple captures, software must have enough time to copy the capture register elsewhere (by reading it) before the next capture occurs. - The MSP430 hardware sets the COV (capture overflow) bit in the TACCTLx register if a second capture occurs before the associated TACCRx register is read. The COV flag indicates data loss. - Always set the SCS bit in the TACCTLx register (asynchronous capture is not useful). - The state of the associated input at the time of the capture can be checked via the SCCI bit in the TACCTLx register. The current input can be checked via the CCI bit. - For input capture, the CAP bit should be set to 1. Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

11 ECE 3430 – Intro to Microcomputer Systems
Pulse Accumulator Pulse Accumulator Applications Event Counting Anything that needs counting Assembly line Vending machine to monitor inventory. - Serial bit stream to know when 8-bits have arrived. Gated Accumulator Monitoring the time it takes for an event to come and go Seeing how fast an assembly line is moving. - Generating interrupts when a pulse exceeds a certain delta. -> Use gated time accumulation mode, pre-program counter, set up pulse accumulator counter overflow interrupt. Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

12 ECE 3430 – Intro to Microcomputer Systems
Pulse Accumulator Pulse Accumulator - Sometimes it is desirable to have an external circuit count external events. The external events manifest themselves as digital pulses—either 0->1->0 pulses or 1->0->1 pulses. - Some microcontrollers provide a circuit to do just this. It is called a pulse accumulator. - Our MSP430 has no dedicated hardware for this—but we can use Timer_A features to do this. - A pulse accumulator can either count external events (event counting mode) or count the number of clock cycles that occur when the pulse accumulator input is asserted (gated time accumulation mode). - How could we make the MSP430 reliably count events? - How could we make the MSP430 accumulate the total time that a signal is asserted? Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014


Download ppt "ECE 3430 – Intro to Microcomputer Systems"

Similar presentations


Ads by Google