microcontrollers - walter scott, jr. college of...

49
Microcontrollers with the Texas Instruments MSP430 Final Report Spring Semester 2008 By Daniel Michaud Jeremy Orban Jesse Snyder Prepared to partially fulfill the requirements for ECE 402 Department of Electrical and Computer Engineering Colorado State University Fort Collins, Colorado 80523 Report Approved: ________________________________ Project Advisor ________________________________ Senior Design Coordinator

Upload: phamtram

Post on 14-Mar-2018

237 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

Microcontrollers with the

Texas Instruments MSP430

Final Report

Spring Semester 2008

By

Daniel Michaud

Jeremy Orban

Jesse Snyder

Prepared to partially fulfill the requirements for ECE 402

Department of Electrical and Computer Engineering

Colorado State University

Fort Collins, Colorado 80523

Report Approved: ________________________________

Project Advisor

________________________________

Senior Design Coordinator

Page 2: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

ii

Abstract

Microprocessors are found or used in almost every aspect of modern engineering, so a good

understanding of their operation is a vital component of an electrical/computer engineering education.

The process of learning to use these powerful devices can be a daunting task for students with little or

no background in programming. A student is required to spend lots of hands-on programming time with

a microprocessor or microcontroller to effectively learn how it functions. This necessitates the use of

development tools. The type and quality of the development tools used in a lab setting have a significant

impact on how quickly a student grasps the concepts.

Dr. Bill Eads and Miguel Morales began an investigation into the use of the TI MSP430 microcontroller in

an effort to improve the quality of the Introduction to Microprocessors (ECE 251) course. This endeavor

would provide reduced costs and better development tools to the students in the course. The course

currently uses a Freescale product that has two major drawbacks: the cost of hardware and an

unfriendly user interface. The project goal was to retool the course lab work to be completed on the TI-

MSP430 microcontroller and have a group of test students complete the course with the new hardware.

Miguel started the project last year and wrote a significant amount of introductory material and several

of the labs. This year we took over the project, finished up the labs and supervised a group of 8

sophomore students who used the Texas Instruments controller instead of the Freescale controller.

During the course of the semester we found that the TI microcontroller was an improved educational

tool for use in lab work. The hardware was cheaper, more portable, and compatible with more

computers. The development software provided enhanced visibility of the current state of the

microcontroller. We found out that working with students as teaching assistants was more challenging

than expected. Overall, we felt like the students proved that our lab set would be a satisfactory

replacement for the current lab set. A significant obstacle preventing use of the MSP430 in the

curriculum at this point is the lack of a textbook for the microcontroller.

For the second semester of our project we decided to undertake the design and building of a useful real

world device that leverages the benefits of the MSP430. We designed and built a clock that will listen to

the government National Institute of Science and Technology WWVB radio station and set the clock time

correctly. The project consist of 2 major sections, first is the design and building of a radio receiver for

the 60kHz WWVB signal. Second is the design of a clock that keeps, displays and sets the time using the

input from the receiver. The project was a success and by E-Days we had a working receiver and clock

although we were unable to receive the signal inside the student center where E-Days was held.

This design project was a good learning experience for us. In the first semester we learned some of what

is needed to teach and in the second semester we gained valuable knowledge and experience in the

actual design and construction of a working device.

Page 3: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

iii

Table of Contents

Title ................................................................................................................................................... i

Abstract ............................................................................................................................................ ii

Table of Contents ............................................................................................................................ iii

List of Figures .................................................................................................................................. iv

List of Tables ................................................................................................................................... iv

I. Introduction ..................................................................................................................................... 1

II. Review of Previous Work ................................................................................................................. 3

III. Comparison of Technology .............................................................................................................. 4

IV. Lab Development & Completion...................................................................................................... 9

V. WWVB Atomic Clock NIST-F1 ......................................................................................................... 14

VI. Receiver Design .............................................................................................................................. 17

VII. Clock Design ................................................................................................................................... 21

VIII. Decoder Design .............................................................................................................................. 24

IX. Processor Interface ........................................................................................................................ 26

X. Project Integration ......................................................................................................................... 29

XI. Conclusions & Future Work ........................................................................................................... 31

References ..................................................................................................................................... 33

Bibliography ................................................................................................................................... 34

Acknowledgments.......................................................................................................................... 35

Appendix A – List of Abbreviations ............................................................................................... A-1

Appendix B – Budget ..................................................................................................................... B-1

Appendix C – MSP430 Code (Programmed in C) .......................................................................... C-1

Page 4: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

iv

List of Figures

Figure 1 – Axiom/Freescale Development Board ......................................................................................... 4

Figure 2 – Texas Instruments Development Board ...................................................................................... 5

Figure 3 – IAR Development Software for Texas Instruments EZ430 ........................................................... 7

Figure 4 – MiniIDE Development Software for Axiom / Freescale MC9S12C322 ......................................... 8

Figure 5 – WWVB Broadcast Antenna ....................................................................................................... 15

Figure 6 – 4AM coverage Map of the WWVB Signal ................................................................................. 15

Figure 7 – NIST-F1 Cesium Fountain Clock ................................................................................................. 16

Figure 8 – 680uH Ferrite Core Inductor ..................................................................................................... 17

Figure 9 – Pre-Rectified WWVB Signal ....................................................................................................... 18

Figure 10 – Post-Rectified Diode Signal ..................................................................................................... 18

Figure 11 – Receiver Output to Clock ......................................................................................................... 19

Figure 12 – Complete Receiver Schematic ................................................................................................ 20

Figure 13 – WWVB Time Code Format ...................................................................................................... 24

Figure 14 – Hitachi HD44780 Character Codes .......................................................................................... 26

Figure 15 – MSP430 & LCD Schematic ....................................................................................................... 28

Figure 16 – Time Display Format ............................................................................................................... 29

Figure 17 – Final Circuit Assembly ............................................................................................................. 30

List of Tables

Table 1 – Relevant Technology Differences .................................................................................................. 5

Table 2 – Completed Labs ............................................................................................................................. 9

Table 3 – Bit Type in WWVB Signal ............................................................................................................. 24

Page 5: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

1

Chapter I – Introduction

Microcontrollers are essentially a computer on a single chip. Many of the standard features of a

computer are packaged onto a single chip for purposes of cost, size, and power consumption. Most

microcontrollers include a math processing unit, the role that is filled by the Central Processing Unit

(CPU) in a system such as a desktop pc. Also included is Random Access Memory (RAM) and or Read

Only Memory (ROM). The memory is used for storage of both programs and data used by the

microcontroller. Another major component is I/O functionality. This hardware comes in different forms

and allows the microcontroller to interface with the outside world including the system it is being used

to control as well as other systems as needed. The last major hardware category found in a

microcontroller is signal processing hardware. This includes Analog-to-Digital and Digital-to-Analog

converters as well as other more specialized signal processing hardware specific to different

applications.

Microcontrollers are found in countless applications in modern systems. In general, the cost of a

microcontroller is relatively small for the benefit it can bring to a modern system design. Some very

common examples of microcontroller use are in automotive applications. A modern automobile

contains at least one, and probably several, microcontrollers. They are used for things like monitoring

the operating condition of the engine and making adjustments to things like fuel flow, air flow, and

spark timings to ensure maximum efficiency and power output. Another application would be to

monitor the speed of the car against how fast the tires are spinning to prevent tire lockups (anti-lock

brakes). Other automotive applications include cruise control, suspension control, and traction control.

Microcontrollers are also very common in robotic control, medical applications, mobile devices (like

voltmeters) and aerospace systems.

With the vast proliferation and usefulness of modern microcontrollers and microprocessors (which are

part of a microcontroller) learning how they operate and how to use them is a vital portion of any

electrical engineers education. At Colorado State University this topic is taught as a sophomore level

engineering class (ECE251) and for the last few years has been taught using a Freescale (formerly

Motorola) MC9S12C32 microcontroller. The microcontroller used in the class is provided by AXIOM

Manufacturing and has several drawbacks for use as an introduction to microprocessors class. These

drawbacks include cost, portability, computer interface, CISC architecture, and the software tools. These

issues are all improved on the Texas Instruments microcontroller we will be investigating and will be

explained in greater detail in the course of this report.

The primary function of this first phase of our project was to investigate the possibility of changing the

microcontroller used for the ECE 251 class at CSU. This project was started during the spring 2007

semester by Miguel Morales and we took over starting in the fall of 2007. Miguel started the project by

becoming familiar with the Texas Instruments EZ430, a small, inexpensive, and portable development

platform for the TI MSP430 microcontroller. He then started the process of developing a series of labs

for students to complete on the EZ430 instead of the Axiom board. During this first phase of our project

we have completed the development of these labs and mentored a test group of students as they

Page 6: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

2

worked through them. The second phase of our project will be to complete a design using the MSP430

for a practical application, which will be discussed in more detail in Chapter VII.

During the spring 2007 semester Miguel started the process of developing the labs for use in the ECE251

course. During the summer we took over the material and set about revising and polishing the labs in

preparation for the test students. The fall 2007 microprocessors course at CSU which is taught by Dr. Bill

Eads who is our advisor on this project. Dr. Eads selected a group of 8 test students who volunteered to

work with us and perform all the required labs using the TI EZ430 instead of the Axiom board the rest of

the students would be using. We each supervised our own lab sessions working with a couple of student

volunteers. Our experiences and conclusions will be the topic of the remainder of this report.

For the spring semester we wanted to design and build a working device that could leverage what we

had learned about the MSP430 in the previous semester as well and serve as an example of a useful real

world device that makes used of the MSP430. We were faced with only a single semester to complete

the project and we wanted a working system by the end of the semester. We decided to build a self

setting clock using the WWVB radio station.

WWVB is a radio signal broadcast by the National Institute of Science and Technology. The signal carries

a Pulse Width Modulated digital signal that contains the current time which is derived by an atomic

clock in Boulder Colorado. The NIST WWVB radio station is located in north Fort Collins Colorado.

The project was broken into two sections: the design and construction of a receiver that could pick up

the WWVB signal and output a digital signal for the MSP430 to decode and the building of a clock that

used the MSP430 to keep time and set time using the digital input from the receiver. Daniel Michaud

started out the receiver design and Jesse Snyder and Jeremy Orban worked on the tasks involving the

MSP430. Once both pieces were working they were integrated and debugged to end up with a complete

working WWVB radio clock.

This report will cover a brief review of the work done by Miguel last semester in Chapter II. We will then

cover the major differences between the Texas Instruments microcontroller and the Axiom

microcontroller in Chapter III. Chapter IV will briefly summarize the lab development process and issued

faced. Next, Chapter V will give background information on the WWVB radio station and the NIST-F1

atomic clock. The design of the receiver portion of our system is covered in Chapter VI. Chapter VII will

cover the clock design, followed by Chapter VIII, which covers the clock design. The processor interface

and hardware is discussed in Chapter IX. The integration of the project parts is reviewed in Chapter X.

Finally, Chapter XI will cover our conclusions for the year.

Page 7: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

3

Chapter II – Review of Previous Work

Miguel Morales, who now works for Texas Instruments in Dallas, began this project during the spring

2007 semester. He began his work gaining familiarity with the MSP430 by experimenting with

development kits donated by Texas Instruments and associated documentation. This process proved to

be complex and involved due to the fact that he started with little more than the hardware and a 400

page technical document. Miguel then collected the relevant information into some overview

documents and he began the process of developing the labs that would potentially be used by the ECE

251 students.

When we took over the project during the summer of 2007 we began preparing the labs for actual use

by sophomore level ECE students in the fall semester. We ran into a few problems as we began the

review process. The first problem was a the lack of any teaching material on the MSP430, the second

was that Dr. Eads decided that the test students would be required to learn both the Freescale and

Texas Instruments microcontroller. They completed all the homework and exams using the Freescale

microcontroller but all of the labs using the TI microcontroller. This required more investment of time

and energy from the students. It became obvious to us that the labs needed to contain all the

information the students would need to understand the differences between the Freescale and TI

microcontrollers to enable them to successfully complete the course. As a result we spent the majority

of our project time revising the labs that Miguel had completed as well as writing from scratch the labs

that were not yet completed.

Page 8: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

4

Chapter III – Comparison of Technology

Microcontrollers come in many varieties suited to fit individual applications. These varieties include

different amounts of on board memory, processing speed, input/output options, signal processing

capabilities, and instruction architecture. Most microcontrollers have a few options that are somewhat

standard including some amount RAM and ROM, input capture and output compare hardware, timers,

and analog-to-digital converters. For the purposes of this project it was important that the Texas

Instruments MSP430 (Figure 2) have the same basic functionality as the Freescale MC9S12C32 (Figure 1)

so that the basic content of the labs could remain unchanged.

This chapter will look at the relevant differences between the Freescale MC9S12C32 and the Texas

Instruments MSP430 microcontrollers. Most of the many differences between the Freescale and TI chips

are beyond the scope of this project and thus beyond the scope of this report. Table 1 below shows a

breakdown of the important technology differences between the microcontrollers which will then be

analyzed in more detail.

Figure 1: Axiom/Freescale Development Board [1]

Page 9: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

5

Figure 2: Texas Instruments Development Board [2]

Table 1: Relevant Technology Differences

Axiom/Freescale MC9S12C32 Texas Instruments MSP430-F2012

CISC Architecture RISC Architecture

8MHz Max Clock Speed 16MHz Max Clock Speed

3-16 bit Registers 11-16 bit Registers

32kB ROM 2kB ROM

2kB RAM 128B RAM

60 Accessible Pins 14 Accessible Pins

RS232 Computer Interface USB Computer Interface

Text Based Development Software Window Based Development Software

Cost - $80 Cost - $20

Page 10: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

6

The overall architecture of a microprocessor can be placed in one of two categories, Complex Instruction

Set Computers (CISC) and Reduced Instruction Set Computers (RISC). The Freescale chip is a CISC

processor whereas the TI is a RISC processor. The biggest difference between these two architectures is

the number of processor instructions available to the user. An instruction is command given to the

microcontroller as part of a program that tells it what to do. For example the command “add R4,R5” tells

the TI chip to add the contents of registers 4 and 5 together. A CISC designed microprocessor has many

instructions available to the user that range from simple load and save commands to complex

mathematics. The downside to this design from a teaching standpoint is that the student is faced with a

large number of instructions to learn (approximately 200 for the Freescale chip). On the other hand a

RISC microprocessor has far fewer instructions (approximately 30 for the MSP430). A RISC processor is

capable of all the same functionality as a CISC processor however the programmer may be required to

write several lines of code to complete what the CISC system can do with a single instruction. For a

student learning how to use these devices for the first time, having fewer instructions and as a result

writing more code to achieve the same behavior can help increase student understanding of the subject.

In the case of these two microcontrollers there is a significant difference in the maximum operating

speed and number of registers available to the programmer to use. The TI chip is capable of operating at

a frequency of 16MHz which is double the operating frequency of the Freescale chip. This speed is

directly related to the time needed per instruction given to the processor, thus the TI chip is, in many

cases, faster than the Freescale chip. The Freescale has only three 16 bit registers compared to the TI’s

eleven. These registers are fast access RAM that the microprocessor uses during the execution of a

program. The more of these memory spots available to the programmer, the less RAM and ROM access

(slow operations) are needed. Thus this difference leads to increased program operation speed. While

the TI chip may be faster and have more registers, speed is not the only consideration in a

microcontroller. Often the microcontroller is already so fast that it spends more time waiting on the

device it is controlling than it does actually doing any work. The labs completed in the ECE 251 course

never even approach the capabilities of either of these microcontrollers; however, the extra registers in

the TI chip do make writing programs simpler for the students.

Another difference between these microcontrollers is the amount of RAM and ROM available to the

developer to use. The Freescale has 32kB of ROM vs. the TI’s 2kB and 2kB RAM vs. the TI’s 128B. The

ROM is used to store the programs and data used by the microcontroller, and the RAM is used during

the operation of those programs. It is easy to see from these numbers that the Freescale chip is capable

of much larger programs and data storage. The lab work in this course never required more than 2kB of

ROM, so the lack of ROM was not a concern with the TI chip. However one lab did require all 128Bytes

of RAM in the TI chip so we had to be creative and change the memory management required for the

lab. Any larger memory requirements would have presented a problem with using the specific MSP430

model we used. There are other models of the MSP430 available that have more RAM & ROM if

desired.

Interfacing the microcontroller with the outside world is vital to any control application. In this case the

Freescale has a large advantage in that it has a full 60 pin input/output interface whereas the TI is

limited to 14. Some of these pins on both microcontrollers are used for power and ground leaving fewer

Page 11: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

7

for data I/O. This difference in I/O options did present some minor problems during the development of

our labs however some creative multiplexing methods were used to work around these problems and

we feel that these solutions were a good learning exercise for the students in terms of finding ways to

work around limited data transfer pins.

Some other advantages of the TI MSP430 over the Freescale include its compact size and computer

interface. The Axiom board, which uses the Freescale microcontroller, uses an RS232 interface which

previously was a standard on any modern personal computer system but is quickly being replaced by

USB. Every year this presents more and more challenges to students who wish to work on the labs at

home or on their laptops. This issue is completely resolved by the TI chip which runs on the new

standard USB interface. In addition to this the TI microcontroller uses a very user friendly development

software called IAR (Figure 3) which includes the ability to see the contents of all the RAM, ROM, and

registers in the microcontroller on the screen. The Axiom development board uses text-based software

called MiniIDE (Figure 4). To see the contents of a memory location or register in this IDE, the developer

must type in commands to display the information. This is slow and frustrating compared to the IAR

system used by the TI microcontroller.

Figure 3: IAR Development Software for Texas Instruments EZ430

Page 12: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

8

Figure 4: MiniIDE Development Software for the Axiom/Freescale MC9S12C322

The largest advantage the Texas Instruments microcontroller has over the Axiom microcontroller for use

in education is cost. The EZ430 development kit shown in Figure 2 has a retail price of only $20 vs. $80

for the Axiom / Freescale kit shown in Figure 1. This cost difference is significant considering the rising

costs of education. A change in microcontroller for the ECE 251 course will save the students money

while enhancing the quality of their education.

Page 13: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

9

Chapter IV – Lab Development & Completion

As mentioned previously in this report one of the biggest components of the lab phase of the project

was to revise and compose the labs to be completed by the volunteer group of students using the TI

MSP430 microcontroller. One of our goals was to make the new lab tasks as similar as possible to the

ones completed by the rest of the students in the course using the Freescale microcontroller. Miguel

Morales started this process during the 2007 spring semester and completed several labs that we then

revised (see Chapter II). The students in both groups were required to complete all 8 MSP430 labs and 2

practical exams in lab using the MSP430. We wrote practical exams that would provide an almost exact

test of the students’ knowledge compared to the preexisting practical exams.

Another requirement of this segment of the project was to oversee the test students’ progress in the

labs using just the MSP430. We then incorporated their comments/suggestions about how to improve

the labs. This set up would be used as a way to judge whether or not the MSP430 could be used as an

effective educational tool for ECE 251. Each of us had a weekly lab session in which the students would

come and work on the labs, demonstrate completion of the labs and complete practical exams. We

were in charge of their grades for the course as well. Since Dr. Eads did not cover the instruction set for

the MSP430 in class, we were required to teach the students how to use the MSP430.

Table 2 shows a list of the labs the students were required to complete along with in which appendix the

lab document can be found. Following the table is a brief overview of each lab with the exception of

labs 1 and 2 which are review and introductory material that do not include material from either the

Freescale or TI microcontrollers.

Table 2: Completed Labs

Lab Number Lab Title Appendix Author

Lab 3 Hardware and Software Setup A Daniel/Miguel

Lab 4 Addressing Modes and Branching B Jeremy

Lab 5 Subroutines and The Stack C Daniel

Lab 6 Binary Coded Decimal Math D Jesse

Lab 7 Parallel I/O and Keyboard Scanning E Jesse/Miguel

Lab 8 Maskable Interrupts F Jeremy/Miguel

Lab 9 Input Capture and Output Compare G Daniel/Miguel

Lab 10 Analog to Digital Converter H Jesse/Jeremy

Page 14: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

10

Lab 3 – Hardware and Software Setup

Lab 3 is a short basic lab that introduces the students to the process of installing the EZ430 drivers and

the IAR development software on a computer. The students are first walked through the process of

installing the drivers and software on a windows based computer. They then setup a project in the IAR

software, compile a test program and load it onto their EZ430 chip. The students are then introduced to

the basic tools in the IAR development tool including monitoring the progress of the test program,

seeing how it works on the actual hardware, and debugging any problems in the code.

Lab 4 – Addressing Modes and Branching

This lab covers the basics of memory addressing and program branching with the MSP430. The

requirements of this lab include basic hexadecimal math as well as modification of an existing program.

The program that must be modified contains a variety of addressing modes and branching techniques to

help the students become accustomed to their usage without the need to determine where to use each

type in a program. The student is also required to complete a set of questions about the result of simple

move operations using different addressing methods. Lab 4 also covers an introduction to some of the

basic assembler directives which are used with the MSP430.

Lab 5 – Subroutines and the Stack

In this lab the students are introduced to subroutines, which are used to break the program code into

manageable and repeatable sections. The stack is a memory management method that simplifies the

passing of data between subroutines and other programs within the system. The students are also

introduced to using the known time it takes to complete a specific instruction based on the operating

speed of the microcontroller to code a software delay, or a pause, in the execution of the program. This

is done by forcing the processor to complete a set number of empty program loops that do nothing but

keep it busy for a while. The students are then asked to write a program that could be used to control a

robot on a manufacturing line (a very simplified version of one anyway) that uses a subroutine to turn

on and off a paint nozzle with different colors and different delays between each coat of paint.

Lab 6 – Binary Coded Decimal (BCD) Math

Lab 6 introduces the students to working with binary coded decimal (BCD) mathematics including

addition, subtraction, multiplication and division. BCD is the representation of base 10 numbers only

using the first 10 hexadecimal numbers (0-9). The microprocessor is based on a base 16 system so that

all calculations done in hardware are in base 16. The students learn how to use special instructions with

the MSP430 so that they can do arithmetic decimally rather than hexadecimally. These instructions

work for addition and subtraction, but not for multiplication and division. For these, the students used

provided multiplication and division subroutines and wrote binary-to-BCD and BCD-to-binary programs

to perform the assigned arithmetic. First, the students would convert the numbers from decimal (BCD)

to binary, perform the arithmetic and then convert back to BCD.

Lab 7 – Parallel I/O and Keyboard Scanning

Page 15: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

11

This lab introduces the students to Digital Input/Output (I/O) with the MSP430 and some basic polling

methods. The students must learn how to read in external digital signals to the microcontroller, execute

a program that interprets the input signal, decides what action is necessary and finally outputs a signal

to external hardware. The students first read in inputs from a dual-in-line package (DIP) switch and

output either a low or high voltage digital logic signal to an LED. The students then must implement

software that interprets signals from several different switches and lights up an LED if exactly the right

combination is given. Finally, the students must interface to a sixteen button keyboard. Using polling

(constantly checking the signal), their program must find which hexadecimal key was pressed and be

intelligent enough to know when the key has been depressed before registering another key being

pressed.

Lab 8 – Maskable Interrupts

The purpose of this lab is to introduce students to the usage of maskable interrupts as well as the use of

the timer system on the microcontroller. The first requirement of this lab is to extend the last

requirement of lab 7 to make use of interrupts instead of polling. This helps ease the students into the

use of interrupts in a familiar environment. The second requirement of this lab is to create a binary

clock which counts in 4 second intervals (4 LEDs to count seconds in a minute and 2 LEDs to count

minutes). This task requires the use of the MSP430 timer module and associated maskable interrupts.

The students are also required to receive inputs to start, stop and reset the timer. Lab 8 is particularly

important to the students as the majority of real-world microcontroller applications make extensive use

of timers and interrupts.

Lab 9 – Input Capture and Output Compare

One of the powerful tools included in most microcontrollers is the ability to gather data through

incoming signals and or output data to other devices. One method this is done is using a timer system

alongside input/output hardware to analyze and produce digital signals. The TI MSP430 does this

through its input capture and output compare hardware. The input capture looks at an incoming digital

signal and looks for rising or falling edges. The edges trigger events in the timer system so a program can

be written to analyze the timer information and decode the incoming data. The same is true in reverse

of the output compare system, the timer system is used to create the correct delays and then the

output pin is switched between high and low voltages to create a digital signal. In this lab the students

are asked to write several programs to analyze incoming signals and save the correct information in

memory.

Lab 10 – Analog-to-Digital Converter

One of the most practical labs from the ECE 251 course is the analog-to-digital (A/D) converter lab. In

this lab, the students learn how program the A/D converter on board the MSP430. This analog

converter uses successive approximation to assign a digital value to an analog signal. For lab 10, the

students were to take in a voltage signal from a power supply anywhere from 0-3.6V and output that

value to a 2-digit 7-segment display. Essentially, the students created a digital voltmeter. The MSP430

USB interface provides 3.6V to the chip, so anything over this value would not be acceptable for proper

Page 16: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

12

operation. We were not sure about how much this value varied or how accurate the A/D converter was

because the display was typically within ±0.2 V whereas we would prefer strictly ±0.1 V for a margin of

error. This is something we will investigate more in our second semester project.

Practical Exams

There are two practical exams which cover the lab material taught throughout the semester. The first

exam covers material up to and including lab 6 while the second covers the remaining 4 lab assignments.

The purpose of these is to allow the students to demonstrate the skills they have learned as well as

show that they can work effectively under a time constraint. Practical Exam 1 requires students to use

subroutines and manipulate bits in memory. The student has the option to either pass the information

to the subroutine by value in a register for a lower point value or passing by reference on the stack for

maximum points. The second exam requires students to use a timer system along with I/O to begin an 8

second count when an input is set true and light an external LED when the time is completed. To get full

point for this exam the student must then configure the system to reset to the start state when the

input is set back to false.

Obstacles & Resolutions

One of the biggest challenges of the lab component of this project was working with the ECE 251

students. Each of our group members had no prior experience as a teaching assistant. This

inexperience led to some problems with the labs. There were several instances in which the students

would misinterpret information from one of us. There were also times when the students would be

unclear about what they were required to complete for the lab sessions. Usually the course has a single

teaching assistant, so being consistent among 3 different people was also a challenge. We did not

compose all of the lab assignments before the semester started. Therefore, as the semester progressed

we learned to explain better what was required for each lab and attempted to be clearer about how to

use the MSP430 microcontroller.

Some of the other challenges that we faced included unforeseen differences between the MC9S12C32

and the MSP430 microcontrollers. One of the biggest components of the MC9S12C32 lab set involved

the functionality to output to the screen and take inputs from the computer’s keyboard. Since the

MSP430 does not have this capability, we defined a different focus for lab 4. In lab 4, the students were

to write an elevator program that either went up or down to a floor specified by a keyboard input. The

elevator would be shown on the screen including messages such as “going up” or “going down.” For lab

4, we focused more on the major concept of the lab, addressing modes. Next, we faced a problem when

trying to write lab 6, binary-coded decimal (BCD) math. The algorithm for converting regular binary-to-

BCD requires a multiplier and divider. However, unlike the MC9S12C32, the MSP430 does not have the

functionality to complete this type of arithmetic natively. Therefore we decided to provide subroutines

to complete these tasks. The students had varying degrees of success using these subroutines, and in

fact, some decided to write their own subroutines.

Another issue that we faced in this project piece was that the timer on the MSP430 was not as accurate

as we expected. We were not able to complete the tasks nearly as accurately as with the MC9S12C32.

Page 17: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

13

After further research, we found a way to increase the accuracy, although not before the students

completed lab 9. One other major issue that we faced was that we did not have enough parallel I/O

ports with which to work. When interfacing with drivers and other external hardware, we did not have

as much flexibility as we would have liked. For lab 10 this meant having to be creative when using the

I/O ports when interfacing with the BCD to 7-segment display driver. A final issue that we faced was

that the USB tool required a driver that could only be installed by a privileged user. This would not be

an issue except for the fact that we do not have software installation privileges as is common in an

education environment. This limited students to a single university computer or their laptop to

complete the labs. At times we had to ask other students to move just so that we could complete the

labs. However, we found out that TI has released a new driver which resolves this concern. We would

definitely recommend using this new driver if the course does eventually switch to the MSP430.

There were several positive aspects for the project for the first semester. One of the greatest

advantages to our group of this phase of the project was that the development and teaching of these

labs helped us learn how to use the microcontroller. Another point of interest is that Rice University is

interested in our labs to be used for one of their microcontroller classes. The microcontroller has not

been previously used in education, so seeing interest in our work was definitely a positive result of the

project. However, there is still not a comprehensive textbook covering the use of the MSP430. Another

significant setback is that an adopting professor would have to write all new lecture notes for the

course. Considering these two major issues with the MSP430, we do not expect that our labs will be

used soon by our university. However, completing the labs gives the option to switch if the ECE

department decides that this is the best for the course.

Finally, we were concerned that the students who volunteered to complete the MSP430 labs would

have a disadvantage when it came to their understanding of the regular coursework. The students were

responsible for both microcontrollers including different functionality and instruction sets. Dr. Eads is

planning on adjusting their final grades to accommodate this problem. We feel that if the students did

not do well or fell behind it was partly due to the fact they were required to learn how to use both

microcontrollers. However, the most likely cause of the problem is that the course (as any current ECE

undergraduate would testify) is one of the most challenging and time-consuming lower level courses in

the ECE curriculum.

Page 18: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

14

Chapter V – WWVB and Atomic Clock NIST-F1

WWVB is the call sign of a radio station operated by the National Institute of Standards and Technology

or NIST. The station is located in Fort Collins, Colorado and broadcasts the official government time

using a Pulse Width Modulated encoding on a 60kHz carrier wave. The time that is transmitted is set by

an atomic clock that is located in Boulder Colorado and thus is very accurate. The carrier wave frequency

of 60kHz is stable and can be used as a reference frequency to test other equipment.

The history of WWVB is an interesting one. In July 1956 the NIST (was then the National Bureau of

Standards) began a test broadcast from Boulder, CO with a 2W signal to show that the frequency

variation due to the Doppler effect [7] in the ionosphere was quite small. This 2W signal was received as

far away as Harvard in Massachusetts. The signal was later bumped up to 15W and was detected in New

Zealand. The transmission antennas were moved to the site near Fort Collins in 1962. This site was

chosen due to a high alkalinity of the ground in the area making it conductive and enabling better signal

transmission. The time code was added in July of 1965, as mentioned in Chapter VIII. At that time the

total transmitted power was 7kW which as then increased to 50kW in 1999 which is where it remains

today.

The transmission of a 60kHz signal has some unique obstacles that must be resolved. An ideal radio

transmission antenna needs a length that is equal to one quarter the wavelength of the signal being

broadcasted. In the case of a 60kHz signal the wavelength is 5,000 meters which translates to roughly

3.1 miles. At this wavelength, a quarter length antenna would have to be approximately 4,000 feet

(roughly a 350 story building). To deal with this, a special arrangement of the antennas is used and

described below by the NIST website.

The antennas are spaced 857 m apart. Each antenna is a top loaded monopole consisting of four

122-m towers arranged in a diamond shape. A system of cables, often called a capacitance hat or

top hat, is suspended between the four towers. This top hat is electrically isolated from the

towers, and is electrically connected to a downlead suspended from the center of the top hat.

The downlead serves as the radiating element.

The wavelength is 5000 m, so a one-quarter wavelength antenna would be 1250 m tall, or about

10 times the height of the WWVB antenna towers. As a compromise, some of the missing length

was added horizontally to the top hats of this vertical dipole, and the downlead of each antenna

is terminated at its own helix house under the top hats. Each helix house contains a large

inductor to cancel the capacitance of the short antenna and a variometer (variable inductor) to

tune the antenna system. Energy is fed from the transmitters to the helix houses using

underground cables housed in two concrete trenches. Each trench is about 435 m long. [3]

A photograph showing one of the two transmission antenna is shown below and the diamond-shaped

antenna wires can be seen against the darker backdrop of the clouds. This system along with the low

frequency of the carrier allows the signal to carry over a large area that varies with the time of day.

Figure 6 is a coverage map of the signal at 4 AM (UTC). The frequency of the carrier transmitted is very

accurate (1 part in 1012) and can be used as a solid reference for other equipment.

Page 19: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

15

Figure 5: WWVB Broadcast Antenna

Figure 6: 4AM Coverage Map of the WWVB Signal

Page 20: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

16

The atomic clock in Boulder Colorado that is used to keep accurate time is named NIST-F1. It is a cesium

fountain clock with an accuracy of one second in 60 million years. The operation of the atomic clock is

an interesting topic of physics that is beyond the scope of this report; however, in simple terms a

combination of lasers and microwaves are used on cesium atoms that have been laser-cooled to very

nearly absolute zero. These cesium atoms have a natural resonance frequency of 9,192,631,770 Hz this

frequency was used by the General Conference of Weights and Measures to define the exact duration of

one second [6]. The NIST-F1 clock along with other atomic clocks around the world are used to maintain

the Coordinated Universal Time (UTC) which is the time transmitted by WWVB.

Figure 7: NIST-F1 Cesium Fountain Atomic Clock (Boulder, Colorado) [3]

Page 21: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

17

Chapter VI – WWVB Receiver Design

To build a working clock that will automatically set the time to WWVB first requires a radio designed to

receive and setup the signal for input into a digital system. The receiver will need to have an antenna,

60kHz filter, signal amplification, and a rectifier. This chapter will cover the design process.

The first step is to design an antenna that is capable of receiving the 60kHz signal. This step also proved

to be more difficult than expected. From research into the possible options, we chose to use a ferrite

core “loop stick” antenna. A 680μH ferrite core inductor was purchased for this task (shown as Figure 8).

This inductor, placed in parallel with a 10nF capacitor, would resonate at 60kHz and act as both a filter

and an antenna. The ferrite bar serves to increase the magnetic field held inside the loop and increase

the inductance. What we learned was that the capacitance of the windings throws off the amount of

capacitance needed to obtain a resonance at 60kHz. The method for solving this problem was taught to

us by a friend of Dr. Eads, Bill Bruce. In this procedure, a function generator is used to run a 60kHz signal

through the inductor and a variable capacitor and the voltage is looked at with a voltmeter. The variable

capacitor is then tuned until the peak voltage is seen across the circuit giving the proper capacitor to

place in parallel with the coil to get a properly working antenna. An untuned link, or a second coil of

about 8 wraps, is then used on top of the initial wraps providing a transformer like transfer of the signal

without loading the antenna circuit. This link wire is then fed into the first stage amplifier.

Figure 8: 680μH Ferrite Core Inductor

Once the antenna is working the signal needs to be amplified. An LF351 Operational Amplifier was

chosen for the first stage amplifier. The LF351 has a JFET transistor input stage which provides very high

input impedance (on the order of 1012Ω) which has the effect of causing very little signal loss and is

important because the signal from the antenna is only in the order of 10-6V. A second LF351 stage

amplifier is used to provide further gain, and a LM741 Operational Amplifier is used for the third stage

to get the signal up to roughly 1.5V peak to peak and ready for rectification. Figure 9 shows a signal

representative of the output of the third stage amplifier.

Page 22: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

18

Figure 9: Pre-Rectified WWVB Signal

After the signal has been amplified to this level it is time to rectify the signal. Rectification is the process

of trimming off one side of the signal using a diode. A diode is a passive circuit element that allows

current to flow in one direction only by blocking current in the reverse bias direction. We chose to use a

germanium diode which has a turn on voltage of about half that of a silicon diode. This provides the

same signal rectification with less voltage drop across the diode. The diode is placed directly on the

output of the third stage amplifier and the below zero portions of the signal are blocked resulting a

signal that looks like Figure 10.

Figure 10: Post-Rectified Diode Signal

Page 23: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

19

A capacitor is then placed between the diode output and ground. When the signal is in its high phase

the voltage peaks of the carrier wave charge up the capacitor which then starts to discharge when the

signal drops back near zero. We used a large enough capacitor that it is unable to fully discharge before

the next peak in the carrier wave thus causing a peak voltage to be maintained on the capacitor during

the entire high time of the signal. When the WWVB signal gets cut by 17dB at the beginning of every

second (See Chapter 8 for more information on the signal format) the peaks are no longer strong

enough to turn on the diode, causing it to shut off. The capacitor then discharges leaving a zero voltage

for the duration of the low time. The rectified and smoothed signal is then run through another

amplifier stage to boost the signal to a high level and the resulting waveform is represented in Figure 11.

Figure 11: Receiver Output to Clock

A voltage divider is then used to reduce the output voltage to an acceptable level to be used by the

MSP430. This is now a clean digital signal that is ready to be decoded by the MSP430. A complete

schematic of the receiver is shown in Figure 12.

Page 24: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

20

Figure 12: Complete Receiver Schematic

Page 25: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

21

Chapter VII – Clock Design

The main function of the clock program was to count one second and update the running time with each

second. In order to do this the MSP430 had to be set up to continuously time one second. The first step

in this process was to set up the timer system Timer A appropriately.

Timer Setup

Using a 16MHz clock there are 6.25E-8 counts per second. The clock divider is set to 2 and thus there

are 1.25E-7 counts per second. To get the maximum time between interrupts while still maintaining a

number which is easy to deal with the count limit is set to 64000 (0xFA00). This gives us 1.25E-7 * 64000

= 8E-3 or 8ms. For one second there are 125 counts at 8ms, thus the program uses a counter that is

incremented each time a timer interrupt occurs. The timer system is set to rising mode which will

trigger an interrupt each time the free running counter reaches the number placed in the compare

register. To detect when a second has passed, a simple condition statement is used to check when the

counter has reached a count of 125.

Accuracy

While the clock on the MSP430 is generally accurate, very small discrepancies in clock speed can

compound over several million counts to cause the clock time to have large time gains/losses over the

course of several hours. To account for the slight differences in clock speed between processors, we

used the following equation.

At = actual time

Ct = clock time

Et = elapsed time

( )adjustmentoverflowNecessary

Et

CtAt

=

∗∗∗−

125*

2

1016125

6

This made it relatively simple to adjust the clock to work with a new microprocessor when necessary.

The final count used in with the MSP430 in the final design is 63362 (0xF782) which is ~1% difference

from the true 16MHz.

Complexities of Time

One of the more complicated tasks in the development of the clock program was dealing with time. We

found that time is much more complex than it seems when it is observed in a short term context. Some

of the challenges we had to deal with were using designing a 12 hour clock, differing month lengths,

leap year, time zone differences and daylight savings time.

Page 26: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

22

12 Hour Clock

The challenge of the 12 hour clock was dealing with the fact that AM and PM each run from 12-11. This

meant that 0 from the 24 hour clock received from the signal had to be converted to 12 AM, however

when the PM section of the 24 hour clock was reached, we could not just subtract 12 and add a PM, we

had to deal with 12 and 13-23 separately. In the final design we handled the AM/PM logic separately

from the 1-12 logic to get around the differences between the two.

Month Lengths and Leap Year

The time received from the incoming signal contains the date in the day of year format. This is a

relatively straight forward process to convert to month and day. To accomplish this we simply used the

following algorithm.

DOY = Incoming day of year

month = 1

while days in month < DOY

subtract days in month from DOY

increment month

day = DOY

This simple process is made more complex by the fact that each month contains a different number of

days. Adding to this, the leap year changes the length of February once every four years. To deal with

this we used an algorithm to assign a “days in month” variable based on the current month, and added

one to the days in month for February for leap years. This allows us to keep the same algorithm for the

remaining math.

Time Zones and Daylight Savings Time

Once we taught the MSP430 how to tell time, we still had to deal with converting time from UTC to MST

as well as accounting for daylight savings time when needed. This again is a straightforward process of

subtracting 7 from the hour for MST and adding one if daylight savings time is in affect. The issue here

comes from when days roll over. If the time is 2:00 AM 5/5/08 and you subtract 7 from the hour, the

result will be -5:00 AM 5/5/08. There are clearly several problems with this result and likewise several

steps to the solution. First the time is negative, which can cause many problems especially if the value is

read as an unsigned number which turns it into a very large positive number. We solve this by checking

if the hour is less than 7 before performing the subtraction. If the hour is less than 7 then it will have 24

added to it to create the proper hour result. To handle daylight savings time with no extra effort, we

just add one before any of the subtract logic if currently in daylight savings. Next we had to deal with

the date showing as one day ahead of the proper time. This was simplified by using the day of year

value instead of the month and day. With this setup we simply subtracted one off of the day if we

added 24 to the hour, thus we were transferring one day from the days to the hours.

Page 27: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

23

The clock design ended up being much more complex that we originally planned. It was an interesting

perspective to work through all of these issues and develop an appreciation of how complex time can be

in the proper perspective. Once we had dealt with each of these issues we were left with a clock

capable of keeping track of the passing seconds.

Page 28: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

24

Chapter VIII – Decoder Design

WWVB Time Code Format

The WWVB signal contains the current time information encoded into each minute by varying the

transmission power by 17dB and using 1 second long data bits. Each bit has a falling edge to start and

the length of time that the transmission signal power is dropped determines which type of bit is being

transmitted. There are three types of bits, as given in Table 3.

Table 3: Bit Type in WWVB Signal

Bit Type Low Time Length (ms)

0 20% 200

1 50% 500

Marker 80% 800

The signal is encoded in a BCD format which includes the current minute, hour, day of year, and year

information including other specific time information outside the scope of this project. A new minute

starts when two marker bits are received consecutively. The information encoded in the signal is the

current time, but once all the information is translated a minute has passed so this must be considered

when setting the clock. A graphic showing a specific time is shown below in Figure 13 (from wikipedia).

Figure 13: WWVB Time Code Format

More specifically, each ten second interval contains 2 blocks of data. A marker bit is always sent in the 9

mod 10 bit and every bit 4 mod 10 is a 0 bit. These allow for error-checking to make sure that a

receiver/decoder is reading in the correct bits during the receiving process. Since there are two bits for

error-checking, 8 possible data bits are left for each 10 second interval. Not all of these data bits are

always used. The first 10 second interval is a little different in that it contains only 7 bits of data rather

than 8 since it contains the first marker bit for a new minute. For example, the minute information is

encoded in BCD for the ones digit separately from the tens digit. 4 bits of data are in binary format

which allow for 0-9 for the ones digit and 3 bits of data allow for 0-5. Of course higher values are

possible but are not valid. A similar process is followed for the rest of the time information. It should be

noted that the WWVB time code cleverly uses day of year (0-365) instead of month/day to save on

transmission bits.

Since the WWVB time code format transmits data through pulse width, we needed to have the MSP430

take in the received signal and determine each incoming bit, start a decoding sequence after 2

consecutive marker bits, check for errors by comparing the received bits to the expected 4 & 9 mod 10

Page 29: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

25

bits and pack the bits into numbers to set the various clock variables. While programming in C we

created various functions for these tasks.

The program attempts to set when the circuit is powered on, and, once set, attempts to set every 30

minutes. Also we have an external switch that will allow for setting at any time. The decoding process is

started when the clock attempts to set and the process behind this involves the following specific tasks.

Since the WWVB time code format transmits data through pulse width, we needed to have the MSP430

take in the received signal and determine each incoming bit type, start a decoding sequence after 2

consecutive marker bits, check for errors by comparing the received bits to the expected 4 & 9 mod 10

bits and pack the bits into numbers to set the various clock variables. While programming in C we

create various functions for these tasks.

Input Capture

To determine which bit is being transmitted, the processor is set up with an interrupt to occur when a

falling edge is received. This interrupt sends the program to an ISR which keeps track of how long the

signal has been low. More specifically, the same overflow count is used from the clock since it already

provided 8ms increments. Once a rising edge is seen, the ISR copies over what the overflow count

variable is to another variable, countLow, and returns control to program. However, it sets a variable

which triggers the program to go into the decoding routine. The program determines which bit was sent

by comparing the number of overflow counts to set ranges using a basic if/else statement.

Commencement of Decoding

The ISR returns control to the program after the bit has been determined and the decoding sequence

begins. First the decoding sequence checks to see if this bit received is a marker bit. If a marker bit is

found then the program sees if the next bit is a marker bit; otherwise, the decoding sequence ends and

the program returns to its normal state of managing the clock & display. If it is indeed a marker bit

decoding continues; otherwise the program goes back to waiting by ignoring this bit received.

Now that the decoder has seen two consecutive marker bits, valid data is ready to be packed from the

bits into the variables for the clock, including minutes, hours, day of year and year. Every bit that is

supposed to be a 0 or a marker bit is verified but not stored. If any of these bits is incorrect, an error

variable is set and the decoding process resets to its beginning. This ensures to some degree that the

received signal is valid and rejects a setting sequence if not. We wrote a rather complex algorithm to

keep track of where in the minute long signal the program was and what each bit actually meant in

terms of setting each of the clock variables.

After the data is packed, more decoding must be done on the day of year. Given the day of the year

from 0-366, we had to determine the month and day including whether or not the year was a leap year.

Considering our awkward calendar, this proved to require a good amount of our 2kB flash memory.

After this is done, the clock is ready to be set, and the variables obtained from decoding are written to

the clock variables. The program stops trying to set until prompted, unless the clock reaches the 0 or 30

minute mark the external switch is closed.

Page 30: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

26

Chapter IX – Processor Interface

The MSP430 device we were using was a 14 pin device, with 10 pins for possible I/O. Eight of these pins

are on what is called Port 1, which is a full 8 bit register, and the other 2 are on Port 2. The MSP430 is

capable of parallel I/O, so each individual pin on these ports can be configured for either reading or

writing. However, for input capture, Port 2 may not be used so no matter what, one of the pins from

Port 1 had to be used for the incoming signal from the receiver. The MSP430 has a hard reset pin which

we connected to a switch if we wanted to reset the program.

Keeping this in mind, we wanted to drive an LCD to show the time and date using the MSP430. We

purchased a 20 character x 4 line display from Futurlec to give us added flexibility for displaying different

information. A schematic for this 16 pin device is given in the appendix. We only used 2 lines of the

display but this allowed for separation between the lines. The display is typical in that it had a

microcontroller built specifically to be interfaced with another microcontroller, the Hitachi HD44780.

The display, similar to the MSP430, had 8 data pins. Basically these 8 bits allowed for complete coding

of ASCII characters and some other extra characters. The format used can be seen in the column and

row headings from Figure 14 (Hitachi HD44780).

Figure 14: Hitachi HD44780 Character Codes

Page 31: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

27

The display will only initialize and be ready to display characters after a “power-on” with very particular

timing characteristics. We were not able to see this, so instead we used the controller’s initialization

algorithm which includes sending a high signal for a certain amount of time to the control bits. This

allows the user to initialize the display in several different operating modes including the number of

data lines to be used, whether there is a cursor or blinker, etc. The typical operation uses 8 data lines,

but the display can be controlled using only 4 data lines but sending data 1 nibble at a time instead of 1

byte at a time.

After the initialization process, writing to the display required precise timing on separate control pins

during normal operation. One of the more subtle control pins was “E”, which is used as a “strobe” in

order to signal a new write. The literature on how to use the display controller didn’t mention this so

we had to do some internet research to finally realize the importance of this in writing to the display.

Essentially all we needed to do was send about a 10ms long pulse to the E pin in order to signal that

writing is to occur. The second major control pin is “RS” or register select. This pin must be toggled

when initializing the display and then left on after ward. Since using these pins is a somewhat

specialized process, we decided to use Port 2 for these control signals. The data lines were all on Port 1

for simplicity. One of the last pins to consider was the read/write pin (R/W’) which we connected to the

display’s Vdd because we weren’t interested in reading from the display.

Finally, the display has a contrast adjust which varies with applied voltage. We used a potentiometer as

a voltage divider to find the level of contrast we liked and then found appropriate resistor values to

replace the potentiometer. The display has pins for the LED backlight, so we connected this to an

external switch to enable the backlight to be on or off. A schematic for the MSP430 connected to the

LCD is given below in Figure 15.

Page 32: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

28

Figure 15: MSP430 & LCD Schematic

Page 33: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

29

Chapter X – Project Integration

Since our project consisted of several smaller parts, it was necessary to integrate these parts together as

they were completed. The four major parts we have outlined in this report were the receiver, clock,

decoder and display. First we incorporated the clock with the display; next we added the decoder and

finally the receiver. A brief discussion of each of these steps is given below.

Step 1: Clock + Display

Since we had the clock already running on the MSP430, a good way to test the display was to output the

time to the display. This step was more of a continued development than an integration. First we

implemented the display using the 8 data line format and after successfully outputting the time

information modified the program to use the 4 data line mode. We experimented with the location of

the characters on the display and how we wanted the time to appear. This included removing leading

zeroes, using a 12 hour format as discussed previously and displaying the words “time” and “date.” The

final display format we chose is shown in Figure 16.

Figure 16: Time Display Format

During this phase we found some logical errors with the clock program regarding how the various time

variables were handled. This included the day rollover and month rollover being off by 1. All of these

errors were resolved by changing simple equalities in the code.

Step 2: Step 1 + Decoder

At the start of step 2, the decoder would take in a full minute signal and store the data into an array of 6

bytes. Each of these bytes contained the data from one 10 second section of the incoming signal. To

combine this program with the clock we had to create functions to extract the actual time information

from data array and store it to the time variables. One of the major challenges during this step was the

memory limit on the MSP430. The model we used has a 2kB flash memory limit which we reached very

early in the integration process. Much of the time during this stage was spent reducing code size and

rewriting functions to make them more efficient. Overall we reduced the code size by more than 1kB

through our optimization efforts. Another complication we faced was the use of interrupts in each of

the programs overlapped the same functionality. This caused errors which made either the clock or

decoder run properly but not both at the same time. We reworked which interrupts we used for each

portion as well as rewriting the interrupt service routines that we used. Once these issues were

resolved, the software was ready to receive an input signal.

Page 34: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

30

Step 3: Step 2 + Receiver

Due to delays in the construction of the receiver we wrote a program to create an artificial signal to start

with this step. During this process our original design incorrectly handled the duty cycle of the marker

bits causing multiple bits to combine without distinction. Once we had a working artificial signal we

were able to test the decoder. We found that while the decoder did in fact wait to receive two market

bits to signal the beginning of a new minute, it did not make the distinction of whether or not those

marker bits were sequential. This caused many errors with a very elusive root cause. We also ran into

more code size issues in this step which we resolved by further optimizing our code.

Once we had a working receiver, the integration process began anew. We found that we had made

some key errors in the format of the signal itself. Originally we were looking for a signal which started

with a rising edge as apposed to the actual signal which starts with a falling edge. This was an easy fix

and only required that we invert the logic in the ISR that handled edge detection. Our other

misconception was that the three bit types included a duty cycles of 20%, 40% and 80% whereas the

40% is actually 50% in the real signal. This did not cause any issues as our detection margins were wide

enough to pick up the proper bits regardless. The most difficult error to fix involved the high processor

load inhibiting the detection of edges in the incoming signal. This was remedied by altering the display

code to only update once per second instead of continuously. Once this change had been made the

clock circuit functioned properly and was able to detect and display the proper time. The final circuit

assembly is shown in Figure 17.

Figure 17: Final Circuit Assembly

Page 35: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

31

Chapter XI – Conclusions & Future Work

This project began with the goal of developing a set of labs for the ECE 251 microcontrollers course

which would be complete and ready to be performed by students. This set of labs was to utilize the new

TI-MSP430 F2012 microcontroller in the place of the existing Freescale MC9S12C32 microcontroller. To

help us determine if we met these goals we substituted our new labs for the Freescale labs for a

volunteer group of students. This allowed us to verify that the lab documents were of a high enough

quality and contained detailed enough explanation to allow the students to complete them as they

would the labs in the current course. Through this we discovered that the students were able to

successfully complete the lab assignments with minimal assistance which verified that they were

complete enough to be used in a classroom setting.

The original purpose of this project was to show that the TI-MSP430 would provide a better educational

tool than the currently in use Freescale MC9S12C32. There were four categories which we looked at in

an attempt to determine the best solution; cost to students, ease of use, viability for long term use and

capabilities relevant to education. The MSP430 was superior in cost to the students in that it is $60 less

expensive than the Freescale model. TI's controller was also found to be more intuitive and simple to

use for the students by providing a more user-friendly graphical interface and many diagnostic tools. Its

RISC architecture also made it easier for students to learn the full functionality of the instruction set.

The MSP430 is also a better long term solution as it interfaces with the computer via a modern USB

interface instead of the MC9S12C32's RS232 interface which is beginning to be excluded from modern

computer systems. The only category which was not a clear win for the MSP430 was capabilities

relevant to education; the Freescale controller includes a keyboard/terminal interface to the board

which is not duplicated by TI's controller. This, however, can be overcome with the extensive diagnostic

tools provided by the MSP430 developing environment.

Our conclusion after our first semester of work is that the MSP430 would make an excellent educational

tool. There is however one limiting factor which will stop the new controller from being adopted by CSU

in the short term: the fact that there is not currently a textbook associated with the MSP430. Therefore

any adopting professor would be forced to provide the students with an extensive set of notes to be

able to successfully teach the course. When a textbook is completed for this controller, it will make a

very capable and worthy addition to any ECE curriculum.

During the second phase of the project we designed a self-setting clock using the WWVB radio signal.

We had to limit the scope of the project because we only had a single semester to complete it. We split

the project into two major sections, including the receiver design and the work relating to the MSP430.

This project proved to be more complicated than we originally believed it would be.

The receiver design taught us several new things about analog design. First when working with RF

devices the theory we learned in class fits the real world operation of devices however it is vital to

account for parasitic capacitances and inductances introduces by the circuit components. Second when

having problems getting things to work correctly much time can be saved by getting advice from

someone who knows the proper tricks to use when tuning and building circuits.

Page 36: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

32

We learned a lot from dealing with the MSP430 in a more robust context as well. One of the major

issues we faced was the 2KB code size limit. We developed several techniques for reducing and

optimizing code. Learning how to use our display was more challenging than expected. We had to read

through the data sheet several times to extract the applicable information. There were several other

issues that came from integrating all of the sections of the design which taught us about dealing with

larger scale designs. Overall this project provided an excellent learning opportunity for all members of

the group.

At this time we cannot see any reason for continuation of this project as it was very small scale and

would be difficult to expand on for another full project.

Page 37: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

33

References

[1] Axiom Manufacturing, “CML-12C32,” [Online document], [cited 2007 Dec 6], Available HTTP:

http://axman.com/?q=node/46

[2] Texas Instruments Incorporated, “eZ430-MSP430F2013 Development Tool User’s Guide,” pp 5.

[Online document], [cited 2007 Dec 6], Available HTTP:

http://focus.ti.com/lit/ug/slau176b/slau176b.pdf

[3] National Institute of Science and Technology,“NIST Radio Station WWVB,” [Online document],

[cited 2008 May 1], Available HTTP: http://tf.nist.gov/stations/wwvb.htm

[4] Wikimedia Foundation, Inc. , “WWVB Modulation Format.” [Online document], [cited 2008 May

1], Available HTTP: http://en.wikipedia.org/wiki/WWVB

[5] Texas Instruments Incorporated, “MSP430x2xx Family User’s Guide.” pp 3-75. [Online

document], [cited 2007 Dec 4], Available HTTP:

http://focus.ti.com/lit/ug/slau144d/slau144d.pdf.

[6] Resolution 1 of the 13th Conference Generale des Poids et Mesures (CGPM), 1967.

[7] Wikimedia Foundation, Inc. , “Doppler effect.” [Online document], [cited 2008 May 3], Available

HTTP: http://en.wikipedia.org/wiki/Doppler_effect.

Page 38: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

34

Bibliography

[1] “Lab 1: Review of Digital Circuit Logic.” (for use with Freescale MC9S12C32) Fort Collins, CO.

Colorado State University, 2005.

[2] “Lab 2: Timing Measurements, Fan-Out & Digital to Analog Interface.” (for use with Freescale

MC9S12C32) Fort Collins, CO. Colorado State University, 2005.

[3] “Lab 3: Software Setup and Introductory Programs.” (for use with Freescale MC9S12C32) Fort

Collins, CO. Colorado State University, 2005.

[4] “Lab 4: Addressing Modes and Branching.” (for use with Freescale MC9S12C32) Fort Collins, CO.

Colorado State University, 2005.

[5] “Lab 5: Subroutines and the Stack.” (for use with Freescale MC9S12C32) Fort Collins, CO.

Colorado State University, 2005.

[6] “Lab 6: BCD Multiplication and Division.” (for use with Freescale MC9S12C32) Fort Collins, CO.

Colorado State University, 2005.

[7] “Lab 7: Parallel I/O and Keyboard Scanning.” (for use with Freescale MC9S12C32) Fort Collins,

CO. Colorado State University, 2005.

[8] “Lab 8: Timing Maskable Interrupts.” (for use with Freescale MC9S12C32) Fort Collins, CO.

Colorado State University, 2005.

[9] “Lab 9: Input Capture and Output Compare.” (for use with Freescale MC9S12C32) Fort Collins,

CO. Colorado State University, 2005.

[10] “Lab 10: Analog-to-Digital Converter.” (for use with Freescale MC9S12C32) Fort Collins, CO.

Colorado State University, 2005.

[11] Texas Instruments Incorporated, “MSP430x2xx Family Data Sheet.” [Online document], [cited

2007 Dec 4], Available HTTP: http://focus.ti.com/lit/ds/symlink/msp430f2012.pdf

Page 39: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

35

Acknowledgements

We would like to thanks Texas Instruments for the hardware donations including MSP430 USB kits with

for the F2013 device, kits of MSP430F2012 target boards and hardware development starter kits. We

estimate the approximate value for their donations to be around $700 total. Without their generous

donations running the labs and learning how to use the processors would not be possible. We would

also like to thank Miguel Morales who started this project during the spring 2007 semester. He has

provided us with guidance and assistance in the project and has been generous with his time. Finally,

we would like to thank Dr. Bill Eads, our project advisor. Dr. Eads always had a very sensible and

practical perspective on our project goals and progress. We appreciate the offer of his time and

expertise considering that he is not paid like a full time faculty member. We also received extensive

help on the receiver design from Bill Bruce.

Page 40: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

Appendix A – Abbreviations

A-1

A/D Analog-to-Digital

BCD Binary Coded Decimal

CPU Central Processing Unit

CISC Complex Instruction Set Computer

ECE Electrical and Computer Engineering

I/O Input/Output

IDE Integrated Development Environment

ISR Interrupt Service Routine

kB Kilobyte (1024 bytes)

LED Light Emitting Diode

LCD Liquid Crystal Display

MST Mountain Standard Time

RAM Random Access Memory

ROM Read Only Memory

RS232 Recommend Standard 232, Serial Communications Standard

RISC Reduced Instruction Set Computer

TI Texas Instruments Incorporated

USB Universal Serial Bus

UTC Coordinated Universal Time

JFET Junction Gate Field-Effect Transistor

Page 41: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

Appendix B – Budget

B-1

Our final budget for the project follows.

Fall Semester

12 MSP430 USB kits with F2013 device ~ $20 each (donated by TI)

15 kits of 3 MSP430F2012 target boards ~ $10 each (donated by TI)

2 Hardware Development Starter kits ~ $150 each (donated by TI)

---------------------------------------------------------------------------------------------------

Total Donations ~ $700 (from Texas Instruments Inc.)

Spring Semester

20x4 Liquid Crystal Display with Backlight - $24.90

Components and Circuit Boards - $43.18

---------------------------------------------------------------------------------------------------

Spring Semester Total = $68.08

Page 42: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

Appendix C – MSP430 Code (Programmed in C)

C-1

#include "msp430x20x2.h" //The following variables are used for the clock/di splay program unsigned char timerCount; unsigned char year, month, day, hour, minute, secon d, leapYear; //The following variables are used for the pulse de tector program unsigned long overflowCount, countHigh; unsigned char done, rising, pm, error; unsigned char part, section, bitNum, var, type; unsigned char setting, initSet, setVar; //The following varialbes are used for the decoder unsigned char LSNibble, MSNibble, setMonth, setYear ; char decode, cycle, DST; unsigned int dayOfYear; char bytenum[6]; //Function prototypes void getDate(int DOY); void binaryValue(char value); void setValues(); void write(char value); void clock(void); void writeNumber(char value, char hideLeadingZero); void getType(); void pack(char size); void writeToDisplay(char value, char repeat); void delay(unsigned int input); void writeNibble(char value); void errorCheck(char checkBit); main() // variable initialization for clock/display error = 0; part = 0; section = 0; bitNum = 0; var = 0; setting = 1; year = 0; month = 1; day = 1; hour = 0; minute = 0; second = 0; leapYear = 0; timerCount = 0; rising = 1; initSet = 0; // variable initialization for pulse detector overflowCount = 0; done = 0; // initialize microprocessor WDTCTL = WDTPW + WDTHOLD; // Stop WDT DCOCTL = CALDCO_16MHZ; // set clock to 16 MHz BCSCTL1 = CALBC1_16MHZ; // Ditto CCTL0 = CCIE; //CCR0 interrup t enabled

Page 43: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

Appendix C – MSP430 Code (Programmed in C)

C-2

TACTL = 0x0250; //Up mode, divi de by 2, SMCLK, TAIE off CCR0 = 0xF782; //Interrupt aft er 8ms //*adjusted for speed discerepancy TACCTL1 = 0x9910; //Pulse detecto r rising edge _BIS_SR(GIE); //Enable global interrupts P1OUT = 0x00; P2OUT = 0x00; P1SEL = 0xC0; //clock with pu lse detector P2SEL = 0x00; P1DIR = 0x2F; //clock with pu lse detector P2DIR = 0xC0; // Set P2.7 to output // initialize display write(0x3); // required write(0x3); // required write(0x3); // required write(0x2); // set 4 bit mo de write(0x2); // function set write(0x8); // function set write(0x1); // turn off dis play write(0x0); // turn off dis play write(0x0); // clear displa y write(0x1); // clear displa y write(0x0); // turn on disp lay write(0xC); // turn display on, cursor off, blink off, DB3=1 // program section while(1) //set every 30 minutes or when button is pr essed initSet = P1IN & 0x10; if(minute == 0 || minute == 30) initSet++; if(initSet && !setting) setting++; TACCTL1 = 0x9910; initSet = 0; if(timerCount >= 125) timerCount = 0; clock(); if(done) getType(); done = 0; if(section == 0) switch(part) case 0: if(type == 3) if(bitNum == 0) bitNum++; else if(bitNum == 1) bitNum = 0; part++; else bitNum = 0;

Page 44: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

Appendix C – MSP430 Code (Programmed in C)

C-3

break; case 1: pack(3); break; case 2: errorCheck(1); break; case 3: pack(4); break; default: error = 1; else if(section > 0 && section <= 5) switch(part) case 0: errorCheck(3); break; case 1: pack(4); break; case 2: errorCheck(1); break; case 3: pack(4); break; default: error = 1; else if(error) error = 0; else setValues(); //turn setting off TACCTL1 = 0x0910; setting = 0; section = 0; //Used for display setup, will write 'value' to the display void write(char value) P1OUT = P1OUT & 0x30; P1OUT = P1OUT | value; delay(100); P2OUT = 0x80; delay(100); P2OUT = 0; delay(60000); //Write hex value to display repeat times void writeToDisplay(char value, char repeat) char valHigh = value >> 4; value = value & 0x0F; int j;

Page 45: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

Appendix C – MSP430 Code (Programmed in C)

C-4

for(j = 0; j < repeat; j++) writeNibble(valHigh); writeNibble(value); //Writes the first half of a byte to the display void writeNibble(char value) P1OUT = P1OUT & 0x30; P1OUT = P1OUT | value; P2OUT = 0x40; delay(100); P2OUT = 0xC0; delay(100); P2OUT = 0x40; delay(100); //Used for writing numbers to the display, writes ' value' to the display //and can show or hide leading zeroes depending on 'hideLeadingZero' void writeNumber(char value, char hideLeadingZero) unsigned char low, high; //split number high = 0; while(value >= 10) high++; value = value - 10; low = (char)value; //write number if(!hideLeadingZero || high != 0) writeToDisplay(high + 0x30, 1); else writeToDisplay(0x20, 1); writeToDisplay(low + 0x30, 1); //subroutine to increment clock by one second void clock(void) second++; if(second > 59) second = 0; minute++; if(minute > 59) minute = 0; hour++; if(hour > 23) hour = 0; day++; if(month == 2) if((day == 29 && leapYear == 0) || day == 3 0) day = 32; if(day == 31 && (month == 4 || month == 6 || mo nth == 9 || month == 11)) day = 32; if(day == 32)

Page 46: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

Appendix C – MSP430 Code (Programmed in C)

C-5

day = 1; month++; if(month > 12) month = 1; year++; //Write the current time to the display each se cond unsigned char displayHour; writeToDisplay(0x20, 4); //adjust hour display for 12 hour clock displayHour = hour; if(hour == 0) displayHour = 12; pm = 0; else if(hour < 12) pm = 0; else if(hour == 12) pm = 1; else if(hour > 12) displayHour = hour - 12; pm = 1; writeNumber(displayHour, 1); writeToDisplay(0x3A, 1); writeNumber(minute, 0); writeToDisplay(0x3A, 1); writeNumber(second, 0); writeToDisplay(0x20, 1); //display AM/PM if(pm) writeToDisplay(0x50, 1); else writeToDisplay(0x41, 1); writeToDisplay(0x4D, 1); writeToDisplay(0x20, 5); //display date writeToDisplay(0x20, 5); writeNumber(month, 1); writeToDisplay(0x2F, 1); writeNumber(day, 1); writeToDisplay(0x2F, 1); writeNumber(year, 0); writeToDisplay(0x20, 45); //clear unused displa y space setVar = 0x20; if(setting) setVar = 0xFF; writeToDisplay(setVar, 1); write(0x0); // reset to start write(0x2); // reset to start //Get the type of the incoming bit 1 = low, 2 = hig h, 3 = signal void getType() char retVal = 1; if(countHigh >= 37) retVal++;

Page 47: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

Appendix C – MSP430 Code (Programmed in C)

C-6

if(countHigh >= 75) retVal++; countHigh = 0; type = retVal; //Pack incoming bits into char void pack(char size) if(bitNum < size) if(type == 1) var = var << 1; else if(type == 2) var = var << 1; var++; else error = 1; bitNum++; if(bitNum == size) bitNum = 0; part++; if(part > 3) part = 0; bitNum = 0; bytenum[section] = var; section++; var = 0; //Translate WWVB signal bytes to actual time/date v alues void setValues() char index; for(index = 0; index < 6; index++) binaryValue(bytenum[index]); switch(index) case 0: minute = MSNibble * 10 + LSNibble + 1; break; case 1: hour = MSNibble * 10 + LSNibble; break; case 2: dayOfYear = MSNibble * 100 + LSNibb le * 10; break; case 3: dayOfYear = dayOfYear + MSNibble; break; case 4: setYear = LSNibble * 10; break; case 5: year = setYear + MSNibble; leapYear = LSNibble >> 3; //Daylight savings time if(0x3 && LSNibble) hour++;

Page 48: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

Appendix C – MSP430 Code (Programmed in C)

C-7

//Adjust from Greenwich Mean Time t o Mountain Standard Time //Handle day rollover appropriately if(hour < 7) hour = hour + 24; dayOfYear = dayOfYear - 1; hour = hour - 7; getDate(dayOfYear); month = setMonth; second = 0; //Translate day of year into month/date void getDate(int DOY) char daysInMonth; char convertDone = 0; setMonth = 1; while(!convertDone) if(setMonth == 2) daysInMonth = 28; if(leapYear) daysInMonth++; else if(setMonth == 4 || setMonth == 6 || setMonth == 9 || setMonth == 11) daysInMonth = 30; else daysInMonth = 31; if(DOY > daysInMonth) setMonth++; DOY = DOY - daysInMonth; else convertDone++; day = DOY; //Separate byte into least significant nibble and m ost significant nibble void binaryValue(char value) LSNibble = 0xF & value; MSNibble = 0xF & (value >> 4); //delay routine void delay(unsigned int input) int i; for(i = 0; i < input; i++) void errorCheck(char checkBit) if(type != checkBit) error = 1; else part++; //ISR increment timerCount every time .08 seconds h as passed #pragma vector=TIMERA0_VECTOR //IAR Place ISR in pr oper interrupt vector __interrupt void clock_interrupt(void)

Page 49: Microcontrollers - Walter Scott, Jr. College of Engineeringprojects-web.engr.colostate.edu/.../microcontrollers/final_report.pdf · Microcontrollers with the Texas Instruments MSP430

Appendix C – MSP430 Code (Programmed in C)

C-8

timerCount++; overflowCount++; //ISR for handling pulse detection #pragma vector=TIMERA1_VECTOR __interrupt void pulseDetector(void) unsigned int regCompare; regCompare = TACCTL1; regCompare = regCompare & CCIFG; if(regCompare == CCIFG) if(rising) TACCTL1 = 0x5910; rising = 0; else TACCTL1 = 0x9910; rising = 1; if(overflowCount > 10) countHigh = overflowCount; done++; if(overflowCount > 10) overflowCount = 0;