hw3_A09_sol

hw3_A09_sol - ECE2801 Homework #3 — Clocks &...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE2801 Homework #3 — Clocks & Timers Solutions Refererence: MSP430 User's Guide Ch. 4, 11 & 13 1) b)" SCFQCTL = 0x1F = 0001 1111 SCFIO = 0x42 = 0100 0010 SCF11= 0x76 = 01110110 FLL_CTLO = 0x00 = 0000 0000 FLL_CTLI = 0x20 = 0010 0000 ACLK= fCrystal = 32768 Hz (LF crystal frequency) FLL_CTLl = 0x20 —> FLL_D|VX =00 (l1) ACLK/n = ACLK=32768 Hz SCF10=b'01 00 00 10’ —>FLLDx=O1 (l2) SCFQCTL = 0x1F —+ N=31 FDCO=D*(N+1)*fcfysta1 = 2*1.048576 MHz POGO/D: 1.048576 MHz FLL_CTLO = 0x00 —> DCOPLUS =0 FDCOCLK= FDcom: 1.048576 MHz FLL_CTLl = 0x20 _> SELMx=00 (MCLK=DCOCLK), SELS=O (SMCLK=DCOCLK) FDCOCLK= FDCO/D= MHZ SCFQCTL = 0x02 = 0000 0010 SCFIO = 0x13 = 0001 0011 SCFII = 0x6A = 01101010 FLL_CTLO = 0x40 = 0100 0000 FLL_CTL1= 0x16 = 00010110 ACLK= fCrystal = 32768 Hz (LF crystal frequency) FLL_CTLI = 0x16 —> FLL_D|VX=10 (l4) ACLK/n=8192 Hz SCFIO=b'0001 0011' —+FLLDx=00 (l1) SCFQCTL = 0x02 —> N=2 FDco=D*(N+1)*fc,ystal = 1*3*32768Hz = 98,304 Hz FDCO/D= 98,304 Hz FLL_CTLO = 0x40 —» DCOPLUS =0 FDCOCLK= FDCO/D= 98,304 HZ FLL_CTL1 = 0x16 _» SELMx=1O (MCLK=XT2CLK), SELS=1 (SMCLK=XT2CLK) MCLK=SMCLK=XT2CLK= 8 MHz 2) For a certain program, it is noted that Timer_B control registers have the values shown below. Use the MSP430 User's Guide to decode the bit fields for each register. Assume the clock signal MCLK = SMCLK = DCOCLK = 1.048567 MHz, ACLK = 32768Hz, describe what function Timer_ B has been configured to have? (10 pts) TBCTL = 0x0150 TBCCRO = 0x147 TBCCTLO = 0x0010 Solution: TBCTL = b'0000 0001 0101 0000' —> CNTLx= 00 (16-bit timer_B), TBSSELx=01 (Timer_B clock source is ACLK), le=01 (input divider is /2), MCx=01 (Up mode), etc. TBCCTLO = b'OOOO 0000 0001 0000' ——> CAP=0 (compare mode), CC|E=1 (CCIFG interrupt enabled) TBCCRO =0x147 —> This value will be written into compare latch TBCLO. So the timer_B has been set up to operate in up mode. The Timer_B will start repeatedly counts up from O to the value of compare latch TBCLO. Once the timer counts from TBCLO-1 to TBCLO, the TBCCRO CCIFG interrupt flag is set. The number of timer counts in the period is TBCLO+1. When the timer value equals to TBCLO, it restarts counting from 0 again. Since timer_B clock source is ACLK=32768, TBCLO=OX147=327. So the timer_B interrupt period = 327/32768 = 0.01 sec. So timer_B has been configured to generate interrupts every 0.01 second. 3) An automated manufacturing process is controlled using an MSP430F449. The execution of the critical step in the process must be timed to Within 0.8 millisecond. Variances greater than 0.8 ms can cause the yield of the process to decline dramatically. Design a timing program suitable for timing this critical operation assuming that SMCLK = XTZCLK = 8.0 MHZ. Show how Timer B would be setup and your interrupt service routine. Will you need to use any leap counting to maintain the accuracy of your timer? Also Show how you'd convert your count to milliseconds and seconds like ssmmmm (to 4 decimal places). // Declare global variables long unsigned int timer = O; unsigned int 55, mm; void setupTimerB (void) { TBCTL = TBSSEL_2 + CNTL_0 + IDWO + MC_1; TBCCRO = 6400; // 6400 ticks at 8MHz is 0.8 millisec TBCCTLO = CCIE; } #pragma vector = TIMERBOJECTOR __interrupt Timer_BO (void) { timer++; } mm = (timer*8)%10000; // find tenths of milliseconds ss = (timer*8)/10000; // find seconds Now assume that the crystal in your timer actually oscillates at 7999800 Hz. What would the error associated with your timer at the end of the 2 minute long assembly batch given that you designed your timer assuming SMCLK = 8.0 MHz exactly. Will you timer be fast of slow? error=(6400 tics)*(8.0E6 Hz) - (6400 tics)*(7,999,800 Hz) 2 20 nsec off every 0.8 millisec (120 sec /0.8 millisec) = 15,000 occurrences of 0.8 millisec in 2 min. 20nsec>< 15,000 occurrences=3 milliseconds slower than real time a. 365 days * 24 hours/day * 60 minutes/hour* 60 seconds/minute =31,536,000 seconds peryear 232 = 4,294,967,296 < 31,536,000 -> a days worth of seconds does fit into a 32-bit integer b. 1 nanosecond =1 * 10‘9 seconds 64-bit unsigned integer=264 = 1.84467441 * 1019 60 minutes/hour * 60 seconds/minute * 1e9 ns/sec= 3.6e12 ns_/hr (2"64)/(3.6e12) = 5124095576 hours Convert to years —> 5124095576 hours * 1 day/24 hours * 1 yr/365 days = 5843424174 —> 584 years 0.9424174 years * 365 days/1yr= 343.89351 -> 343 days 0.89351 days * 24 hours/1 day = 21.44424 -> 21 hours 0.44424 hours * 60 minutes/1hr: 26.6544 -> 26 minutes 0.6544 minutes * 60 seconds/1 min = 39.264 —> 39 seconds 0.264 seconds * 1e9 ns/1 sec = 264000000 -> 2.64e8 nanoseconds Note: Answers may vary based on rounding error. i I c. //One implementation forthis problem is shown below #include "msp430x44x.h" #include<stdio.h> ‘ #include <math.h> //forthe floorfunction longintyear=0; * longint month = 0; longint day: 0; longint hour=0; longint minute =0; long int second = 0; unsigned long int timeUTC; unsigned long int tempTime; unsigned longintjdn; unsignedlongjd; //Convertthe UTCtime given intoJulian day(1-365), hours, minutes and seconds unsigned long convertUTC(void) { tempTime =timeUTC; //move the UTCtime into a temp variable to perform calculations on //and preserve the UTCtime ifwe need it later. //Separate out all of the values we need to converttoj ulian day second =tempTime %60; tempTime /=60; minute =tempTime %60; tempTime /=60; hour=tempTime%24; tempTime /=24; day=tempTime % 365; tempTime/= 365; month = tempTi me %12; year=tempTime; //Calcu|ate a,yand m a = floor((14-month)/12); y= year+ 4800 -a; m = month+ 12*a - 3; //Calcuate theJulian Day Number jdn = day+ floor((153*m + 2)/5) + 365*y +floor(y/4) - 32083; //Calculate the full Julian date (day, hour, minutes, seconds) jd =jdn+ (hour- 12)/24 + minute/1440+ second/86400; //return thejulian date returnjd; d. Convertto years 1,005,679 seconds * 1 minute/SOsec * 1 hour/60 mins * 1 day/24 hrs * 1 yr/365 days = 0.0318898719 -> Oyears 0.0318898719 years * 365 days/ 1 year = 1163989324 -> 11 days 0.63980324 days * 24 hours/1 day = 15.35527776 -> 15 hours 0.35527776 hours * 60 minutes/1hr: 213166656 -> 21 minutes 0.3166656 minutes * 60 seconds/1 min = 18.999936 -> 18.999936 seconds -> "19 seconds Starting atJanuary lst 12:00 AM, it will beJanuary 12th? 3:21:19 PM with a count of 1,005,679 seconds. e. //Set up ti me rB void time(void) { //ACLK, 16 Bit, up mode, div=1 TBCTL = TBSSEL_1 + CNTL_O + MC_1 + |D__0; TBCCRO= 0x8000; //32768 tics = 1 second TBCCTLO = CCIE; //enab|e interrupts } #pragma vector: TIMERBO_VECTOR //l nte rrupt Service Routine (ISR) -> lncrementi every second _interrupt void Time r_B0(void) { timeUTC++; // global unsigned longint for counting purposes } ...
View Full Document

Page1 / 5

hw3_A09_sol - ECE2801 Homework #3 — Clocks &amp;amp;...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online