I decided to go for a slightly harder approach to the task. Below is a Block Diagram of the system.
To make the alarm clock I decided to make the minutes of the clock count first. Below is the circuit diagram.
I wired up two seven segment displays to two 7447 seven segment decoder chips. Both 7447 segment decoder chips were connected to port A of the micro controller.
Below is the code I used to get the seven segment displays to count from 0 to 59 to represent the minutes of the clock.
Dim A As integer
Dim Mu As integer
Dim Mt As integer
Out $3a , $ff
Do
For Mt = 0 to 5
For Mu = 0 to 9
A = Mt x 16
A = A + Mu
Out $3b , A
Wait 1
Next Mu
Next Mt
Loop
I powered up the circuit to test if the seven segment displays counted from 0 to 59 and repeat. It worked. I made the seven segment displays count fast on purpose so I wouldn’t have to wait an whole hour to see if it counted from 0 to 59 and start over again. I will change the delay later on in the project.
I am now going to connect two more seven segment displays and 7447 seven-segment decoders to port C of the micro controller.
Port A will be connected to the two seven segment displays that will represent the hours and port C will be connected to the two seven segment displays that will represent the minutes.
Below is the circuit diagram of the alarm clock.
Below is the code I used in the micro controller.
Dim A As integer
Dim A As integer
Dim Mu As integer
Dim Mt As integer
Dim Hu As integer
Dim Ht As integer
Out $34 , $ff
Out $3a , $ff
Do
For Ht = 0 to 2
For Hu = 0 to 9
If Ht = 2 AND Hu = 4 then
Ht = 0
Hu = 0
End if
B = Ht x 16
B = B + Mu
Out $3b , B
For Mt = 0 to 5
For Mu = 0 to 9
A = Mt x 16
A = A + Mu
Out $35 , A
Wait 1
Next Mu
Next Mt
Next Hu
Next Ht
Loop
I powered up the circuit to test if the clock worked. The test was successful. It counted up to 24 hours then repeated itself.
I am now going to add switches to port B to enable me to change and set the time correctly.
Dim A As Integer
Dim B As Integer
Dim Mu As Integer
Dim Mt As Integer
Dim Hu As Integer
Dim Ht As Integer
Dim C As Integer
Dim Settime As Integer
Out $34 , $ff
Out $3a , $ff
Do
For Ht = 0 To 2
For Hu = 0 To 9
If Ht = 2 And Hu = 4 Then
Ht = 0
Hu = 0
End If
B = Ht * 16
B = B + Hu
Out $3b , B
For Mt = 0 To 5
For Mu = 0 To 9
For C = 0 To 15
A = Mt * 16
A = A + Mu
Out $35 , A
Settime = Inp($36)
Settime = Settime And $01
If Settime => 0 Then
Settime = Inp($36)
Settime = Settime And $02
If Settime > 0 Then Mu = Mu + 1
Settime = Inp($36)
Settime = Settime And $04
If Settime > 0 Then Mu = Mu - 1
End If
Wait 1
Next C
Next Mu
Next Mt
Next Hu
Next Ht
Loop
To test if the set time function worked I powered up the circuit and set the time to 02:36, the test was successful.
I am now going to make the alarm, to do this I will make an Astable using a 555-timer chip. The Astable will be connected to Port D pin 10 of the Atmel AT90S8515 micro controller and a speaker will be connected to the output of the Astable.
F = 1.44
(R1 = 2R2) C
F = 700 Hz
C = 1000 nf
R2 = 10K Ω
R1 =?
Rearrange the formulae to find R1
R1 = 1.44 - 2R2
FC
R1 = _ 1.44 _ - 20K Ω
700Hz X 100nf
R1 = 571Ω
560 Ω is the nearest value resistor
Code used to set alarm and stop alarm
Dim A As Integer
Dim B As Integer
Dim Mu As Integer
Dim Mt As Integer
Dim Hu As Integer
Dim Ht As Integer
Dim C As Integer
Dim Amu As Integer
Dim Amt As Integer
Dim Ahu As Integer
Dim Aht As Integer
Dim Setalarm As Integer
Dim Alarmstop As Integer
Dim Settime As Integer
Out $34 , $ff
Out $3a , $ff
Out $31 , $ff
Out $37 , $e0
Ht = 0
Hu = 0
Mt = 0
Mu = 0
Do
Mu = Mu + 1
For C = 0 To 59
If Ht = 2 And Hu = 4 Then
Hu = 0
Ht = 0
End If
B = Ht * 16
B = B + Hu
Out $3b , B
A = Mt * 16
A = A + Mu
Out $35 , A
Settime = Inp($36)
Settime = Settime And $01
If Settime => 0 Then
Settime = Inp($36)
Settime = Settime And $07
If Settime = 3 Then Mu = Mu + 1
If Settime = 5 Then Mu = Mu - 1
End If
If Mu = 10 Then
Mu = 0
Mt = Mt + 1
End If
If Mt = 6 Then
Mt = 0
Hu = Hu + 1
End If
If Hu = 10 Then
Hu = 0
Ht = Ht + 1
End If
If Ht = 2 And Hu = 4 Then
Ht = 0
Hu = 0
End If
If Mu = -1 Then
Mu = 9
Mt = Mt - 1
End If
If Mt = -1 Then
Mt = 5
Hu = Hu - 1
End If
If Hu = -1 Then
Hu = 9
Ht = Ht - 1
End If
If Ht = -1 Then
Ht = 2
End If
Wait 1
Setalarm = Inp($36) And $08
While Setalarm = 8
B = Aht * 16
B = B + Ahu
Out $3b , B
A = Amt * 16
A = A + Amu
Out $35 , A
Setalarm = Inp($36)
Setalarm = Setalarm And 14
If Setalarm = 10 Then Amu = Amu + 1
If Setalarm = 12 Then Amu = Amu - 1
If Amu = 10 Then
Amu = 0
Amt = Amt + 1
End If
If Amt = 6 Then
Amt = 0
Ahu = Ahu + 1
End If
If Ahu = 10 Then
Ahu = 0
Aht = Aht + 1
End If
If Aht = 2 And Ahu = 4 Then
Aht = 0
Ahu = 0
End If
If Amu = -1 Then
Amu = 9
Amt = Amt - 1
End If
If Amt = -1 Then
Amt = 5
Ahu = Ahu - 1
End If
If Ahu = -1 Then
Ahu = 9
Aht = Aht - 1
End If
If Aht = -1 Then
Aht = 2
End If
Waitms 500
Setalarm = Inp($36) And $08
Wend
Alarmstop = Inp($36)
Alarmstop = Alarmstop And 16
If Alarmstop => 0 Then
Out $38 , 0
End If
If Ht = Aht And Hu = Ahu And Mt = Amt And Mu = Amu And C = 0 Then
Out $38 , $80
End If
Next C
Loop
I powered up the circuit, set the time to 03:34 and the alarm to 03:36. When the time reached 03:36 I found two problems with the alarm clock. Firstly when the alarm sounded the sound was very low, too low for an alarm. Secondly the alarm only came on for 1 second then went off again.
The first problem is an electronic problem so I had to look at my circuit to solve the sound level of the alarm I decided to connect a mossffet to the speaker, as this would increase the current to the speaker hence increasing the sound level of the alarm. Below is the diagram.
I powered up the circuit, set the time to 03:45 and the alarm to 03:58. When the time reached 03:58 the alarm sound was much louder. I measured the sound level with a sound level meter it read 90dB. I was happy as it was within the boundaries of my specification for the sound level of the alarm, which is 85 – 95 dB.
The second problem is a program problem so I looked at my code, in particular the section the Alarm Stop section. I had made a simple mistake.
Alarmstop = Inp($36)
Alarmstop = Alarmstop And 16
If Alarmstop => 0 Then
Out $38 , 0
End If
It should be,
Alarmstop = Inp($36)
Alarmstop = Alarmstop And 16
If Alarmstop > 0 Then
Out $38 , 0
End If
I made the alteration and tested the alarm as I did before. It worked.
Testing
Assessment
After assessing my system I have come to the conclusion that as a whole my system is functioning as it is specified to in my specification.
Once powered up I am able to set the time accordingly with ease by holding down the Set time button and pressing the up/down button, set the alarm by holding down the Set alarm button and pressing the up/down button. When the alarm is trigged the sound level (90 dB) is loud enough to wake a person up from sleep and can be easily switched off by pressing the Stop alarm button. The time is accurate to 100% and is erasable to read.
Overall I am pleased with my system as it is fully functioning and meets all of my requirements.
Limitations and modifications
I have found that my system is limited in one way, which is that the seconds of the time are not displayed. This was not part of my specification but if I were to redo my project I would have added this point to the specification. This is easily doable by adding two more seven segment displays and a bit more coding, which would be very similar to the one I have done.
Evaluation of final system
I am pleased with the outcome of my project. It meets all the specification requirements. After carrying out the testing of the whole system I have found that I am able to set the time and alarm accordingly, stop the alarm once it is triggered. The loudness of the alarm is 90dB which is in the boundaries of 85dB – 95dB. All the seven segment displays have the brightness of above 0.80 lux. The hours and minutes are clearly visible. The system works from a range of power supplies and the clock is 100%accurate