void Mode_WTimer3BISR(void){ ROM_TimerIntClear(WTIMER3_BASE, TIMER_CAPB_EVENT); // Doc trang thai canh ngat if (GPIOPinRead(GPIO_PORTD_BASE,GPIO_PIN_3)&GPIO_PIN_3) ui32T_Edgeup_Mode = ROM_TimerValueGet(WTIMER3_BASE, TIMER_B); else { if (firstEdgeMode) { firstEdgeMode=0; return; } ui32T_Edgedown_Mode = ROM_TimerValueGet(WTIMER3_BASE, TIMER_B); i32DeltaT_Mode = (int32_t)(ui32T_Edgedown_Mode - ui32T_Edgeup_Mode); // UARTPutn(UART0_BASE,i32DeltaT_SStop); // UARTCharPut(UART0_BASE,'\n'); // if ((i32DeltaT_Mode<125000) && (i32DeltaT_Mode>115000)) // isAuto=true; // else if ((i32DeltaT_Mode>135000) && (i32DeltaT_Mode<145000)) // isAuto=false; } }
void SStop_WTimer2AISR(void){ ROM_TimerIntClear(WTIMER2_BASE, TIMER_CAPA_EVENT); // Doc trang thai canh ngat if (GPIOPinRead(GPIO_PORTD_BASE,GPIO_PIN_0)&GPIO_PIN_0) ui32T_Edgeup_SStop = ROM_TimerValueGet(WTIMER2_BASE, TIMER_A); else { if (firstEdgeSStop) { firstEdgeSStop=0; return; } ui32T_Edgedown_SStop = ROM_TimerValueGet(WTIMER2_BASE, TIMER_A); i32DeltaT_SStop = (int32_t)(ui32T_Edgedown_SStop - ui32T_Edgeup_SStop); // UARTPutn(UART0_BASE,i32DeltaT_SStop); // UARTCharPut(UART0_BASE,'\n'); if ((i32DeltaT_SStop<125000) && (i32DeltaT_SStop>115000)) SSTOP_STOP; else if ((i32DeltaT_SStop>135000) && (i32DeltaT_SStop<145000) && isRunning) //both RF receiver and PC gui must start SSTOP_START; } }
void Throttle_WTimer2BISR(void){ ROM_TimerIntClear(WTIMER2_BASE, TIMER_CAPB_EVENT); // Doc trang thai canh ngat if (ROM_GPIOPinRead(GPIO_PORTD_BASE,GPIO_PIN_1)&GPIO_PIN_1) ui32T_Edgeup_Throttle = ROM_TimerValueGet(WTIMER2_BASE, TIMER_B); else { static int32_t sp=0,pre_sp=0; if (firstEdgeThrottle) { firstEdgeThrottle=0; return; } ui32T_Edgedown_Throttle = ROM_TimerValueGet(WTIMER2_BASE, TIMER_B); i32DeltaT_Throttle = (int32_t)(ui32T_Edgedown_Throttle - ui32T_Edgeup_Throttle); if ((i32DeltaT_Throttle<70000) || (i32DeltaT_Throttle>170000)) return; #ifdef DEBUG_DELTAT_THROTTLE printStep++; if (printStep==5) { RFprint("Throttle sp:%d\r\n", i32DeltaT_Throttle); printStep = 0; } #endif sp = (i32DeltaT_Throttle-80000)/PULSE2VEL; if (sp<0) sp=0; else if (sp>1000) sp=1000; if ((sp - pre_sp > 2)||(sp - pre_sp < -2)) throttleSet(sp); pre_sp = sp; #ifdef DEBUG_THROTTLE_SETPOINT printStep++; if (printStep==5) { RFprint("Throttle sp:%d\r\n", sp); printStep = 0; } #endif } }
//***************************************************************************** // // The interrupt handler for the fourth timer interrupt. (light) // //***************************************************************************** void Timer3IntHandler(void) { // // Clear the timer interrupt. // ROM_TimerIntClear(TIMER3_BASE, TIMER_TIMA_TIMEOUT); // Get the timer value and reset it ROM_TimerDisable(TIMER5_BASE, TIMER_A); // Get the timer value Timer = ROM_TimerValueGet(TIMER5_BASE, TIMER_A); // Reset the timer value to 65000 ROM_TimerLoadSet(TIMER5_BASE, TIMER_A, 65000); // Timer5 ROM_TimerEnable(TIMER5_BASE, TIMER_A); // // Toggle the flag for the light timer. // HWREGBITW(&g_ui32InterruptFlags, 2) = 1; // // Update the interrupt status. // }
double current_time(int reset) { if(!initFlag)InitTimer() ; initFlag = true ; if(reset)ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, -1); return (double)(-(int)ROM_TimerValueGet(TIMER0_BASE, TIMER_A ))/120000000.0 ; }
//***************************************************************************** // // The main loop of the application. This implementation is specific to the // EK-LM4F232 board and merely displays the current timer count value and the // number of interrupts taken. It contains nothing directly relevant to the // timer configuration or operation. // //***************************************************************************** void MainLoopRun(void) { uint32_t ui32Count, ui32LastCount; // // Set up for the main loop. // ui32LastCount = 10; // // Loop forever while the timer runs. // while(1) { // // Get the current timer count. // ui32Count = ROM_TimerValueGet(TIMER4_BASE, TIMER_A); // // Has it changed? // if(ui32Count != ui32LastCount) { // // Yes - update the display. // usnprintf(g_pcPrintBuff, PRINT_BUFF_SIZE, "%d ", ui32Count); GrStringDraw(&g_sContext, g_pcPrintBuff, -1, 80, 26, true); // // Remember the new count value. // ui32LastCount = ui32Count; } // // Has there been an interrupt since last we checked? // if(HWREGBITW(&g_ui32Flags, 0)) { // // Clear the bit. // HWREGBITW(&g_ui32Flags, 0) = 0; // // Update the interrupt count. // usnprintf(g_pcPrintBuff, PRINT_BUFF_SIZE, "%d ", g_ui32IntCount); GrStringDraw(&g_sContext, g_pcPrintBuff, -1, 80, 36, true); } } }
void delay(uint32_t nTime) { ROM_TimerLoadSet(WTIMER5_BASE, TIMER_A, nTime * 10); ROM_TimerIntEnable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(WTIMER5_BASE, TIMER_A); ROM_SysCtlSleep(); // Make sure the timer finished, go back to sleep if it didn't // (Another interrupt may have woken up the system) while (ROM_TimerValueGet(WTIMER5_BASE, TIMER_A) != nTime * 10) ROM_SysCtlSleep(); ROM_TimerIntDisable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerDisable(WTIMER5_BASE, TIMER_A); }
uint32_t micros(void) { return 0xFFFFFFFF - ROM_TimerValueGet(WTIMER4_BASE, TIMER_B); }
uint32_t millis(void) { return (0xFFFFFFFF - ROM_TimerValueGet(WTIMER4_BASE, TIMER_A)) / 2; }
void Steering_WTimer3AISR(void){ ROM_TimerIntClear(WTIMER3_BASE, TIMER_CAPA_EVENT); // Doc trang thai canh ngat if (isAuto) return; if (ROM_GPIOPinRead(GPIO_PORTD_BASE,GPIO_PIN_2)&GPIO_PIN_2) ui32T_Edgeup_Steering = ROM_TimerValueGet(WTIMER3_BASE, TIMER_A); else { static int32_t sp = 0, i=0; if (firstEdgeSteering) { firstEdgeSteering=0; return; } ui32T_Edgedown_Steering = ROM_TimerValueGet(WTIMER3_BASE, TIMER_A); i32DeltaT_Steering = (int32_t)(ui32T_Edgedown_Steering - ui32T_Edgeup_Steering); if (i<10) { i32SteeringMid += i32DeltaT_Steering; i++; if (i==10) { i32SteeringMid = i32SteeringMid/10; } return; } i32Pulse_Steering = i32DeltaT_Steering-i32SteeringMid; if ((i32Pulse_Steering<-50000) || (i32Pulse_Steering>50000)) return; // UARTPutn(UART0_BASE, i32Pulse_Steering); // ROM_UARTCharPut(UART0_BASE, '\n'); #ifdef DEBUG_DELTAT_STEERING printStep++; if (printStep==5) { RFprint("Steering:%d\r\n",i32DeltaT_Steering); printStep = 0; } #endif if (i32Pulse_Steering < -DEADBAND_STEERING) { i32Pulse_Steering = sp + (i32Pulse_Steering+DEADBAND_STEERING)/T2VEL; if (i32Pulse_Steering<-MAX_STEERING_SETPOINT) sp = -MAX_STEERING_SETPOINT; else sp = i32Pulse_Steering; steeringSet(sp,-1); } else if (i32Pulse_Steering > DEADBAND_STEERING) { i32Pulse_Steering = sp + (i32Pulse_Steering-DEADBAND_STEERING)/T2VEL; if (i32Pulse_Steering>MAX_STEERING_SETPOINT) sp = MAX_STEERING_SETPOINT; else sp = i32Pulse_Steering; steeringSet(sp,-1); } #ifdef DEBUG_STEERING_SETPOINT printStep++; if (printStep==5) { RFprint("Steering sp:%d\r\n", sp); printStep = 0; } #endif } }
unsigned long micros(void) { return 4294967295 - ROM_TimerValueGet(WTIMER4_BASE, TIMER_B); }
unsigned long millis(void) { return (4294967295 - ROM_TimerValueGet(WTIMER4_BASE, TIMER_A)) / 2; }