0% found this document useful (0 votes)
134 views5 pages

Group3 DigitalAlarmClock PDF

This document describes a digital alarm clock project created using a Dragon12-Plus2 microcontroller and Arduino Uno board. The clock displays the time on 4 7-segment displays and uses an MP3 file played through an Arduino and shield as the alarm sound. The time is set and alarm configured through a menu on an LCD screen using a HEX keypad. The microcontroller handles the real-time clock functionality using interrupts to increment the time display every minute, hour, and to change AM/PM. The Arduino communicates serially to play the MP3 file as the alarm and display additional status.

Uploaded by

Muhammad Anaz's
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views5 pages

Group3 DigitalAlarmClock PDF

This document describes a digital alarm clock project created using a Dragon12-Plus2 microcontroller and Arduino Uno board. The clock displays the time on 4 7-segment displays and uses an MP3 file played through an Arduino and shield as the alarm sound. The time is set and alarm configured through a menu on an LCD screen using a HEX keypad. The microcontroller handles the real-time clock functionality using interrupts to increment the time display every minute, hour, and to change AM/PM. The Arduino communicates serially to play the MP3 file as the alarm and display additional status.

Uploaded by

Muhammad Anaz's
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Digital Alarm Clock

Matthew Screws, Binh Ton, Adam Schrader


Electrical and Computer Engineering Department
School of Engineering and Computer Science
Oakland University, Rochester, MI
ECE 470/570 Fall 2014 - Computer-Based System Design
Professor Daniel Llamocca
[email protected], [email protected], [email protected]
I. ABSTRACT and the delay counters “mcount” and “ms250_count” to
zero to prepare them for the next “minute” count.
The final project consists of a digital time clock with sleep
alarm capabilities. This device is made using the HCS12 Using the RTI module, a real time interrupt was then used
Dragon12-Plus2 in communication with an Arduino Uno to take the “min” variable from the above interrupt and
with Sparkfun’s MP3 Shield connected. The utilization of adjust the remaining digits of the clock to correspond to a
the Arduino platform was to gain access to community time of day. This interrupt is triggered every 10.24ms and
created library functionality for connection with works by also using a series of “if” statements. After ten
Sparkfun’s MP3 Shield. The MP3 Shield allows an MP3 minutes have passed, this interrupt will increment the the
sound file to play as the alarm. The overall purpose and variable “tmin” to keep track of each set of ten minutes and
functionality of the project is within today’s scope of a reset the “min” variable back to zero. Once sixty minutes
modern digital alarm clock device and is the driving have passed, the variable “hr” is incremented and while the
decision for implementing this system on the HCS12 previous two variable are again reset to zero. The rest of
Dragon12-Plus2 microcontroller. The main controllers of the “if” statements are used to control the hours making
the Dragon12-Plus2 and Arduino Uno boards have been sure that the hours and tens of hours digits will adjust
programmed by using Freescale’s CodeWarrior and properly until twelve is reached and then reset to one. The
Arduino’s Sketch Pad Compilers, respectively. RTI interrupt is also responsible for changing the status of
AM and PM every time the 12th hour is reached. This
interrupt prepares the each of the clock digits to be
II. INTRODUCTION presented by the 7-segment display, and outputs the
AM/PM indicator on the RGB LED.
Our desire to utilize all the skills acquired in the class
B. Menu Interface through LCD Display
made us want to make something that we thought would be
of interesting and applicable to our daily lives. As such we The LCD module is the main visual interface for the menu
settled on making a fully functional and programmable options the user will be allowed to configure for the core
alarm clock. This consists of a digital time clock with an functionality of the digital alarm clock system. Working in
conjunction with the HEX keypad for user input, the LCD
MP3 music file as the output for alarm capabilities.
display changes accordingly to user interaction. On
initially startup of the system, the HELP menu will cycle
We are using the timer module of the Dragon12 Plus board through the different displays configured to show the user
to construct the real-time clock. The time is displayed the key mapping for the HEX keypad, the functionality of
utilizing the four 7-segment displays. Ante-meridian and each key, and its uses in our system. After the HELP menu
post-meridian are shown using the Dragon12-Plus2 RGB has finished its sequence, the LCD display will initialize on
LED. Use of the HEX keypad is the way the user interfaces the menu option to set the current time. The system is
with the clock functionalities. Keys on the HEX keypad preconfigured to set the current time to 12:00 A.M. after
have been defined and allow the user to interface with a each reset of the system.
menu displayed on the LCD module connected to the
Dragon12-Plus2 board. Menu options range from core The LCD interface was done through the use of a “case”
clock functionality like setting the current time as well as structure with the current state of the LCD menus as the
the alarm time. These options are reflected on the LCD index to the cases. The “Set Time” menu has index 0, “Set
module. For the actual alarm we are using an Arduino Uno Alarm” has index 1, etc. The index is incremented or
with a MP3 shield. This is connected via USB and decremented depending on the user input through the HEX
communicates serially using SCI. keypad. Passing the current index value to the function
LCD_display(index) displays the menu based upon the
current menu index. When the user has selected to enter
III. METHODOLOGY one of the menu options for setting the time/alarm and
enters their desired time or alarm setting, the previous
menu is displayed. This functionality is capable since the
A. Clock index is left unchanged and is prohibited from changing
The clock has been designed around the use of an output while the user is in the menu options to set the time/alarm.
While the user has entered one of the menu options, they
compare timer module set to trigger an interrupt every
are allowed to cancel and go to the previous menu. This is
250ms. This is accomplished by using a prescaler of 128 in done through a simple function call to LCD_display(index)
the timer module creating a timer clock that runs at since the index is left unchanged upon entering the menu
187.5KHz and triggers an interrupt every 46,875 clock options for configuring the time/alarm. A decision to
cycles. Once in the interrupt, a couple of “if” statements cancel and return to the previous main menu disregards
are used to create 1 minute delays. Once a minute has any user input while in the configuration menus. This
passed, the variable named “min” is incremented by one makes sure that the user only commits appropriate changes
to the time/alarm settings upon pressing the “Enter” key on First each digit is defined as either the tens of hours, hours,
the HEX keypad. Please reference Section D for further tens of minutes and minutes. Once the user has loaded the
information about user configuration through the use of the time into the LCD display and pressed enter, the values are
HEX keypad. Displayed below are pictures of the LCD loaded into the programs variables. These variables are
module displaying various menu displays. then passed into RTI interrupt 7 handler which decides
how to increment the 7-seg using a series of IF statements.
These IF statements ensure proper values are loaded into
the 7-seg display for the end user. These rules include the
tens of hours being one or not displaying at all. The hours
go to zero, one, or two if the tens of hours is one.
Otherwise the hours can go from one to nine. The tens of
minutes can be equal to zero through five, and the minutes
can go to nine. These IF statements describe a standard
twelve hour clock. The digits are then pulled from the RTI
7 interrupt and loaded into the output compare interrupt
OC6ICR where they are sent to their proper place holder.
The OC6ICR is triggered every 1.01ms. This keeps each of
the 7 segments illuminated for equal amounts of time,
which gives the appearance to the user that they are all on
simultaneously with each at the same brightness. Pictured
below are the initialized 7-seg displays to 12:00 on
startup/reset.

D. User Input through HEX Keypad


Access to prior libraries was used to get the HEX keypad
to function. For the HEX keypad, the getkey(), keyscan(),
and wait_keyup() functions were used. The keyscan()
function is constantly reading each of the keycodes and
puts this value in PORTA. If nothing is being pressed then
it returns a value of 0x10 or 16. The getkey() function waits
for a button to be pressed and goes through a debounce
while the wait_keyup() function waits until the user has
released the key.
A breakdown of the mapping for the HEX keypad and each
digit’s functionality in the system is as follows: Keys 0-9
are used as input for the time and alarm settings. Keys ‘A’
and ‘B’ is for maneuvering up and down through the main
menu displays, respectively. Key ‘C’ acts as a backspace
key for users to delete the previous entry when setting the
time or alarm. Key ‘D’ functions as a cancel button to
disregard current user input and return to the previous main
menu display based upon the menu index (reference
Section B for further information about the LCD menu
interface). Key ‘*’ acts as the enter button for confirmation
of user selection and input. This key is used for selection
C. 7-segment Time Display into the different menu options as well as finalizing user
The 7-seg time display is initialized to 12:00 as a standard input for the time and alarm. Key ‘#’ is not mapped and
digital clock would be found. Programming the time using thus has no functionality in the system.
the HEX keypad incorporates a series of case statements.
E. Sparkfun’s MP3 Shield connected to an Arduino Uno having the alarm trigger only once allowing the program to
The purpose of utilizing a second microcontroller for the return to previous main screen function to accept another
MP3 sound file as the alarm was based solely on the ease command from the user. As for the first problem, it quickly
and availability of obtaining this functionality. The became evident quickly that the user interface display and
Arduino platform is a powerhouse in the field of clock display must be separated for proper operation.
microcontrollers and the Arduino Uno was a definitive These two sections of code conflict, only allowing one
choice when it came to which Arduino was to be used in device to be displayed/used at a time. In order to display all
this project. The option to expand the capabilities of the 7 segments constantly, a loop must be run to keep each lit
Arduino Uno through the addition of Arduino Shields at a uniform period of time. Since the user interface is
allows for an even more robust and user-friendly platform. waiting for the user to input data, the 7 segments would not
The shield that was utilized in this project was Sparkfun’s update in a proper fashion, leaving the last lit digit much
MP3 Player Shield that connects on top of the Uno’s PCB. brighter than all the rest. to eliminate this problem, both the
The MP3 Shield pulls MP3 files from a microSD card. The RTI interrupt and output compare register OC6 were
audio decoder IC on the shield operates in slave mode and implemented to multitask the operations the HCS12
receives its bitstream through SPI. After the stream has processor had to take on. Both interrupts stop the main
been decoded, the audio is sent out to a 3.5mm headphone program continuously for very short durations allowing for
jack that is connected to stereo speakers to sound the music the 7 segments to be displayed at the desired uniform rate,
alarm. while at the same time allowing the user to interact with
the clock menu options.
We are using the powerful SFEMP3Shield Arduino
Library which acts as a driver for the audio decoder IC on The second problem was encountered while testing the
the MP3 Player Shield. The library allows for a alarm. The test and trigger for the alarm were initially
straightforward implementation of playing an MP3 file. placed inside RTI interrupt 7. This was so the alarm
The Dragon12-Plus2 board simply has to establish serial variables were continuously compared at a uniform fashion
communication between itself and the Arduino Uno. This and at a rate fast enough to trigger with minimal delay. The
is done through connecting the SCI1 pinouts for Tx and Rx problem with triggering the alarm there is that this stops
to the Rx and Tx pinouts on the Arduino Uno and the rest of the interrupts from performing their function
communicating at the same baud rate. The microSD card in and does not allow for the proper display of the clock or
the MP3 Player Shield has nine different MP3 files stored provide a means for the user to turn off the alarm. No other
onto it. To play a track, the Uno simply has to receive a function can happen until the program returns from the
character of the track number. To stop the song from interrupt. On the other hand placing the code for the alarm
playing, a character of ‘s’ is sent. For example, to play in the main program loop would not allow for the alarm to
track 5 on the microSD card, the Dragon12 sends a actually sound. This is due to the fact that the main
character of “5” to the Uno and a character “s” is sent to program loop is always waiting for the user to press a key
stop the alarm. The system was programmed to play a on the hex keypad. To correct this error, the function
random song out of the nine on the microSD as the alarm. alarm_trig( ) was created and implemented in RTI
interrupt 7. This function uses a system of “if” statements
to both trigger the alarm and to set flags letting the
IV. TESTING AND RESULTS program know that the alarm was played once and should
not be sounded again until alarm time is encountered again
During assembly, the program was tested several times in another 24 hours. The main program was also modified
along the way to check for any bugs or glitches in the so the program would not wait until the user entered a key
operation. Along the way several issues were found in the but rather would respond to a command once the key was
7 segment display, alarm trigger module, and the display pressed. This was done by swapping out the getkey( )
menu functions. These issues were caught by thorough command provided by the EGR 280 library with the
testing all conditions and potential loopholes that could be keyscan( ) command encased in a conditional while loop
thought of by visually inspecting the outputs on the LCD which checked for the alarm triggered flag. This allowed
and 7 segments, by listening for the output of the music the main program to break from its main function and
from the MP3 shield, and by using a clock to time the 1 quickly operate the alarm.
minute intervals of the output capture function of the clock
timer. V. CONCLUSION
Some major problems encountered during construction of
the clock include finding a way to keep the clock Overall, the project was a tremendous success, both in its
displaying on the 7 segments at a stabilized brightness operations and in the lessons obtained from taking on such
while allowing the user interact with the clock menus and an involved project. The main lesson learned was that
seemingly simple tasks quickly became surprisingly VI. REFERENCES
complicated as other simple tasks became intertwined.
There were few issues individually in getting the 7-
segment display to display all segments at the same [1] Budakoti, A. (2014, May 9). How to generate a
intensity, the hex keypad to retrieve user input without random number in C? Retrieved from
holding up other parts of the program, the LCD interface to http://stackoverflow.com/questions/822323/how-
display the appropriate menus, the clock to function to-generate-a-random-number-in-c
[2] HASKELL, R., & HANNA, D. (2008). HEX KEYPAD. IN
properly with the use of interrupts, or get the alarm to go
LEARNING BY EXAMPLE USING C: PROGRAMMING
off. However, when you combine all these facets of the DRAGON12-PLUS USING CODEWARRIOR (SECOND
project these simple tasks start to interfere with one ED., P. 28). ROCHESTER: LBE BOOK
another. A major portion of the project was finding and [3] HUANG, H. (2006). THE HCS12/9S12: AN
resolving bugs associated with improper logic or timing INTRODUCTION TO SOFTWARE AND HARDWARE
issues. INTERFACING(SECOND ED.). CLIFTON PARK, NY:
DELMAR/THOMSON LEARNING.
One feature we would add in the future is a snooze alarm. [4] PORTER, B. (2012, JANUARY 28). SPARKFUN MP3
This could be done by generating a high or low edge over a SHIELD ARDUINO LIBRARY. RETRIEVED DECEMBER 2,
2014, FROM
certain amount of clock cycles and then using edge
HTTP://WWW .BILLPORTER.INFO/2012/01/28/SPARKFUN-
detection to trigger an interrupt for the alarm. The width of MP3-SHIELD-ARDUINO-LIBRARY/
this pulse could be generated using a formula that would
get increasingly shorter until it is perpetually on, and the
user would have to turn the alarm off.

You might also like