// WTimer1A is used to measure the width of the pulses // WTimer1B is used to turn off motors if the connection to the RX is lost void initRX(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER1); // Enable Wide Timer1 peripheral SysCtlDelay(2); // Insert a few cycles after enabling the peripheral to allow the clock to be fully activated SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); // Enable GPIOC peripheral SysCtlDelay(2); // Insert a few cycles after enabling the peripheral to allow the clock to be fully activated GPIOPinConfigure(GPIO_PC6_WT1CCP0); // Use alternate function GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_6); // Use pin with timer peripheral // Split timers and enable timer A event up-count timer and timer B as a periodic timer TimerConfigure(WTIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP | TIMER_CFG_B_PERIODIC); // Configure WTimer1A TimerControlEvent(WTIMER1_BASE, TIMER_A, TIMER_EVENT_BOTH_EDGES); // Interrupt on both edges TimerIntRegister(WTIMER1_BASE, TIMER_A, CaptureHandler); // Register interrupt handler TimerIntEnable(WTIMER1_BASE, TIMER_CAPA_EVENT); // Enable timer capture A event interrupt IntPrioritySet(INT_WTIMER1A, 0); // Configure Wide Timer 1A interrupt priority as 0 IntEnable(INT_WTIMER1A); // Enable Wide Timer 1A interrupt // Configure WTimer1B timerLoadValue = SysCtlClockGet() / 10 - 1; // Set to interrupt every 100ms TimerLoadSet(WTIMER1_BASE, TIMER_B, timerLoadValue); TimerIntRegister(WTIMER1_BASE, TIMER_B, TimeoutHandler); // Register interrupt handler TimerIntEnable(WTIMER1_BASE, TIMER_TIMB_TIMEOUT); // Enable timer timeout interrupt IntPrioritySet(INT_WTIMER1B, 0); // Configure Wide Timer 1B interrupt priority as 0 IntEnable(INT_WTIMER1B); // Enable Wide Timer 1B interrupt TimerEnable(WTIMER1_BASE, TIMER_BOTH); // Enable both timers validRXData = false; }
void Interrupt_WDTimer0Init(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0); TimerConfigure(WTIMER0_BASE,TIMER_CFG_A_CAP_COUNT_UP); TimerControlEvent(WTIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE); TimerLoadSet(WTIMER0_BASE,TIMER_A,0x00); //TimerEnable(WTIMER0_BASE, TIMER_A); }
int main() { //Enable Peripherals SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Start specific Pin Ports GPIOPinTypeGPIOOutput(port_A, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4); GPIOPinTypeGPIOOutput(port_C, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); GPIOPinTypeGPIOOutput(port_D, GPIO_PIN_6); GPIOPinTypeGPIOOutput(port_E, GPIO_PIN_0); GPIOPinTypeGPIOOutput(port_F, GPIO_PIN_4); GPIOPinTypeGPIOInput(port_F, GPIO_PIN_2 | GPIO_PIN_3); //Timer Configuration TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); TimerLoadSet(TIMER0_BASE, TIMER_A, frequency); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); TimerEnable(TIMER0_BASE, TIMER_A); //Enable pin for interrupt GPIOIntEnable(GPIO_PORTF_BASE, (GPIO_INT_PIN_2 | GPIO_INT_PIN_3)); //Set ISR GPIOIntRegister(GPIO_PORTF_BASE, the_taco_meter); //Set interrupt type GPIOIntTypeSet(GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3) , GPIO_BOTH_EDGES); //Initialize the display initializeDisplay(); //RS High GPIOPinWrite(port_C, GPIO_PIN_5, pin_5); write_string("Speed = #### RPM"); while(1) { taco_display(); } }
void Tach_Init(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0); /* Setup Timer0A Counter in edge-time-capture mode. */ TimerDisable(TIMER0_BASE, TIMER_A); //TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_CAP_TIME | TIMER_CFG_B_PERIODIC); TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT | TIMER_TIMA_TIMEOUT); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); TimerLoadSet(TIMER0_BASE, TIMER_A, 0xFFFF); IntEnable(INT_TIMER0A); // Activate timer TimerEnable(TIMER0_BASE, TIMER_A); }
void init(){ // Init OLED RIT128x96x4Init(1000000); // Set the clock to 50 MHz SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // Select SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Navigation Switches SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // CAN Connection SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0); GPIOPinTypeCAN(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1); CANInit(CAN0_BASE); CANBitRateSet(CAN0_BASE, 8000000, 250000); CANIntEnable(CAN0_BASE, CAN_INT_MASTER); IntEnable(INT_CAN0); CANEnable(CAN0_BASE); // CAN Objects transmit.ulMsgID= 0x200; transmit.ulMsgIDMask= 0; transmit.ulMsgLen= 2*sizeof(unsigned long); // IR Receiver SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_4); // Timer SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_A_CAP_TIME); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_NEG_EDGE); TimerLoadSet(TIMER0_BASE, TIMER_A, TIME_WIDTH); TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT | TIMER_TIMA_TIMEOUT); TimerEnable(TIMER0_BASE, TIMER_A); IntEnable(INT_TIMER0A); }
/* TIMER_init - initial timer module */ void TIMER_init(TIMER_t *timer) { /* Configure timers mode */ TimerConfigure(timer->base, timer->config); if (timer->event_config != 0xffffffff) TimerControlEvent(timer->base, timer->ntimer, timer->event_config); TimerPrescaleSet(timer->base, timer->ntimer, timer->prescale); TimerLoadSet(timer->base, timer->ntimer, timer->value); if (timer->handler) { TimerIntEnable(timer->base, timer->intermod); /* Registe timer handler */ TimerIntRegister(timer->base, timer->ntimer, timer->handler); /* Setup the interrupt for the timer timeouts */ IntEnable(timer->interrupt); /* Enable the timer */ /* TimerEnable(timer->base, timer->ntimer); */ } } /* ----- end of function TIMER_init ----- */
int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //Set up the general purpose I/Os SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);//1024hz = 15625 //Set up the input/output pins GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_1); GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6); //Set up the interrupt pins GPIOIntEnable(GPIO_PORTC_BASE, GPIO_INT_PIN_5 | GPIO_INT_PIN_6); GPIOIntRegister(GPIO_PORTC_BASE, interrupt_handler); GPIOIntTypeSet(GPIO_PORTC_BASE, (GPIO_PIN_5 | GPIO_PIN_6), GPIO_RISING_EDGE); //Just a quick toggle to make sure code is working toggle(); //Timer Configuration TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); TimerLoadSet(TIMER0_BASE, TIMER_A, frequency); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); TimerEnable(TIMER0_BASE, TIMER_A); //Timer Interrupt Enable TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerIntRegister(TIMER0_BASE, TIMER_A, timer_interrupt); //Loop forever while(1){ // if(TimerValueGet(TIMER0_BASE, TIMER_A) == 0){ // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, pin_data); // pin_data^=0x04; // } } }
int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //Configure System Clock //SSD SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //Enable Port D SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Enable Port B GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,0x0F); GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,0xFF); //S1 and S2 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Enable Port F //Mode 1 SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //Enable ADC0 Module SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //Enable Port E GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1); //Select ADC Function of PE 1 ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0); //Configure ADC0 Sequencer ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END); //Configure the step of the sequencer //Mode 2 SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); //Enable TIMER1 Module GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4); //Set PF4 as Input GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); //Configuring the PF4 GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_BOTH_EDGES); //Setting Interrupt to trigger on both edges TimerConfigure(TIMER1_BASE,TIMER_CFG_PERIODIC); //Configure TIMER1 into a Continuous Mode TimerIntRegister(TIMER1_BASE, TIMER_A, fast); //Register interrupt if PF4 pressed for more than 1s //Mode 3 SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4); //Enable TIMER4 Module SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0); //Enable WTIMER0 Module SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); //Enable Port C GPIOPinConfigure(GPIO_PC4_WT0CCP0); GPIOPinTypeTimer(GPIO_PORTC_BASE,GPIO_PIN_4); //Set PC4 as a Timer Capture pin TimerIntRegister(TIMER4_BASE,TIMER_A,freqfind); //Register a timer interrupt for TIMER4 TimerConfigure(TIMER4_BASE,TIMER_CFG_PERIODIC); //Configure Timer4 in continuous mode TimerConfigure(WTIMER0_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_CAP_COUNT); TimerControlEvent(WTIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE); //Configure WTIMER0 for Positive Edge Capture IntMasterEnable(); GPIOPinWrite(GPIO_PORTB_BASE,0xFF,0x00); //Initialize SSD to 0x00 GPIOPinWrite(GPIO_PORTD_BASE, 0x0F, 0x00); //Turn off all the digits of the SSD SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Enable TIMER0 Module TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC); //Configure TIMER0 into a Continuous Mode TimerIntRegister(TIMER0_BASE, TIMER_A, ssdmux); //Register ISR for TIMER0 Interrupt to update SSD TimerLoadSet(TIMER0_BASE, TIMER_A,SysCtlClockGet()/3000); //Set the refresh rate of the SSD IntEnable(INT_TIMER0A); TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT); //Enable the timer interrupt TimerEnable(TIMER0_BASE,TIMER_A); //Start the timer HWREG(GPIO_PORTF_BASE|GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE|GPIO_O_CR) = GPIO_PIN_0; //Unlock PF0 from the NMI mode HWREG(GPIO_PORTF_BASE|GPIO_O_LOCK) = 0; ssdset(0); mode1set(); GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0); //Setting PF0 to Input GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); //Configuring the pins GPIOIntRegister(GPIO_PORTF_BASE, modeselect); //Register Interrupt for Port F with ISR modeselect() GPIOIntClear(GPIO_PORTF_BASE, GPIO_PIN_0); //Clear any existing interrupts GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_FALLING_EDGE); //Setting Interrupt to trigger on falling edges GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_0); //Enable the GPIO Interrupts on Port F IntEnable(INT_GPIOF); //Enable Interrupts on Port F while(1){ switch(mode) //Select operation according to mode { case 1: mode1(); break; case 2: ssdsetHex(hex_count); if(fast_flag) { mode2(); SysCtlDelay(SysCtlClockGet()/300); } break; case 3: mode3(); break; case 4: mode1(); break; case 5: ssdsetHex(hex_count); if(fast_flag) { mode2(); SysCtlDelay(SysCtlClockGet()/300); } break; } SysCtlDelay(SysCtlClockGet()/3000); } return 0; }
int main(void) { //Set the clock SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //Enable the peripherals SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); //Set the input type GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4); GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2); GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_6); //Timer Configuration TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); TimerControlEvent(TIMER1_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); TimerLoadSet(TIMER1_BASE, TIMER_A, 50000); TimerEnable(TIMER1_BASE, TIMER_A); while(1) { //Check the state of the timer if(TimerValueGet(TIMER1_BASE, TIMER_A) == 0x0) { number++; //reanable the timer. TimerLoadSet(TIMER1_BASE, TIMER_A, 50000); } int first_nible = (number & first_digit) >> 4; int second_nible = (number & second_digit); if(first_nible >= 10) { first_nible = first_nible + 7; } if(second_nible >=10) { second_nible = second_nible + 7; } //Turn off both displays GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, pin_4); GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2, pin_2); //Make sure all data pins are low lower_pins(); //Send Data sevenSegWrite((char)(((int)'0')+first_nible)); //Turn on first 7-seg control signal GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, 0x00); timer_delay(); //Turn off control signal for both 7-seg GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, pin_4); GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2, pin_2); //Make sure all data pins are low lower_pins(); //Send Data sevenSegWrite((char)(((int)'0')+second_nible)); //Turn on second 7-seg control signal GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2, 0x00); timer_delay(); } }
int main() { //Set the Clock at 16MHZ SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //Enable Timer Peripheral SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Enable Peripherals SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Initialize Output ports GPIOPinTypeGPIOOutput(port_A, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4); GPIOPinTypeGPIOOutput(port_C, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); GPIOPinTypeGPIOOutput(port_D, GPIO_PIN_6); GPIOPinTypeGPIOOutput(port_E, GPIO_PIN_0); GPIOPinTypeGPIOOutput(port_F, (GPIO_PIN_4 | GPIO_PIN_1 | GPIO_PIN_3)); //Input Pins GPIOPinTypeGPIOInput(port_F, GPIO_PIN_2 | GPIO_PIN_3); //Interrupt Enables GPIOIntEnable(GPIO_PORTF_BASE, (GPIO_INT_PIN_2 | GPIO_INT_PIN_3)); GPIOIntRegister(GPIO_PORTF_BASE, interrupt_handler); GPIOIntTypeSet(GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3) , GPIO_FALLING_EDGE); //Timer Setup TimerLoadSet(TIMER0_BASE, TIMER_A, 0xFFFF); TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_NEG_EDGE); TimerEnable(TIMER0_BASE, TIMER_A); //Initialize the display initializeDisplay(); while(1) { if(display_flag == 1) { //Software Debouncing display_flag = 0; SysCtlDelay(160000); //Clear scree clear_screen(); //RS High for writing GPIOPinWrite(port_C, GPIO_PIN_5, pin_5); write_char_to_pins((char)(((int)'0')+ (0x00FF & TimerValueGet(TIMER0_BASE, TIMER_A))% 10)); //Back to Low GPIOPinWrite(port_C, GPIO_PIN_5, 0x0); } } }
// After a certain number of edges are captured, the application prints out // the results and compares the elapsed time between edges to the expected // value. // // Note that the "B" timer is used because on some devices the "A" timer does // not work correctly with the uDMA controller. Refer to the chip errata for // details. // //***************************************************************************** int main(void) { unsigned long ulIdx; unsigned short usTimerElapsed; //unsigned short usTimerErr; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the UART and write a status message. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_EVEN)); //UARTStdioInit(0); //UARTprintf("\033[2JuDMA edge capture timer example\n\n"); //UARTprintf("This example requires that PD0 and PD7 be jumpered together" // "\n\n"); // // Create a signal source that can be used as an input for the CCP1 pin. // SetupSignalSource(); // // Enable the GPIO port used for the CCP1 input. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the Timer0 CCP1 function to use PD7 // GPIOPinConfigure(GPIO_PB2_CCP3); GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2); // // Set up Timer0B for edge-timer mode, positive edge // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_CAP_TIME); TimerControlEvent(TIMER1_BASE, TIMER_B, TIMER_EVENT_BOTH_EDGES); TimerLoadSet(TIMER1_BASE, TIMER_B, 0xffff); // // Enable the uDMA peripheral // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ucControlTable); // // Put the attributes in a known state for the uDMA Timer0B channel. These // should already be disabled by default. // ROM_uDMAChannelAttributeDisable(UDMA_CHANNEL_TMR1B, UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK); // // Configure DMA channel for Timer0B to transfer 16-bit values, 1 at a // time. The source is fixed and the destination increments by 16-bits // (2 bytes) at a time. // ROM_uDMAChannelControlSet(UDMA_CHANNEL_TMR1B | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1); // // Set up the transfer parameters for the Timer0B primary control // structure. The mode is set to basic, the transfer source is the // Timer0B register, and the destination is a memory buffer. The // transfer size is set to a fixed number of capture events. // ROM_uDMAChannelTransferSet(UDMA_CHANNEL_TMR1B | UDMA_PRI_SELECT, UDMA_MODE_BASIC, (void *)(TIMER1_BASE + TIMER_O_TBR), g_usTimerBuf, MAX_TIMER_EVENTS); // // Enable the timer capture event interrupt. Note that this signal is // used to trigger the DMA request and not an actual interrupt. // Start the capture timer running and enable its interrupt channel. // The timer interrupt channel is used by the uDMA controller. // //UARTprintf("Starting timer and uDMA\n"); TimerIntEnable(TIMER1_BASE, TIMER_CAPB_EVENT); TimerEnable(TIMER1_BASE, TIMER_B); IntEnable(INT_TIMER1B); // // Now enable the DMA channel for Timer0B. It should now start performing // transfers whenever there is a rising edge detected on the CCP1 pin. // ROM_uDMAChannelEnable(UDMA_CHANNEL_TMR1B); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Wait for the transfer to complete. // //UARTprintf("Waiting for transfers to complete\n"); while(!g_bDoneFlag) { } // // Check for the expected number of occurrences of the interrupt handler, // and that there are no DMA errors // if(g_uluDMAErrCount != 0) { //UARTprintf("\nuDMA errors were detected!!!\n\n"); } if(g_ulTimer0BIntCount != 1) { //UARTprintf("\nUnexpected number of interrupts occurrred (%d)!!!\n\n", // g_ulTimer0BIntCount); } // // Display the timer values that were captured using the edge capture timer // with uDMA. Compare the difference between stored values to the PWM // period and make sure they match. This verifies that the edge capture // DMA transfers were occurring with the correct timing. // //UARTprintf("\n Captured\n"); //UARTprintf("Event Value Difference Status\n"); //UARTprintf("----- -------- ---------- ------\n"); const unsigned char nbColonnes = '1'; UARTSend(&nbColonnes,1); for(ulIdx = 1; ulIdx < MAX_TIMER_EVENTS; ulIdx++) { // // Due to timer erratum, when the timer rolls past 0 as it counts // down, it will trigger an additional DMA transfer even though there // was not an edge capture. This will appear in the data buffer as // a duplicate value - the value will be the same as the prior capture // value. Therefore, in this example we skip past the duplicated // value. // if(g_usTimerBuf[ulIdx] == g_usTimerBuf[ulIdx - 1]) { const unsigned char dup = '$'; UARTSend(&dup,1); //UARTprintf(" %2u 0x%04X skipped duplicate\n", ulIdx, // g_usTimerBuf[ulIdx]); continue; } // // Compute the difference between adjacent captured values, and then // compare that to the expected timeout period. // usTimerElapsed = g_usTimerBuf[ulIdx - 1] - g_usTimerBuf[ulIdx]; //usTimerErr = usTimerElapsed > TIMEOUT_VAL ? // usTimerElapsed - TIMEOUT_VAL : // TIMEOUT_VAL - usTimerElapsed; // // Print the captured value and the difference from the previous // unsigned char data[10]; itoa(usTimerElapsed,data); UARTSend(data,10); //UARTprintf(" %2u 0x%04X %8u ", ulIdx, g_usTimerBuf[ulIdx], // usTimerElapsed); // // Print error status based on the deviation from expected difference // between samples (calculated above). Allow for a difference of up // to 1 cycle. Any more than that is considered an error. // //if(usTimerErr > 1) //{ // UARTprintf(" ERROR\n"); //} //else //{ // UARTprintf(" OK\n"); //} } const unsigned char fin = '\n'; UARTSend(&fin,1); // // End of application // while(1) { } }
/******** Timer_Init ******************************************************* // Initialize timer as either CCP, PWM or regular timer // Input: // timer - one of the Timer_T value ( Timer1A, Timer1B... ) // config - indicates the operational mode of the timer // xParameter - additional configure value, depends the mode of timer // tBool - if true then enable timer right away // Output: none // ------------------------------------------------------------------------*/ void Timer_Init ( Timer_T timer, Timer_Config config, unsigned long xParameter, tBoolean enable ) { unsigned long timer_base, timer_config; // only turn on system control for the same timer once if ( !(TIMER_ON(timer/2)) ) { SysCtlPeripheralEnable ( Timer_Periph[timer] ); TIMER_POWER_ON ( timer/2 ); } // disable timer before configure TimerDisable ( Timer_Base[timer], get_half_timer(timer) ); // determine what user want this timer to do switch ( config ) { case Timer_CCP: { if ( timer >= NUM_CCP ) { // return if the timer does not associate with a CCP pin return; } // initialize CCP pin GPIO_Init ( CCP_Port[timer], CCP_Pin[timer], 0, 0, CCP ); // initialize Timer if ( timer % 2 ) { // timer B, 16bit capture TimerConfigure ( Timer_Base[timer], TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_ONE_SHOT | TIMER_CFG_B_CAP_TIME ); TimerControlEvent ( Timer_Base[timer], TIMER_B, xParameter); Timer_IntFlag[timer] = TIMER_CAPB_EVENT; } else { // timer A, 16bit capture TimerConfigure ( Timer_Base[timer], TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_ONE_SHOT | TIMER_CFG_A_CAP_TIME ); TimerControlEvent ( Timer_Base[timer], TIMER_A, xParameter); Timer_IntFlag[timer] = TIMER_CAPA_EVENT; } break; } case Timer_PWM: { break; } case Timer_Periodic: { break; } case Timer_OneTime: { break; } default: { break; } } if ( enable ) { TimerEnable ( Timer_Base[timer], get_half_timer(timer) ); } }
int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);//1024hz = 15625 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6); GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_3); GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); GPIOPinConfigure(GPIO_PB1_U1TX); GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_1); UARTConfigSetExpClk(b1, SysCtlClockGet(), 9600, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE); UARTEnable(b1); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, (GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_1)); GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); frequency = SysCtlClockGet()/2; changeCursorUnderscore(); toggleLED(); //Clear Display clearDisplay(); //putPhrase("Hello World!"); //Timer Configuration TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); TimerLoadSet(TIMER0_BASE, TIMER_A, frequency); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); TimerEnable(TIMER0_BASE, TIMER_A); //Timer Interrupt Enable TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerIntRegister(TIMER0_BASE, TIMER_A, timer_interrupt); while(1){ if(flag = 1){ //Reset the line read code = 0; //Turn on the scan for a line if(counter == 0) GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3, 0x8); if(counter == 1) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4, 0x10); if(counter == 2) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, 0x20); if(counter == 3) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0x40); //Check which button on the line was pressed if(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_5) == 0x20) { code = 1; temp = log_code; } if(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_6) == 0x40) { code = 2; temp = log_code; } if(GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_7) == 0x80) { code = 3; temp = log_code; } //Turn off the scan for a line if(counter == 0) GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3, 0x0); if(counter == 1) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4, 0x0); if(counter == 2) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, 0x0); if(counter == 3) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0x0); //Check the next line on the next run and if overflows, reset //Calculate the index_code for the lookup table index_code = temp + code; key_char = lookup_table[index_code]; log_code = log_code + 4; if(log_code > 12){ log_code = 0; } counter++; if(counter > 3) counter = 0; if(key_char != 'x'){ //toggleLED(); putChar(key_char); //SysCtlDelay(100000); index_code = 0; } flag = 0; } } }