Lab 3: Timer and Clock

Similar documents
ABSTRACT. List of Tables 1 Excitation, Sample/Hold, and Direct Comparator Input Configurations DCM Register Configuration...

Experiment 7 Fall 2012

MSP430F15x/16x/161x Device Erratasheet Current Version

Design and Implementation of Timer, GPIO, and 7-segment Peripherals

Hello and welcome to this presentation of the STM32L4 Analog-to-Digital Converter block. It will cover the main features of this block, which is used

Digital (5hz to 500 Khz) Frequency-Meter

SWITCH: Microcontroller Touch-switch Design & Test (Part 2)

CHW 261: Logic Design

RF4432 wireless transceiver module

Programmable Logic Design Techniques II

Tutorial Introduction

Chapter 4: One-Shots, Counters, and Clocks

STA2051E VESPUCCI 32-BIT SINGLE CHIP BASEBAND CONTROLLER FOR GPS AND TELEMATIC APPLICATIONS 1 FEATURES. Figure 1. Packages

RF4432F27 wireless transceiver module

Hello, and welcome to this presentation of the STM32 system window watchdog. It will cover the main features of this peripheral used to detect

HT162X HT1620 HT1621 HT1622 HT16220 HT1623 HT1625 HT1626 COM

o The 9S12 has a 16-bit free-running counter to determine the time and event happens, and to make an event happen at a particular time

Lab #10 Hexadecimal-to-Seven-Segment Decoder, 4-bit Adder-Subtractor and Shift Register. Fall 2017

o The 9S12 has a 16-bit free-running counter to determine the time and event happens, and to make an event happen at a particular time

Microcontrollers. Outline. Class 4: Timer/Counters. March 28, Timer/Counter Introduction. Timers as a Timebase.

TV Synchronism Generation with PIC Microcontroller

An Enhanced MM MHz Generator

Introduction to Mechatronics. Fall Instructor: Professor Charles Ume. Analog to Digital Converter

Point System (for instructor and TA use only)

Logic Gates, Timers, Flip-Flops & Counters. Subhasish Chandra Assistant Professor Department of Physics Institute of Forensic Science, Nagpur

Menu. 68HC12 Timer Block Diagram EEL 3744 EEL Input Capture (IC)

Digital Systems Laboratory 3 Counters & Registers Time 4 hours

Integrated Circuit for Musical Instrument Tuners

35058-TE. PLJ-6LED-A LED Frequency Display Module Manual

Application Note. RTC Binary Counter An Introduction AN-CM-253

Digital Fundamentals: A Systems Approach

Hello and welcome to this training module for the STM32L4 Liquid Crystal Display (LCD) controller. This controller can be used in a wide range of

Data Conversion and Lab (17.368) Fall Lecture Outline

Introduction. NAND Gate Latch. Digital Logic Design 1 FLIP-FLOP. Digital Logic Design 1

Chapter 5 Flip-Flops and Related Devices

C8188 C8000 1/10. digital audio modular processing system. 4 Channel AES/EBU I/O. features. block diagram. 4 balanced AES inputs

Counter/timer 2 of the 83C552 microcontroller

PGT104 Digital Electronics. PGT104 Digital Electronics

Experiment # 4 Counters and Logic Analyzer

EEE2135 Digital Logic Design Chapter 6. Latches/Flip-Flops and Registers/Counters 서강대학교 전자공학과

PESIT Bangalore South Campus

Laboratory Exercise 4

MSP430-HG2231 development board Users Manual

MSP430-H2618 development board Users Manual

Senior Design Project: Blind Transmitter

013-RD

C8000. sync interface. External sync auto format sensing : AES, Word Clock, Video Reference

Digital Clock. Perry Andrews. A Project By. Based on the PIC16F84A Micro controller. Revision C

TRIMBLE GPS / 10MHz REFERENCE MONITOR DISPLAY V January 2015

Solutions to Embedded System Design Challenges Part II

EEM Digital Systems II

Digital Circuits I and II Nov. 17, 1999

INTRODUCTION (EE2499_Introduction.doc revised 1/1/18)

Today 3/8/11 Lecture 8 Sequential Logic, Clocks, and Displays

Experiment 8 Fall 2012

ECE 2274 Pre-Lab for Experiment Timer Chip

C8000. switch over & ducking

Timing Pulses. Important element of laboratory electronics. Pulses can control logical sequences with precise timing.

AN1324 APPLICATION NOTE

Mission. Lab Project B

Lab #10: Building Output Ports with the 6811

An Introduction to CY8C22x45

CARLETON UNIVERSITY. Facts without theory is trivia. Theory without facts is bull 2607-LRB

A MISSILE INSTRUMENTATION ENCODER

Introduction. ECE 153B Sensor & Peripheral Interface Design Winter 2016

EECS 140 Laboratory Exercise 7 PLD Programming

Tutorial Introduction

Power Supply and Watchdog Timer Monitoring Circuit ADM9690

SPI Serial Communication and Nokia 5110 LCD Screen

Lab #5: Design Example: Keypad Scanner and Encoder - Part 1 (120 pts)

Exercise 2: D-Type Flip-Flop

DE2-115/FGPA README. 1. Running the DE2-115 for basic operation. 2. The code/project files. Project Files

MSP430 Teaching Materials

Combinational vs Sequential

Analog-to-Digital Converter

Burlington County College INSTRUCTION GUIDE. for the. Hewlett Packard. FUNCTION GENERATOR Model #33120A. and. Tektronix

DEDICATED TO EMBEDDED SOLUTIONS

Logic Analyzer Triggering Techniques to Capture Elusive Problems

Figure 30.1a Timing diagram of the divide by 60 minutes/seconds counter

PRE J. Figure 25.1a J-K flip-flop with Asynchronous Preset and Clear inputs

EKT 121/4 ELEKTRONIK DIGIT 1

In-process inspection: Inspector technology and concept

BABAR IFR TDC Board (ITB): requirements and system description

FLIP-FLOPS AND RELATED DEVICES

8-BIT MCU WITH SINGLE VOLTAGE FLASH MEMORY, DATA EEPROM, ADC, TIMERS, SPI

SDA 3302 Family. GHz PLL with I 2 C Bus and Four Chip Addresses

LATCHES & FLIP-FLOP. Chapter 7

EET 1131 Lab #12 - Page 1 Revised 8/10/2018

Copyright 2011 by Enoch Hwang, Ph.D. and Global Specialties. All rights reserved. Printed in Taiwan.

CS8803: Advanced Digital Design for Embedded Hardware

Special Applications Modules

Report on 4-bit Counter design Report- 1, 2. Report on D- Flipflop. Course project for ECE533

VARIABLE FREQUENCY CLOCKING HARDWARE

Laboratory 1 - Introduction to Digital Electronics and Lab Equipment (Logic Analyzers, Digital Oscilloscope, and FPGA-based Labkit)

Chapter 11 Sections 1 3 Dr. Iyad Jafar

M68HC11 Timer. Definition

FRQM-2 Frequency Counter & RF Multimeter

DT9834 Series High-Performance Multifunction USB Data Acquisition Modules

Name Of The Experiment: Sequential circuit design Latch, Flip-flop and Registers

Radio Clock with DCF77

Transcription:

CS4101 Introduction to Embedded Systems Lab 3: Timer and Clock Prof. Chung-Ta King Department of Computer Science, Taiwan

Introduction In this lab, we will learn more advanced timer operations and clocking of MSP430 LanuchPad Capture/compare block of the timer Characteristics of different clock sources and their settings Clock Timer 1

Interior of MSP430G2553 Clock system IO X Not available on 20-pin device Timer system 2

Recall: MSP430 Timer_A TAR (0170h): the counter itself TACTL (0160h): register to control TAR settings TACCR0 (0172h): target for counting Others: clock source selection, flags 3

Timer_A Capture/Compare Block Timer Block TACTL Capture/Compare Block TACCTL2 May contain several Capture/Compare Blocks Each C/C block is controlled by a control register, TACCTLx Inside each C/C block, the Capture/Compare Register, TACCRx, holds the count to configure timer But, all C/C blocks within Timer_A share the same timer block: TAR 4

Modes of Capture/Compare Block Compare mode: Compare the value of TAR with the value stored in TACCRx and update an output when they match Capture mode: used to record time events Records the time (value in TAR) at which the input changes into TACCRx The input, usually CCIxA and CCIxB, can be either external or internal from another peripheral or software, depending on board connections 5

Capture Basics 15 TAR 0 Clock Input Clock GPIO Pin (TACLK) Capture Input signal triggers transfer: Counter Capture Capture Input CCInA CCInB Software Counter Register (TAR) Capture/Compare Register (TACCR x ) Counter Overflow Action Interrupt (TAIFG) Capture Actions Interrupt (CCIFGx) Signal peripheral Modify pin (TAx.n) Capture time (i.e. count value) when Capture Input signal occurs When capture is triggered, count value is placed in CCR and an interrupt is generated 6

Compare Basics 15 TAR 0 Clock Input Clock GPIO Pin (TACLK) Counter Register (TAR) Counter Overflow Action Interrupt (TAIFG) when Counter = Compare Compare Actions can occur Capture/Compare Register (TACCR x ) Compare Actions Interrupt (CCIFGx) Signal peripheral Modify pin (TAx.n) Capture time (i.e. count value) when Capture Input signal occurs When capture is triggered, count value is placed in CCR and an interrupt is generated 7

TACCTLx 8

TACCTL cont d 9

Example of Compare Mode Exact behavior of a Capture/Compare Block depends on setting of the corresponding control register, e.g. TAR counts to TACCR0 and resets (i.e., TACCR0 determines frequency (along with TAR input frequency)) At Output Mode 3, EQU1 is set when TAR>TACCR1 (i.e., TACCR1 determines pulse width) 10

Lab 3 Basic 1: Flash both red and green LEDs at 1 Hz. The green LED should be on for 0.5 sec and off for 0.5 sec. The red LED should be on for 0.2 sec and off for 0.8 sec. Use TAR to keep a cycle time of 1 sec. Use TACCR1 to control the green LED and TACCR2 to control the red LED. Bonus: Flash the green LED at 1 Hz by polling Timer_A. When the button is pressed, run Basic 1 for 4.8 sec. Then, return to Flash the green LED at 1 Hz. 11

MSP430 Clock System Clock system 12

Needs for Clocking A timer is no more than a counter and has no direct concept of time. It is the programmer s job to establish a relation between the value in the counter and real time. This depends on the frequency of the clock for the timer. Clock Timer A clock is a square wave signal whose edges trigger hardware Systems usually have conflicting requirements for clocks 13

Different Requirements for Clocks Devices often in a low-power mode until some event occurs, then must wake up and handle event rapidly Clock must get to be stabilized quickly Devices also need to keep track of real time: (1) can wake up periodically, or (2) time-stamp external events Therefore, two kinds of clocks often needed: A fast clock to drive CPU, which can be started and stopped rapidly but need not be particularly accurate A slow clock that runs continuously to monitor real time, which must use little power and be accurate 14

Different Requirements for Clocks Different clock sources also have different characteristics Crystal: accurate and stable (w.r.t. temperature or time); expensive, delicate, drawing large current, external component, longer time to start up/stabilize Resistor and capacitor (RC): cheap, quick to start, integrated within microcontroller and sleep with CPU; poor accuracy and stability Ceramic resonator and MEMS clocks in between Need multiple clocks 15

Clock System of MSP430 Variety of osc sources on-chip (cheap, reliable) and offchip (accurate) Rich selection of oscillator sources routed to internal clocks 16

Clocks in MSP430 Name Description Used-by Typical Speed MCLK Master Clock CPU Fast SMCLK Sub-Master Clock Peripherals Fast ACLK Auxiliary Clock Peripherals Slow Master clock (MCLK): for CPU and some peripherals, normally driven by digitally controlled oscillator (DCO) Subsystem master clock (SMCLK): distributed to peripherals, normally driven by DCO Auxiliary clock (ACLK): distributed to peripherals, normally for real-time clocking and driven by a low-frequency crystal oscillator, typically at 32 KHz 17

Clock Sources Low- or high-frequency crystal oscillator, LFXT1: External; used with a low- or high frequency crystal; an external clock signal can also be used; connected to MSP430 through XIN and XOUT pins High-frequency crystal oscillator, XT2: External; similar to LFXT1 but at high frequencies Very low-power, low-frequency oscillator, VLO: Internal at 12 KHz; alternative to LFXT1 when accuracy of a crystal is not needed; may not available in all devices Digitally controlled oscillator, DCO: Internal; a highly controllable RC oscillator that starts fast 18

From Sources to Clocks Typical sources of clocks: MCLK, SMCLK: DCO (typically at 1.1 MHz) ACLK: LFXT 1 (typically at 32 KHz) 19

Controlling Clocks In MSP430, the Basic Clock Module is also an IO peripheral and can be controlled by registers, DCOCTL and BCSCTL1 3 DCOCTL (056h): configure DCO BCSCTL1 (basic clock system control 1, 057h): configure ACLK BCSCTL2 (basic clock system control 2, 058h): configure MCLK, SMCLK BCSCTL3 (basic clock system control 3, 053h): control LFXT1/VLO 20

Control Registers for Clocks Control Registers for Clock System DCOCTL and BCSCTL1 combined define the frequency of DCO, among other settings 21

DCOCTL (at Memory Address 056h) Tag-Length-Value DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation 22

Tag-Length-Value Tag-Length-Value (TLV) stores device-specific information in the flash memory to set DCOCTL and BCSCTL1 for DCO frequency BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; // Set range 23

BCSCTL1 BCSCTL1 = CALBC1_1MHZ; // Set range 24

BCSCTL2 MCLK SMCLK BCSCTL2 = SELM_3 + DIVM_3; // MCLK = VLO/8 25

BCSCTL3 In MSP430G2231 BCSCTL3 = LFXT1S_2; // Enable VLO as MCLK/ACLK src 26

Interrupt Flag Register 1 (IFG1) OFIFG oscillator-fault flag is set when an oscillator fault (LFXT1OF) is detected. IFG1 &= ~OFIFG; // Clear OSCFault flag 27

Recall Sample Code for Timer_A Flash red LED at 1 Hz if SMCLK at 800 KHz #include <msp430g2553.h> #define LED1 BIT0 void main (void) { WDTCTL = WDTPW WDTHOLD; // Stop watchdog timer P1OUT = ~LED1; P1DIR = LED1; TACCR0 = 49999; TACTL = MC_1 ID_3 TASSEL_2 TACLR; //Setup Timer_A //up mode, divide clk by 8, use SMCLK, clr timer for (;;) { // Loop forever while (!(TACTL&TAIFG)) { // Wait time up } // doing nothing TACTL &= ~TAIFG; // Clear overflow flag P1OUT ^= LED1; // Toggle LEDs } // Back around infinite loop } 28

Sample Code for Setting Clocks Set DCO to 1MHz, enable crystal #include <msp430g2231.h> (#include <msp430g2553.h> ) void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer if (CALBC1_1MHZ ==0xFF CALDCO_1MHZ == 0xFF) while(1); // If TLV erased, TRAP! BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; P1DIR = 0x41; // P1.0 & 6 outputs (red/green LEDs) P1OUT = 0x01; // red LED on BCSCTL3 = LFXT1S_0; // Enable 32768 crystal IFG1 &= ~OFIFG;// Clear OSCFault flag P1OUT = 0; // red LED off BCSCTL2 = SELS + DIVS_3; // SMCLK = DCO/8 // infinite loop to flash LEDs } 29

Lab 3 Basic 2: Flash the green LED at 1 Hz by polling Timer_A, which is driven by ACLK sourced by VLO. Hint: Since TAR register is 16-bit (0~65535) long, you should be careful of its overflow by using clock source Divider. 30