void heartbeat_int(void) { uint32_t status = TimerIntStatus( TIMER0_BASE, 0 ); TimerIntClear( TIMER0_BASE, status ); jaguar_heartbeat(); }
void ServoInterrupt(){ //Remember to clear the interrupt flags uint32_t status=0; status = TimerIntStatus(TIMER5_BASE,true); TimerIntClear(TIMER5_BASE,status); /* * This increments the counter * The counter works like a timer in PWM mode in count up mode. * The value 4000 sets the wave period. * Then we have the "match" values that set the positive pulse width, * those are the values saved in the array ServoPos. The outputs start as HIGH and go to LOW * when the match value is reached */ ServoCount++; uint32_t i; if(ServoCount > 4000) ServoCount = 0; for(i=0; i < ServoNumber; i++){ ServoPos[i] = ServoPosTemp[i]; } for(i=0; i < ServoNumber; i++){ if(ServoCount > ServoPos[i]) GPIOPinWrite(ServoBase[i],ServoPin[i], 0); else GPIOPinWrite(ServoBase[i],ServoPin[i], ServoPin[i]); } }
//***************************************************************************** // //! \biref The main example function //! //! \return none // //***************************************************************************** void OneSecondClock(void) { SysCtlHClockSet(SYSCTL_XTAL_12MHZ | SYSCTL_OSC_MAIN); // // Set the timer clock // SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_TMR0_S_EXT12M); // // Enable tiemr0 // SysCtlPeripheralEnable(SYSCTL_PERIPH_TMR0); // // Clear the flag first // TimerIntClear(TIMER0_BASE, TIMER_INT_MATCH); while(TimerIntStatus(TIMER0_BASE, TIMER_INT_MATCH)); // // Config as One shot mode // TimerInitConfig(TIMER0_BASE, TIMER_MODE_PERIODIC, 1000); TimerPrescaleSet(TIMER0_BASE, 91); TimerMatchSet(TIMER0_BASE, 0x1ffff); TimerIntEnable(TIMER0_BASE, TIMER_INT_MATCH); // // Start the timer // TimerStart(TIMER0_BASE); // // One shot mode test. // while(1) { // // wait until the timer data register reach equel to compare register // while(!TimerIntStatus(TIMER0_BASE, TIMER_INT_MATCH)); TimerIntClear(TIMER0_BASE, TIMER_INT_MATCH); } }
void Timer0A_Handler(void){ static unsigned long Counter = 0; // may interrupt from timeouts multiple times before edge unsigned long ulIntFlags = TimerIntStatus(TIMER0_BASE, true); TimerIntClear(TIMER0_BASE, ulIntFlags);// acknowledge if(ulIntFlags & TIMER_TIMA_TIMEOUT) { Counter++; // keep track of timeouts } if(ulIntFlags & TIMER_CAPA_EVENT) { Period = Last - TimerValueGet(TIMER0_BASE, TIMER_A) + Counter*TimerLoadGet(TIMER0_BASE, TIMER_A); Last = TimerValueGet(TIMER0_BASE, TIMER_A); Counter = 0; } }
void UpdateSpeed_ISR(){ uint32_t status = TimerIntStatus(WTIMER4_BASE,true); TimerIntClear(WTIMER4_BASE,status); if(Target_Dir !=0){ Direction_Dir=QEIDirectionGet(QEI0_BASE); EncoderDirVel=( (QEIVelocityGet(QEI0_BASE)*13)/48*12) * Direction_Dir; Error_Dir = Target_Dir - EncoderDirVel; I_Dir = (I_Dir+Error_Dir) * Ki_Dir; D_Dir = D_Dir * (Error_Dir - LastError_Dir); PID_Dir = P_Dir + I_Dir + D_Dir; if(PID_Dir > 1022) PID_Dir = 1022; else if(PID_Dir < -1022) PID_Dir = -1022; } else{ PID_Dir = 0; I_Dir=0; Error_Dir=0; } if(Target_Esq !=0){ Direction_Esq=QEIDirectionGet(QEI1_BASE); EncoderEsqVel=( (QEIVelocityGet(QEI1_BASE)*13)/48*12) * Direction_Esq; Error_Esq = Target_Esq - EncoderEsqVel; I_Esq = (I_Esq+Error_Esq) * Ki_Esq; D_Esq = D_Esq * (Error_Esq - LastError_Esq); PID_Esq = P_Esq + I_Esq + D_Esq ; if(PID_Esq > 1022) PID_Esq = 1022; else if(PID_Esq < -1022) PID_Esq = -1022; } else{ PID_Esq = 0; I_Esq=0; Error_Esq=0; } DRV8833_MotorB(PID_Dir); DRV8833_MotorA(PID_Esq); LastError_Dir = Error_Dir; LastError_Esq = Error_Esq; }
/* In Startup.S, added: * * EXTERN EdgeSampler * * Under the EXPORT __Vectors, changed this line: * * DCD EdgeSampler ; Timer 0 subtimer A * */ void EdgeSampler(void){ unsigned long intType= TimerIntStatus(TIMER0_BASE, false); TimerIntClear(TIMER0_BASE, TIMER_CAPA_EVENT | TIMER_TIMA_TIMEOUT); // If we have a timeout, return instantly if(intType== TIMER_TIMA_TIMEOUT){ ++timeoutCount; return; // If we catch an edge, check the period width (measured in timeouts) }else if(intType== TIMER_CAPA_EVENT){ if(timeoutCount > 5 && timeoutCount < 9){ // 0-bit size ++bitCount; }else if(timeoutCount > 12 && timeoutCount < 16){ // 1-bit size currCommand|= 0x80000000 >> bitCount; ++bitCount; }else if(timeoutCount > 70 && timeoutCount < 80){ // Repeat pulse size
void Timer0AIntHandler(void) { uint32_t intStatus; intStatus = TimerIntStatus(TIMER0_BASE, true); TimerIntClear(TIMER0_BASE, intStatus); /***********************************************/ get_AttitudeVal(gyroTmp); control_Attitudes(gyroTmp); #if 0 sendLineX(MCU1, 0X1F, gtmp[0]); sendLineX(MCU1, 0X2F, gtmp[1]); sendLineX(MCU1, 0X3F, gtmp[2]); sendLineX(MCU1, 0X4F, pitch); sendLineX(MCU1, 0X5F, roll); sendLineX(MCU1, 0X6F, yaw); #endif /***********************************************/ }
void ProcessTimerHandler(void) { IntDisable(INT_TIMER0A); uint32_t int_status = TimerIntStatus(TIMER0_BASE, false); TimerIntClear(TIMER0_BASE, int_status); uint16_t i = current_index; uint16_t size = DmaRxDataAvailable(current_index); for (i = 0; i < size; ++i) { uint8_t c = uart_rx_buf[current_index]; // Try to detect packet start if (state == STATE_WAITING_START) { if (c == packet_start[check_at]) { ++check_at; if (check_at == 4) { state = STATE_READ_SIZE1; check_at = 0; } } else { //UARTprintf("\nFrom UART: Invalid packet start.\n"); check_at = 0; } } else if (state == STATE_READ_SIZE1) { state = STATE_READ_SIZE2; packet_length = 0; ((uint8_t*)&packet_length)[0] = c; } else if (state == STATE_READ_SIZE2) { ((uint8_t*)&packet_length)[1] = c; UARTprintf("UART: %d; ", packet_length); if (packet_length >= 2500) { UARTprintf("Ignoring invalid huge packet %d\n", packet_length); state = STATE_WAITING_START; } else { rec_packet_start_index = current_index; state = STATE_READ_PACKET; rec_packet_size = 0; rec_packet_checksum = 0; } } else if (state == STATE_READ_PACKET) { if (rec_packet_size == packet_length) { uint8_t checksum = c; if (rec_packet_checksum != checksum) { state = STATE_WAITING_START; UARTprintf("Invalid checksum!\n", rec_packet_size); } else { state = STATE_WAITING_START; UARTprintf("--%d--> \n", rec_packet_size); } } else { rec_packet_checksum += c; ++rec_packet_size; } } ++current_index; if (current_index == UART_RX_BLOCKS_COUNT * UART_RX_BLOCK_SIZE) { current_index = 0; } if (state == STATE_WAITING_START) { uart_rx_read_index = current_index; } } IntEnable(INT_TIMER0A); }
void Timer1BIntHandler(void) { uint32_t intStatus; intStatus = TimerIntStatus(TIMER1_BASE, true); TimerIntClear(TIMER1_BASE, intStatus); //g_ui32Counter++; timeCounter++; keyStatus = KeyScan(); if(keyStatus == 1) { iss = 1; M1_LED_ON; setMotorPowerMax(); pduty += 50; } else if(keyStatus == 2) { iss = 2; M1_LED_OFF; setMotorPowerMin(); } #ifdef USE_MCU2 switch(keyStatus) { case 0: M2_LED1_OFF; M2_LED2_OFF; break; case 1: M2_LED1_ON; //GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0, 0x01); //GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, 0x02); break; case 2: M2_LED2_ON; //GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0, 0x00); //GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, 0x00); M2_LED4_OFF; break; case 3: disVal++; if(disVal % 2 == 0) { M2_LED3_ON; M2_LED4_ON; } else { M2_LED3_OFF; M2_LED4_OFF; } break; } #endif if(timeCounter == NUMBER_OF_INTS) { //g_ui32Counter = 0; timeCounter = 0; #if 0 disVal++; if(disVal % 2 == 0) M1_LED_ON; else M1_LED_OFF; #endif //OLED_P6x8Num(2,4,disVal++); //stop_Timer0B(); } }
//***************************************************************************** // //! \brief xtimer 001 test execute main body. //! //! \return None. // //***************************************************************************** static void xTimer001Execute(void) { unsigned long ulTemp; unsigned long ulBase; int i, j ; // // One shot mode test. // for(i = 0; i < 4; i++) { ulBase = ulTimerBase[i]; // // Clear the flag first // TimerIntClear(ulBase, TIMER_INT_MATCH); while(TimerIntStatus(ulBase, TIMER_INT_MATCH)); // // Config as One shot mode // TimerInitConfig(ulBase, TIMER_MODE_ONESHOT, 1000); TimerIntEnable(ulBase, TIMER_INT_MATCH); xIntEnable(ulTimerIntID[i]); xTimerIntCallbackInit(ulBase, TimerCallbackFunc[i]); TimerStart(ulBase); // // wait until the timer data register reach equel to compare register // TestAssertQBreak("a","One shot mode Intterrupt test fail", -1); xIntDisable(ulTimerIntID[i]); } // // Periodic mode // for(i = 0; i < 4; i++) { ulBase = ulTimerBase[i]; ulTemp = 0; // // Clear the flag first // TimerIntClear(ulBase, TIMER_INT_MATCH); // // Config as periodic mode // TimerInitConfig(ulBase, TIMER_MODE_PERIODIC, 1000); TimerIntEnable(ulBase, TIMER_INT_MATCH); TimerStart(ulBase); // // wait the periodic repeat 5 times // for (j = 0; j < 5; j++) { while(!TimerIntStatus(ulBase, TIMER_INT_MATCH)); ulTemp++; if(ulTemp == 5) { break; } TimerIntClear(ulBase, TIMER_INT_MATCH); } TestAssert(ulTemp == 5, "xtimer mode \" periodic test\" error!"); TimerStop(ulBase); } // // Toggle mode test // for(i = 0; i < 4; i++) { ulBase = ulTimerBase[i]; ulTemp = 0; // // Clear the Int flag first // TimerIntClear(ulBase, TIMER_INT_MATCH); // // Config as toggle mode // TimerInitConfig(ulBase, TIMER_MODE_PERIODIC, 1000); TimerIntEnable(ulBase, TIMER_INT_MATCH); TimerStart(ulBase); // // wait the toggle repeat 5 times // for (j = 0; j < 5; j++) { while(!TimerIntStatus(ulBase, TIMER_INT_MATCH)); ulTemp++; if(ulTemp == 5) { break; } TimerIntClear(ulBase, TIMER_INT_MATCH); } TestAssert(ulTemp == 5, "xtimer mode \" Toggle mode test\" error!"); TimerStop(ulBase); } // // Continuous mode test. // for(i = 0; i < 4; i++) { ulBase = ulTimerBase[i]; ulTemp = 0; // // Clear the flag first // TimerIntClear(ulBase, TIMER_INT_MATCH); while(TimerIntStatus(ulBase, TIMER_INT_MATCH)); // // Config as One shot mode // TimerInitConfig(ulBase, TIMER_MODE_CONTINUOUS, 10000); TimerMatchSet(ulBase, 10); TimerIntEnable(ulBase, TIMER_INT_MATCH); TimerStart(ulBase); // // Delay some time to wait the count register reach to 200. // xSysCtlDelay(100); if(TimerIntStatus(ulBase, TIMER_INT_MATCH) == xtrue) { ulTemp++; } TimerIntClear(ulBase, TIMER_INT_MATCH); TimerMatchSet(ulBase, 2000); // // Wait until reach the 1000 // //while(!TimerIntStatus(ulBase, TIMER_INT_MATCH)); xSysCtlDelay(10000); if(TimerIntStatus(ulBase, TIMER_INT_MATCH) == xtrue) { ulTemp++; } TimerIntClear(ulBase, TIMER_INT_MATCH); TestAssert(ulTemp == 2, "xtimer mode \" Continuous mode test\" error!"); TimerStop(ulBase); xIntDisable(ulTimerIntID[i]); } }