There are two main state machines running at the same time. The first one is to check whether there is a button press and the second one carries out respective function after a button is pressed.
The first state machine (StateMachine) uses the debounce scheme that has been using in previous lab to detect a button press. Debounce scheme is used to avoid the performance of multiple tasks when the button is held for too long. Inside this state machine, when it detects a button press the flag ‘buttonpress’ will become 1. This signal tells state machine two whether a button is being pressed or not.
The second state machine (Operation) synchronizes with the first one by the ‘buttonpress’ flag. It performs instruction only when ‘buttonpress’ is equal to 1. When a function is carried out in state machine two, before exiting ‘buttonpress’ is set back to 0 to avoid a continuous running of the second state machine. The following describes what will happen if different button is pressed.
When Set button is pressed:
The state machine will go to the SetHour state where variable ‘temphour’ is alternated by the increment and decrement button. Also it detects to see whether it is now in 12-Hour mode or 24-Hour mode since different display method for the variable Hour is required. ‘temphour’ is running in a military time bases (0-23), adjustment is made on the variable hour depends on whether it is now in 12-Hour state or 24-Hour state. The state machine will keep running in the SetHour state unless Set button is pressed. When the set button is pressed, SetMin is the next state and there the variable Minute is alternated. Same criteria as SetHour. The next state will be DaySet, MonthSet, YearSet and WeekSet. Inside these states, they are all using the same mechanism as the one in SetHour. They follow one another and when Set is pressed in the WeekSet state the state machine will jump back to the Release state to wait for next button press.
When Alarm Set is pressed:
The state machine will jump into the AlarmSetHour state. Again the same mechanism is used as SetHour but this time the variable Alarmtemphour is being altered. The next state will beAlarmsetmin. If Set is pressed in the Alarmsetmin state it will jump back to the release state.
When 12HR/24HR is pressed:
The state machine will jump into the HourSwitch. If it is currently in 12HR mode it will change to 24HR mode by doing some calculations on the Hour variable with reference to the ‘temphour’, and vice versa.
When Alarm is pressed:
The state machine will not jump to anywhere but setting the Alarmbutton to 1 if it is currently 0 and vice versa. This indicates the Alarm function that the button is pressed so when time alarm time matches the current time it will buzz. The alarm will not be working at all unless Alarmbutton = 1, even if alarm time equals to the current time.
When Light is pressed:
It switches on and off of the LEDs.
Another function called Alarm is running at the background also. Every interrupts it will check to see if the alarm time is equal to the current time or not. If they are and the alarmbutton = 1, the buzzer is turned on.
The Trigger function is used to keep the voice recognition system in listening mode so that it will provide respective respond if there is a match word.
The AT90S8515 was chosen for the purposes of our project. We used the 90S8515 because we can utilize the built-in timer1 and timer0 interrupts more than special functions with FLASH memory or any analog to digital conversions. As well, due to the simple structure of our implementation we only utilized C programming in our project.
We used timer1 interrupt to keep track of the time to ensure we have an accurate clock scheme. OCR1A for the timer1 is set to 8000, which allows it to go into interrupt every 1ms.
1ms x 1/(8MHz) = 8000
\OCR1A = 8000
We chose 1ms to be our basis point because this gives the easiest prediction of how the state machines will behave in our program. Other variables like minutes, hours, days, etc are all being calculated within the 1ms interrupt time base. In the Timer1 interrupt program, there is a counter where ‘second’ will increment once when the counter equals to 1000. This is because 1000 x 1ms = 1 sec.
We used timer0 interrupt to generate sound for our alarm, and keep track of how fast the button push state machines are. Similarly, we calibrated timer0 to interrupt every 1ms to allow us to have an easy prediction of how and when the interrupt is set and entered.