Appendix K: Pseudocode for Pedometer and Timer
Pedometer's ISR
The program enters this ISR on a negative edge of the IRQ
line, and during the bouncing phase it will enter this
routine a number of times and each time setting the bounce
flag.
-
Pedometer_ISR
-
IF (pedometer timer is not enabled)
-
Enable timer
-
Clear bounce_occurred flag
-
IF (state equals idle)
-
Set state to step_occuring
-
ELSE
-
Set state to step_occuring_waiting_for_direction
-
ENDIF
-
ELSE
-
Set bounce_occurred flag
-
ENDIF
-
RETURN
Timer's ISR
Once the timer is enabled, the program enters this ISR
every 8.2 ms until the timer is disabled which occurs after
205 ms of non-bouncing from the pedometer.
-
Timer_ISR
-
IF (bounce_occurred)
-
reset 205 ms counter
-
Clear the bounce_occurred flag
-
ELSE
-
Add 1 to the 205 ms counter
-
IF (205 ms counter equals 25)
-
disable interrupt timer
-
reset 205 ms counter
-
register the step
-
IF (state equals step_occurring)
-
signal compass a new direction is needed
-
ENDIF
-
change state to step_occurred_waiting_for_direction
-
ENDIF
-
ENDIF
-
RETURN