Pseudocode for BeaconService.c Module level variables: volatile static unsigned int PeriodR; volatile static unsigned int PeriodL; static unsigned int LastRisingEdge; static unsigned int LastFallingEdge; static int BeaconsSensed = NeitherSensed; static int BeaconNumber = 0; InitBeaconService Initialize the standard timer library Turn the timer system on Set the pre-scale to /128 Set prescale to /16 Set to capture rising edge for T0 and falling edge for T1 Set TIOS to capture pins 0 and 1 on port T Clear all flags Enable associated capture interrupts on T0 & T1 Enable interrupts Initialize timer to run at 1ms and time out at 50ms Post the initial transition event ES_EVENT RunBeaconService Local variables: int i ES_Event ReturnEvent; ReturnEvent.EventType = ES_NO_EVENT; If EventType is ES_TIMEOUT Sample the Beacon Sensors If either period is within range of interest For i = 0, i less than 5 Call beacon check function. Else post neither aligned Increment i If beacon check function returns 1 Break out of for loop End if End for End if Else update BeaconsSensed to NeitherSensed Reset PeriodR and PeriodL to 0 Reset the timer to 50ms Break and return ReturnEvent Global Functions: Int QueryBeacons Return BeaconsSensed Int QueryBeaconNumber Return BeaconNumber Local Functions: Void BeaconCheck(Int CurrentBinTested): Function Level Variables: unsigned int LowerThreshold; unsigned int UpperThreshold; If CurrentBinTested is 1 Assign proper thresholds for bin 1 Else if CurrentBinTested is 2 Assign proper thresholds for bin 2 Else if CurrentBinTested is 3 Assign proper thresholds for bin 3 Else if CurrentBinTested is 4 Assign proper thresholds for bin 4 If PeriodL is greater than LowerThreshold and Period L is less than UpperThreshold And PeriodR isgreater than LowerThreshold and Period R is less than UpperThreshold BeaconsSensed is equal to BothSensed; BeaconNumber is equal to CurrentBinTested; Else if PeriodL is greater than LowerThreshold and PeriodR is less than UpperThreshold BeaconsSensed is equal to LeftSensed; BeaconNumber is equal to CurrentBinTested; Else if PeriodR is greater than LowerThreshold and PeriodR is less than UpperThreshold BeaconsSensed is equal to RightSensed; BeaconNumber is equal to CurrentBinTested; void interrupt _Vec_tim0ch4 RespToPhotoTransistorL(void) Local variables: unsigned int CurrentTime; Clear the interrupt flag Update CurrentTime Update PeriodL to CurrentTime – LastRisingEdge Update LastRisingEdge to CurrentTime void interrupt _Vec_tim0ch5 RespToPhotoTransistorR(void) Local variables: unsigned int CurrentTime; Clear the interrupt flag Update CurrentTime Update PeriodR to CurrentTime – LastFallingEdge Update LastFallingEdge to CurrentTime