<< Chapter < Page Chapter >> Page >
In this lab, we will cover various timing options for the MSP430 and configure some more digital IO.

Clock setup

The following exercise will show you how to manipulate the clocking system on the MSP430. You may need to refer to the MSP430F16x Lite Development Board schematic and the User's Guide to correctly configure the clock as specified.

  • In order to easily check the state of the clock, output MCLK from a pin header. (HINT: Output MCLK from P5.4) Use the oscilloscope to observe the frequency of the clock, and to see the impact of the changes you will make. Without modifying the clock registers any further, at what clock rate is the processor running at? How is the clock currently configured in order to produce this built-in clock signal?
  • Take the following piece of code that attempts to configure the clock on the MSP430. It has one major caveat: it doens't work. It contains incorrect Macro definitions, incorrectly sets the appropriate bits one some registers, and most importantly, it doesn't enable that fastest oscillator for SMCLK and MCLK. Modify the appropriate lines in order to operate 7.37 MHz without deleting any lines of code. BCSCTL1 |= XTOFF; // XT2 = HF XTAL do { IFG1 = OFIFG; // Clear OSCFault flag for (i = 0xFF; i > 0; i--); // Time for flag to set } while ((IFG1 & OFIFG) != 0); // OSCFault flag still set? BCSCTL2 &= SELM0+DIVS1; // Enable fastest clocking mode
The preceding code should make the following happen:
  • XT2 must be turned on and is set as the high frequency oscillator.
  • Clear the oscillator fault interrupt flag. It is helpful to halt the processor until the processor is certain that the flag is cleared and the crystal has stablized. This is done by setting the flag bits in the Interrupt Flag Register to 1 .
  • Don't forget to stop the Watchdog Timer.
The power consumed by any computer system is directly proportional to it's clock speed. A new Pentium 4 can consume upwards of 100 Watts of power. Embedded devices try to consume as little power as possible, so it will only enable the features it absolutely needs and will run at the lowest possible clock frequency.
  • Change the configuration of the clock so that it uses the DCO and runs at ~200kHz. Why wouldn't we want to run at this rate all the time?

Got questions? Get instant answers now!

Led update

Using your new (fast) timer settings and your blinking light system from Lab 2 Problem 4 , modify the code so that each LED remains on for a half second. Basically, generate the same behavior as the original version but using the new clock settings. What were the original (much slower) settings for the clock? What was changed in order to keep the original blink rate?

Got questions? Get instant answers now!

Calculator

Write a program that does that following:

  • Write a funtion void led_num(int num) . The function will take a number as a perameter and will use the LEDs to display this number in binary. Be sure to check for overflow. Overflow occurs when you try to represent a number greater than the number of bits available. In the case of the LEDs, you can not represent a number greater than 3 bits. What is that number? You should put all the possible values for PxOUT in an array, in order to simplify your code.
The main program will do the following:
  • Each time button_1 is pushed the LEDs will count up (in increments of one) from zero to their maximum.
  • Each time button_2 is pushed the number currently displayed on the LEDs is added to an internal accumulator and the results will be displayed.
  • If button_1 is pushed again, the LED counter will count up from zero, and that number will be added to the running sum when button_2 is pushed.
  • Pushing the reset button will let you start over.

Got questions? Get instant answers now!

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Microcontroller and embedded systems laboratory. OpenStax CNX. Feb 11, 2006 Download for free at http://cnx.org/content/col10215/1.29
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Microcontroller and embedded systems laboratory' conversation and receive update notifications?

Ask