ECE 3430 – Intro to Microcomputer Systems

Slides:



Advertisements
Similar presentations
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Advertisements

Chung-Ta King National Tsing Hua University
More fun with Timer/Counters
4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
Microcontroller Programming II MP6-1
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
EET 2261 Unit 10 Enhanced Capture Timer  Read Almy, Chapter 20.  Homework #10 and Lab #10 due next week.  Quiz next week.
Introduction of Holtek HT-46 series MCU
ECE 372 – Microcontroller Design Parallel IO Ports - Interrupts
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
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.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
ECE 371- Unit 11 Timers and Counters (“Stop Watches and Alarm Clocks”)
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
ARM Timers.
MSP430 Mixed Signal Microcontroller – Parte 2 Afonso Ferreira Miguel Source: slau056d – Texas instruments.
Unit 10.2 Timer Examples. Example – Music Generation Channel 6 – Set up as a timer Output to Generate Square Waves Channel 4 – Set up as a timer Output.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
ECE 447 Fall 2009 Lecture 10: TI MSP430 Timers and Capture Modes.
Lecture 11: TI MSP430 Timers Compare Modes
ECE 447 Fall 2009 Lecture 7: MSP430 Polling and Interrupts.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
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.
A walk through interrupts on the PPC 823
EET 2261 Unit 13 Enhanced Capture Timer
Why are Timer Functions Important?
Lecture 10: TI MSP430 Timers and Capture Modes
Application Case Study Security Camera Controller
ECE 3430 – Intro to Microcomputer Systems
Lecture 8: TI MSP430 Interrupts, ISRs
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
8085 Interrupts LAKSHMI.B.E..
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
PWM and DC Motor Control
68HC11 Interrupts & Resets.
Mon. Oct 2 Announcements Quiz Postponed to Wednesday – still only on 2.a + 2.b Video lecture for 2.a posted Lab 6 experiment extension You must come to.
Timer and Interrupts.
UNIT – Microcontroller.
BITS EDU. CAMPUS , VARNAMA
ECE 3430 – Intro to Microcomputer Systems
AVR Addressing Modes Subject: Microcontoller & Interfacing
MSP432 ARM Timer Programming
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
Interrupt.
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
* * * * * * * 8051 Interrupts Programming.
ECE 3430 – Intro to Microcomputer Systems
I/O PORTS : MSP430x5xx devices have up to 12 digital I/O ports :
ECE 3430 – Intro to Microcomputer Systems
Interrupts Interrupt is a process where an external device can get the attention of the microprocessor. The process starts from the I/O device The process.
Programmable Interval timer 8253 / 8254
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Lecture 9: TI MSP430 Interrupts & Low Power Modes
Programmable Interval timer 8253 / 8254
Interrupts.
MSP432™ MCUs Training Part 6: Analog Peripherals
ECE 3430 – Intro to Microcomputer Systems
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Wireless Embedded Systems
ECE 3430 – Intro to Microcomputer Systems
Flip-Flops.
Presentation transcript:

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

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 1 Event 2 (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 = (0x0200 - 0x0100) (time per TAR clocks) = (0x100) (1us) = (256) (1us) = 256us Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

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 14 0 0 Capture disabled 0 1 Capture on rising edges 1 0 Capture on falling edges 1 1 Capture on any edge Lecture #16 ECE 3430 – Intro to Microcomputer Systems Fall 2014

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 = TACCR0 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

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

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. TACCR0 TACCR1 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

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

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

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 = 0xFFF0 Capture 2 = 0x0005 - 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

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

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

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