ECE2049 Homework #3 Clocks & Timers (Due Tuesday 9/19/17 At the BEGINNING of class) Your homework should be neat and professional looking. You will loose points if your HW is not properly submitted (by properly I mean stapled with a cover sheet including your ECE box number). Any code should be typed! Reading: Davies 2.6. 5.8, 8.3-4, 8.9-10, MSP430x55xx User's Guide Ch. 5,17 Problem 1 (20 pts) a) Check the MSP430F559 Launchpad Schematic. What are the exact frequencies of the crystals XT1 and XT2 on our lab board? b) To what frequencies are ACLK, MCLK and SMCLK set by default by Code Composer Studio? What are the range of possible clock frequencies for MCLK and SMCK? What is each clock (ACLK, MCLK and SMCLK) primarily used for? c) The following line is executed at the beginning of configdisplay() during system initialization by our demo project code. We are working with the clock system not digital IO. Why is it necessary? What does it do? Why do you think none of the buttons, or LEDs or the keypad, or scroll wheel, etc., use any port 5 pins? P5SEL = (BIT5 BIT4 BIT3 BIT2); d) Below are the values of the Unified Clock System registers for two different MSP430 applications. Use the MSP430x55xx User's Guide Chapter 5 and class notes to decode the bit fields for each register. What are the resulting values of ACLK, MCLK, and SMCLK in each case. (Hint: see Users Guide page 164 for f DCOCLK equations) UCSCTL0 = 0x12A8 UCSCTL1 = 0x0040 UCSCTL2 = 0x1004 UCSCTL3 = 0x0050 UCSCTL4 = 0x0044 UCSCTL5 = 0x0010 UCSCTL6 = 0xC0CC UCSCTL7 = 0x0403 UCSCTL8 = 0x0707 e) Write a C function (see prototype below) that expressly turns on both XT1 and XT2 (see UCSCTL6) and sets the frequency of MCLK and SMCLK either 1.8 MHz or 18MHz (or as close as you can get) depending on the value of the input argument. Explain whether you used XT1 or XT2 as source for DCO REFCLK for each frequency and why. Assume all other clock settings are to be left in their default state. You may still assume that P5.5-2 are set as shown in (c) at the top of configdisplay() and that they do not have to be configured by your function. Your code must be typed to be graded. void clks_1x_10x(unsigned char speed_option);
Problem 2 Time standards are very important to the scientific, engineering and computing communities. However, precisely keeping track of time all over the world is a deceptively tricky business. Watch this video and do a bit of Googling and tell me the following. (30 pts) a) What is Coordinated Universal Time (UTC)? What is the time zone for Colombo, Sri Lanka in terms of UTC, (e.g. Minsk, Belarus is UTC + 2:00)? In the scientific community, times are often written something like 19:00Z, read as 19 hundred Zulu. What is Zulu time? In computing, UTC based time scales usually store the current time as the number of seconds that have elapsed since the beginning of some epoch. Usually the number of elapsed seconds are stored in a 32-bit unsigned integer. b) What is the start date of the Network Time Protocol (NTP) epoch? If 0 seconds corresponds to midnight (i.e. 00:00:00) on the first day of the NPT epoch, how many full years plus days, hours, minutes and seconds can be stored in a 32-bit unsigned integer? In many systems it is more practical to just consider the seconds in the current year. The time format is modified such that a count of 0 seconds corresponds to midnight January 1 of the current year with a second variable holding the year. c) If a UTC-style clock counting whole seconds was initialized to 0 at midnight 1 Jan 2017 currently has a count of 19,400,000 seconds what day (i.e. date) and time is it? Like April 3, 8:43:02 am. Hint: Remember that days are counted from 1. d) An autonomous data logger device is to be placed on the ocean floor for 6 months during which it will automatically take various oceanographic measurements. It must be able to measure the time elapsed since deployment to within 5 millisecond throughout its operational life. The engineers have designed the device to record for a maximum of 200 days in case there were to be a delay in device retrieval. Can the engineers use a 32-bit unsigned integer to store time to within 5 ms inside this data recorder? Or, must they use a 64-bit variable? Explain your answer. e) How would you configure TimerA2 to implement a clock with 5 ms resolution assuming SMCLK has already been configured to equal 4 MHz? Write a C code segment (including the TimerA2 setup and TimerA2 ISR) implementing a clock that saves its time (count) to a variable of the appropriate size (as determined in part d). You do not have to configure the UCS registers to set the value of SMCLK. Your timer should generate interrupts only once per millisecond. Do you need leap counting? Explain. f) Create a C function that converts the timer count from parts d & e to recorder mission day, hours, minutes and sec.sss. The count of days should starts at 1 not 0 (e.g. Mission Day 1 00:00:00.000 is midnight on the first deployed day). Your code must be typed to be graded. You do not have to convert your results to ascii for display.
Problem 3 For a certain application TimerA2 has been configured as shown below. a) What is the exact time between interrupts. Assume that ACLK, SMCLK and MCLK are running at their default settings. (20 pts) void runtimera2(void) { TA2CTL = TASSEL_2 MC_1 ID_3; TA2CCR0 = 1310; TA2CCTL0 = CCIE; // enable Timer A2 interrupt } b) If the system clock and TimerA2 settings from part (a) are used implement a timing system, how long until the time displayed by that system is off by 0.005 seconds? By 0.01 seconds? Will the system be fast or slow? How do you know? c) Write the interrupt service routine for TimerA2 for this application. Include a single level of leap counting to keep the display accurate for longer. How long until you leap counting system is off my 0.005 sec. Your code must be typed to be graded. d) Assume the MSP430 clocks have been configured to the following frequencies. ACLK = 32,768 Hz MCLK = 2.0 MHz SMCLK = XT2 = 4.0 MHz What is the smallest time interval you could theoretically measure using TimerA2 assuming these settings for MCLK, SMCLK and ACLK? Could your MSP430 system actually function with the Timer set to that interval? Explain why or why not.
Problem 4 A new style of automated gas pump (controlled by an MSP430F5529) dispenses product a constant, fixed rate of 0.15 gallons per second. The pump needs to be able to calculate the total cost of the product dispensed to at least 1/10 th cent = 0.001 dollars. Right now the pump is design to work for gasoline products could be priced up to $9.00 per gallon. (30 pts) a. The MSP430 will use Timer A2 to measure how long the pump is depressed (i.e. how long product is being delivered). What timer interval should Timer A2 be set to in order to able to measure total cost to 0.1 cents accuracy for a products costing up to $9.00? Which requires finer time resolution to meet the 0.1 cent spec, a higher priced product or a lower priced one? b. Assume that SMCLK has already been configured to equal XT2. Write a function in C to setup TimerA2 using SMCLK divided by 2 as its clock to measure the interval you determined in part (a). Also show your interrupt service routine. c. Assume a user fills up with 12.3 gallons of gas and gas currently cost $6.76 per gallon (OK, assume we're in Europe some place). How long will the fill-up take. What is the accuracy of you pump in cents for gas at this price. Remember, the pump always dispenses at 0.15 gal/sec. d. Now assume that the XT2 crystal used with your MSP430F5529 is on the low end of its tolerance and actually oscillates at 4,000,025 Hz (i.e. it is 0.000625% off.) What would the error associated with your timer at the end of the 11.4 gallon fill up be given that you designed your timer assuming XT2CLK = 4.0 MHz exactly. Will your actual time count be fast of slow? By how much will you have overcharged or under charged for the gas? Explain.
ECE2049 Homework #3 Submitted by: ECE Box #: Date: Question Grade 1-20 2-30 3-20 4-30 Total (100):