ES_Event RunLidarService( ES_Event ThisEvent ) { // ES_Event New_Event; ES_Event ReturnEvent; ReturnEvent.EventType = ES_NO_EVENT; // assume no errors switch (CurrentLidarState) { case InitLidar: // If current state is initial Psedudo State if (ThisEvent.EventType == ES_INIT)// only respond to ES_Init { CurrentLidarState = LidarStart; printf("\r\n Lidar Inited \r\n"); //ES_Timer_InitTimer(LIDAR_TIMER, 100); } break; case LidarStart: if (ThisEvent.EventType == GET_DISTANCE) { //printf("\r\n GET_DISTANCE received in Lidar"); if (Period == 0){ HWREG(GPIO_PORTE_BASE+(GPIO_O_DATA + ALL_BITS)) &= BIT2LO; TriggerLow = true; CurrentLidarState = LidarMeasure; ES_Timer_InitTimer(LIDAR_TIMER, 50); ReturnEvent.EventType = ES_NO_EVENT; } } break; case LidarMeasure: if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == LIDAR_TIMER) { if (Period2Return != 0){ //Distance = (float)Period2Return/(float)800; Distance = (float)((Period2Return*25/20000)*2.02-21.87); ES_Event Event2Post; Event2Post.EventType = DISTANCE_FOUND; PostMasterSM(Event2Post); TriggerLow = false; printf("\r\n Lidar Measure result is %f", Distance); HWREG(GPIO_PORTE_BASE+(GPIO_O_DATA + ALL_BITS)) |= BIT2HI; Period = 0; CurrentLidarState = LidarStart; ReturnEvent.EventType = ES_NO_EVENT; } } else { ES_Timer_InitTimer(LIDAR_TIMER, 50); ReturnEvent.EventType = ES_NO_EVENT; } break; } // end switch on Current State return ReturnEvent; }
/**************************************************************************** Function RunMapKeys Parameters ES_Event : the event to process Returns ES_Event, ES_NO_EVENT if no error ES_ERROR otherwise Description maps keys to Events for HierMuWave Example Notes Author J. Edward Carryer, 02/07/12, 00:08 ****************************************************************************/ ES_Event RunMapKeys( ES_Event ThisEvent ) { ES_Event ReturnEvent; ReturnEvent.EventType = ES_NO_EVENT; // assume no errors if ( ThisEvent.EventType == ES_NEW_KEY) // there was a key pressed { printf("Key entered: \t %c\r\n",toupper(ThisEvent.EventParam)); switch ( toupper(ThisEvent.EventParam)) { // this sample is just a dummy so it posts a ES_NO_EVENT case '0': ThisEvent.EventType = ES_NO_EVENT; break; case 'A': ThisEvent.EventType = GAME_STARTED; break; case 'B': ThisEvent.EventType = CITY_FOUND; break; case 'C': ThisEvent.EventType = IR_FOUND; break; case 'D': ThisEvent.EventType = SHOOT_CITY; ThisEvent.EventParam = 8; break; case 'S': ThisEvent.EventType = SEND2PAC; ThisEvent.EventParam = (0xB0 | 5); break; case 'F': ThisEvent.EventType = CITY_COMPLETED; break; case 'G': ThisEvent.EventType = FRONT_BUMPER_HIT; break; case 'H': ThisEvent.EventType = ES_TIMEOUT; ThisEvent.EventParam = TURN_TIMER; break; case 'Z': ThisEvent.EventType = GAME_OVER; break; case '?': ReportAllStates(); break; default: ReportAllStates(); ThisEvent.EventType = ES_NO_EVENT; break; } PostEventPrinter(ThisEvent); PostMasterSM(ThisEvent); } return ReturnEvent; }
static ES_Event DuringProcessingState( ES_Event Event) { ES_Event ReturnEvent = Event; // assme no re-mapping or comsumption // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events if ( (Event.EventType == ES_ENTRY) || (Event.EventType == ES_ENTRY_HISTORY) ) { // implement any entry actions required for this state machine // after that start any lower level machines that run in this state //StartLowerLevelSM( Event ); // repeat the StartxxxSM() functions for concurrent state machines // on the lower level //printf("\r\n Entry Event DuringProcessing"); // no lower Level SMs here ES_Event GoProcess; GoProcess.EventType = ES_NO_EVENT; PostMasterSM(GoProcess); } else if ( Event.EventType == ES_EXIT ) { // on exit, give the lower levels a chance to clean up first //RunLowerLevelSM(Event); // repeat for any concurrently running state machines // now do any local exit functionality //printf("\r\n Entry Event ExitProcessing"); }else // do the 'during' function for this state { // run any lower level state machine // ReturnEvent = RunLowerLevelSM(Event); printf("\r\n In PROCESSING"); // repeat for any concurrent lower level machines //printf("\r\n Else DuringProcessing"); // do any activity that is repeated as long as we are in this state updateOurKartStatus(); ES_Event DoneProcessing; DoneProcessing.EventType = DONE_PROCESSING; PostMasterSM(DoneProcessing); } // return either Event, if you don't want to allow the lower level machine // to remap the current event, or ReturnEvent if you do want to allow it. return(ReturnEvent); }
static void PIControl(void){ // start by clearing the source of the interrupt HWREG(WTIMER1_BASE+TIMER_O_ICR) = TIMER_ICR_TATOCINT; HWREG(WTIMER1_BASE+TIMER_O_ICR) = TIMER_ICR_TBTOCINT; TargetRPMLeft = (float)GetTargetRPMLeft(); TargetRPMRight = (float)GetTargetRPMRight(); if(TargetRPMLeft >= 0){ RPMErrorL = TargetRPMLeft - (float)rpmL; SpeedControlState.LeftDirection = FOR; }else{ RPMErrorL = -(float)rpmL-TargetRPMLeft; SpeedControlState.LeftDirection = REV; } IntegralTermL += iGain * RPMErrorL; SpeedControlState.RequestedDutyL = (uint16_t)(pGain * ((RPMErrorL)+IntegralTermL)); //printf("\r\n request duty left %i", SpeedControlState.RequestedDutyL); if(SpeedControlState.RequestedDutyL > 100 && RPMErrorL > 0){ IntegralTermL -= iGain * RPMErrorL; SpeedControlState.RequestedDutyL=100; }else if(SpeedControlState.RequestedDutyL < 0 && RPMErrorL < 0 ){ IntegralTermL -= iGain * RPMErrorL; SpeedControlState.RequestedDutyL=0; } if(TargetRPMRight >= 0){ RPMErrorR = TargetRPMRight - (float)rpmR; SpeedControlState.RightDirection = FOR; }else{ RPMErrorR = -(float)rpmR-TargetRPMRight; SpeedControlState.LeftDirection = REV; } //printf("\r\n current rpm right %i left %i",rpmR, rpmL); //printf("\r\n target rpm right %f left %f",TargetRPMRight,TargetRPMLeft); //printf("\r\n error right %f left %f", RPMErrorR, RPMErrorL); IntegralTermR += iGain * RPMErrorR; SpeedControlState.RequestedDutyR = (uint16_t)(pGain * ((RPMErrorR)+IntegralTermR)); //printf("\r\n request duty right %i", SpeedControlState.RequestedDutyR); if(SpeedControlState.RequestedDutyR > 100 && RPMErrorR > 0){ IntegralTermR -= iGain * RPMErrorR; SpeedControlState.RequestedDutyR=100; }else if(SpeedControlState.RequestedDutyR < 0 && RPMErrorR < 0 ){ IntegralTermR -= iGain * RPMErrorR; SpeedControlState.RequestedDutyR=0; } ES_Event Event2Post; Event2Post.EventType = PWM_UPDATE; PostMasterSM(Event2Post); }
/**************************************************************************** Function RunMapKeys Parameters ES_Event : the event to process Returns ES_Event, ES_NO_EVENT if no error ES_ERROR otherwise Description maps keys to Events for HierMuWave Example Notes Author J. Edward Carryer, 02/07/12, 00:08 ****************************************************************************/ ES_Event RunMapKeys( ES_Event ThisEvent ) { ES_Event ReturnEvent; ReturnEvent.EventType = ES_NO_EVENT; // assume no errors if ( ThisEvent.EventType == ES_NEW_KEY) // there was a key pressed { switch ( toupper(ThisEvent.EventParam)) { // this sample is just a dummy so it posts a ES_NO_EVENT case 'O' : ThisEvent.EventType = ES_NO_EVENT; break; case 'A' :ThisEvent.EventType = GAME_STATUS_CHANGE; ThisEvent.EventParam = 1; break; case 'B' :ThisEvent.EventType = CHANGE_LED_COLOR; break; case 'C' :ThisEvent.EventType = ENTER_SHOOT_AREA; break; case 'D' :ThisEvent.EventType = ARRIVE_LOCATION; break; case 'E' :ThisEvent.EventType = GET_RESPONSE; ThisEvent.EventParam = 1; break; case 'F' :ThisEvent.EventType = IR_ALIGNED; break; case 'G' : ThisEvent.EventType = FIELD_MEASURED; break; case 'H' :ThisEvent.EventType = FORWARD; ThisEvent.EventParam = 100; break; case 'I' :ThisEvent.EventType = CLOCKWISE; ThisEvent.EventParam = 100; break; case 'J' :ThisEvent.EventType = COUNTERCLOCKWISE; ThisEvent.EventParam = 100; break; case 'K' :ThisEvent.EventType = STOP; ThisEvent.EventParam = 100; break; case 'L' :ThisEvent.EventType = BACKWARD; ThisEvent.EventParam = 100; break; case 'M' :ThisEvent.EventType = ALIGNBEACON; break; case 'N' :ThisEvent.EventType = GETTING_GAME_STATUS_TOPPAC; break; } PostMasterSM(ThisEvent); } return ReturnEvent; }
static ES_Event DuringAttack_t( ES_Event Event) { ES_Event ReturnEvent = Event; // assme no re-mapping or comsumption // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events if ( (Event.EventType == ES_ENTRY) || (Event.EventType == ES_ENTRY_HISTORY) ) { // implement any entry actions required for this state machine // Stop positioning when in the attack SM ES_Timer_StopTimer(POSITION_CHECK); // after that start any lower level machines that run in this state //StartLowerLevelSM( Event ); StartAttackSM(Event); // repeat the StartxxxSM() functions for concurrent state machines // on the lower level } else if ( Event.EventType == ES_EXIT ) { // on exit, give the lower levels a chance to clean up first //RunLowerLevelSM(Event); ReturnEvent = RunAttackSM(Event); // repeat for any concurrently running state machines // now do any local exit functionality // Count the number of shots, and don't start a next shot timer // if we are out of ammo shotCounter++; if (shotCounter < 5) { ES_Timer_InitTimer(ATTACK_PHASE_TIMER, NEXT_SHOT_T); } // Reset positioning ES_Event ResetEvent; ResetEvent.EventType = ES_RESET_DESTINATION; PostMasterSM(ResetEvent); }else // do the 'during' function for this state { // run any lower level state machine // ReturnEvent = RunLowerLevelSM(Event); ReturnEvent = RunAttackSM(Event); // repeat for any concurrent lower level machines // do any activity that is repeated as long as we are in this state } // return either Event, if you don't want to allow the lower level machine // to remap the current event, or ReturnEvent if you do want to allow it. return(ReturnEvent); }
//Interrupt Response to Manage our Control Feedback loop to the motors void CannonControl_PeriodicInterruptResponse(void){ // start by clearing the source of the interrupt clearPeriodicInterrupt(CANNON_CONTROL_INTERRUPT_PARAMATERS); //Calculate RPM static float currentRPM; currentRPM = CalculateRPM(); // If we're supposed to get the cannon up to speed if (Revving) { // If the cannon is at its target speed, post it if (SpeedCheck(currentRPM)) { ES_Event NewEvent; NewEvent.EventType = ES_CANNON_READY; PostMasterSM(NewEvent); Revving = false; SpeedCheckTimeoutCounter = 0; } else { // Otherwise, increment a timeout counter SpeedCheckTimeoutCounter++; if (SpeedCheckTimeoutCounter > SPEED_CHECK_LIMIT) { ES_Event NewEvent; NewEvent.EventType = ES_CANNON_READY; PostMasterSM(NewEvent); Revving = false; SpeedCheckTimeoutCounter = 0; } } } //Calculate Control Response calculateControlResponse(currentRPM); }
void HallCaptureRightResponse(void){ HWREG(WTIMER3_BASE+TIMER_O_ICR) = TIMER_ICR_CAECINT; //Clear the source of the interrupt //Grab the capture value and calculate for the period uint32_t ThisCapture; ThisCapture = HWREG(WTIMER3_BASE+TIMER_O_TAR); PeriodR[counterR]=ThisCapture - LastCaptureRight; counterR++; // update LastCapture to prepare for the next edge if(counterR >= aveNum){ counterR = 0; ES_Event Event2Post; Event2Post.EventType = HALL_DETECT; Event2Post.EventParam = RIGHT; PostMasterSM(Event2Post); } LastCaptureRight = ThisCapture; }
void HallCaptureMidResponse(void){ HWREG(WTIMER2_BASE+TIMER_O_ICR) = TIMER_ICR_CBECINT; //Clear the source of the interrupt //Grab the capture value and calculate for the period uint32_t ThisCapture; ThisCapture = HWREG(WTIMER2_BASE+TIMER_O_TBR); PeriodM[counterM]=ThisCapture-LastCaptureMid; counterM++; // update LastCapture to prepare for the next edge if(counterM >= aveNum){ counterM = 0; ES_Event Event2Post; Event2Post.EventType = HALL_DETECT; Event2Post.EventParam = MID; PostMasterSM(Event2Post); } LastCaptureMid = ThisCapture; }
//The interrupt response for our phototransistor void PhotoTransistor_InterruptResponse(void) { // Clear Interrupt clearCaptureInterrupt(PHOTOTRANSISTOR_INTERRUPT_PARAMATERS); // Determine Capture time uint32_t ThisCapture = captureInterrupt(PHOTOTRANSISTOR_INTERRUPT_PARAMATERS); // Calculate period uint32_t Period = ((ThisCapture - LastCapture) * MICROSECONDS_DIVISOR ) / TICKS_PER_MS; //Store the Last Cpature LastCapture = ThisCapture; //Iterate Through the different frequency options for (int i = 0; i < NUMBER_BEACON_FREQUENCIES; i++) { // If the period matches a beacon period if (ToleranceCheck(Period, beacons[i].period, PERIOD_MEASURING_ERROR_TOLERANCE)) { // If we're searching for a beacon if (Bucketing) { buckets[i]++; } // If we're supposed to align to the bucket, and the number of pulses we've seen for // this beacon is greater than our threshold if ((AligningToBucket) && (buckets[i] >= NUMBER_PULSES_FOR_BUCKET)) { // If this is the beacon corresponding to our target bucket if (((MyColor() == COLOR_BLUE) && (i == BEACON_INDEX_NW)) || ((MyColor() == COLOR_RED) && (i == BEACON_INDEX_SE))) { // stop our drive clearDriveAligningToBucket(); // Post an aligned event ES_Event AlignedEvent; AlignedEvent.EventType = ES_ALIGNED_TO_BUCKET; PostMasterSM(AlignedEvent); // stop aligning AligningToBucket = false; // reset all buckets for (int j = 0; j < NUMBER_BEACON_FREQUENCIES; j++) { buckets[j] = 0; } // reset average information ResetAverage(); // return to searching for beacons Bucketing = true; LastBeacon = NULL_BEACON; ES_Timer_StopTimer(AVERAGE_BEACONS_TIMER); return; } } // If we're not aligning to a bucket, and the number of pulses we've seen for this // beacon is greater than our threshold else if (buckets[i] >= NUMBER_PULSES_TO_BE_ALIGNED && LastBeacon == NULL_BEACON && !AligningToBucket) { // store the beacon to be recorded LastBeacon = i; // reset all buckets for (int j = 0; j < NUMBER_BEACON_FREQUENCIES; j++) { buckets[j] = 0; } // restart the timer to evaluate the beacon ES_Timer_InitTimer(AVERAGE_BEACONS_TIMER, AVERAGE_BEACONS_T); Bucketing = false; } // increment the sum of all encoder angles for this beacon sums[i] += GetPeriscopeAngle(); // increment the number of pulses seen for this beacon numSamples[i]++; // If the evaluation timer is already running, restart it ES_Timer_SetTimer(AVERAGE_BEACONS_TIMER, AVERAGE_BEACONS_T); } } }
/**************************************************************************** Function RunRPMSM ****************************************************************************/ ES_Event RunRPMSM( ES_Event CurrentEvent ) { bool MakeTransition = false;/* are we making a state transition? */ RPMState_t NextState = CurrentState; ES_Event EntryEventKind = { ES_ENTRY, 0 };// default to normal entry to new state ES_Event ReturnEvent = CurrentEvent; // assume we are not consuming event switch(CurrentState) { case CONTROL : if(CurrentEvent.EventType == ES_TIMEOUT){ if(CurrentEvent.EventParam == ENCODER_TIMER){ //printf("\r\nRPM are %i left %i right, Errors are %f left %f right",rpmL, rpmR, RPMErrorL, RPMErrorR); //distance control distSofarR = absCounterR/12.0/50*PI*3.937; distSofarL = absCounterL/15.7/50*PI*3.937; //printf("\r\n dist left %f dist right %f", distSofarL, distSofarR); float distance = Querydistance(); if(TargetRPMLeft > 0 && TargetRPMRight > 0){ float diff = distance - (distSofarL+distSofarR)/2.0; //printf("\r\n distance to destination %f", diff); if(diff < 0){ ES_Event Event2Post; Event2Post.EventType = STOP; PostMasterSM(Event2Post); //Stop(); ES_Timer_InitTimer(MOTOR_TIMER, ONE_SEC/10); NextState = IDLE; MakeTransition = true; ES_Timer_InitTimer(ENCODER_TIMER, ONE_SEC/100); printf("\r\n change to idle"); }else if(diff < 0.5){ ES_Event Event2Post; Event2Post.EventType = DECELERATE; uint16_t newRPMTarget = (uint16_t)(80.0*RPM_DC_RATIO/4); //printf("\r\n new rpm target %i", newRPMTarget); Event2Post.EventParam = newRPMTarget; PostMasterSM(Event2Post); PIControl(); ES_Timer_InitTimer(ENCODER_TIMER, ONE_SEC/100); }else if(diff < 1.0){ ES_Event Event2Post; Event2Post.EventType = DECELERATE; uint16_t newRPMTarget = (uint16_t)(80.0*RPM_DC_RATIO/2); //printf("\r\n new rpm target %i", newRPMTarget); Event2Post.EventParam = newRPMTarget; PostMasterSM(Event2Post); PIControl(); ES_Timer_InitTimer(ENCODER_TIMER, ONE_SEC/100); }else{ PIControl(); ES_Timer_InitTimer(ENCODER_TIMER, ONE_SEC/100); } }else{ float aveAngleSoFar = (distSofarR+distSofarL)/2.0/(D/2.0); float angle = PI; //QueryAngle(); float ratio = aveAngleSoFar/angle; //printf("\r\n angle ratio %f", ratio); if (angle - aveAngleSoFar <= 0){ //ES_Event Event2Post; //Event2Post.EventType = MOTION_COMPLETED; //PostMasterSM(Event2Post); Stop(); ES_Timer_InitTimer(MOTOR_TIMER, ONE_SEC/100); NextState = IDLE; // NextState }else{ PIControl(); ES_Timer_InitTimer(ENCODER_TIMER, ONE_SEC/100); } } } if(CurrentEvent.EventParam == INPUT_STOP_TIMER){ ES_Timer_InitTimer(INPUT_STOP_TIMER, ONE_SEC/10); uint32_t newPeriodL; newPeriodL = avePeriodL; if(lastPeriodL == newPeriodL){ rpmL=0; //printf("\r\nleft motor stops"); } lastPeriodL = newPeriodL; uint32_t newPeriodR; newPeriodR = avePeriodR; if(lastPeriodR == newPeriodR){ rpmR=0; //printf("\r\nright motor stops"); } lastPeriodR = newPeriodR; ReturnEvent.EventType = ES_NO_EVENT; } //break; } break; case IDLE: if(CurrentEvent.EventType == ES_TIMEOUT && CurrentEvent.EventParam == MOTOR_TIMER){ NextState = CONTROL; MakeTransition = true; ES_Event Event2Post; printf("\r\n change to control"); //ES_Timer_InitTimer(ENCODER_TIMER, ONE_SEC/10); Event2Post.EventType = MOTION_COMPLETED; PostMasterSM(Event2Post); ReturnEvent.EventType = ES_NO_EVENT; } break; } // NextState = STATE_TWO;//Decide what the next state will be // MakeTransition = true; //mark that we are taking a transition // EntryEventKind.EventType = ES_ENTRY_HISTORY; // ReturnEvent.EventType = ES_NO_EVENT; // if (MakeTransition == true) { CurrentEvent.EventType = ES_EXIT; RunRPMSM(CurrentEvent); CurrentState = NextState; RunRPMSM(EntryEventKind); } return(ReturnEvent); }
/**************************************************************************** Function RunAlignBeaconSM ****************************************************************************/ ES_Event RunHallSensor( ES_Event CurrentEvent ) { ES_Event ReturnEvent = CurrentEvent; // ????????????????? NO EVENT? ES_Event Event2Post; uint32_t period = 0; switch (CurrentEvent.EventType) { case HALL_DETECT : switch (CurrentEvent.EventParam) { case LEFT : for (uint8_t i=0; i<aveNum; i++){ avePeriodL += PeriodL[i]; } avePeriodL = avePeriodL/aveNum; period = avePeriodL*1000/111*100/PWMTicksPerMS; printf("\r\n left measured period is %i", period); break; case RIGHT : for (uint8_t i=0; i<aveNum; i++){ avePeriodR += PeriodR[i]; } avePeriodR = avePeriodR/aveNum; period = avePeriodR*1000/111*100/PWMTicksPerMS; printf("\r\n right measured period is %i", period); break; case MID : for (uint8_t i=0; i<aveNum; i++){ avePeriodM += PeriodM[i]; } avePeriodM = avePeriodM/aveNum; period = avePeriodM*1000/111*100/PWMTicksPerMS; printf("\r\n middle measured period is %i", period); break; } if(period>(500-Period_Toler) && period<(500+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x0f; PostMasterSM(Event2Post); }else if(period>(556-Period_Toler) && period<(556+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x0e; PostMasterSM(Event2Post); }else if(period>(611-Period_Toler) && period<(611+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x0d; PostMasterSM(Event2Post); }else if(period>(667-Period_Toler) && period<(667+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x0c; PostMasterSM(Event2Post); }else if(period>(722-Period_Toler) && period<(722+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x0b; PostMasterSM(Event2Post); }else if(period>(778-Period_Toler) && period<(778+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x0a; PostMasterSM(Event2Post); }else if(period>(833-Period_Toler) && period<(833+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x09; PostMasterSM(Event2Post); }else if(period>(889-Period_Toler) && period<(889+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x08; PostMasterSM(Event2Post); }else if(period>(944-Period_Toler) && period<(944+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x07; PostMasterSM(Event2Post); }else if(period>(1000-Period_Toler) && period<(1000+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x06; PostMasterSM(Event2Post); }else if(period>(1055-Period_Toler) && period<(1055+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x05; PostMasterSM(Event2Post); }else if(period>(1111-Period_Toler) && period<(1111+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x04; PostMasterSM(Event2Post); }else if(period>(1166-Period_Toler) && period<(1166+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x03; PostMasterSM(Event2Post); }else if(period>(1222-Period_Toler) && period<(1222+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x02; PostMasterSM(Event2Post); }else if(period>(1277-Period_Toler) && period<(1277+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x01; PostMasterSM(Event2Post); }else if(period>(1333-Period_Toler) && period<(1333+Period_Toler) ){ Event2Post.EventType = HallSensorRead; Event2Post.EventParam = 0x00; PostMasterSM(Event2Post); }else{ printf("\r\nfrequency not match"); } ReturnEvent.EventType = ES_NO_EVENT; break; } return(ReturnEvent); }