Example #1
0
//*****************************************************************************
//
// Configure Timer0B as a 16-bit one-shot counter with a single interrupt
// after 1ms.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);

    //
    // The Timer0 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for Timer operation.
    //
    InitConsole();

    //
    // Display the example setup on the console.
    //
    UARTprintf("16-Bit Timer Interrupt ->");
    UARTprintf("\n   Timer = Timer0B");
    UARTprintf("\n   Mode = One Shot");
    UARTprintf("\n   Rate = 1ms");

    //
    // The Timer0 peripheral must be enabled for use.
    //
    TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT);

    //
    // Set the Timer0B load value to 1ms.
    //
    TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / 1000);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Configure the Timer0B interrupt for timer timeout.
    //
    TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);

    //
    // Enable the Timer0B interrupt on the processor (NVIC).
    //
    IntEnable(INT_TIMER0B);

    //
    // Enable Timer0B.
    //
    TimerEnable(TIMER0_BASE, TIMER_B);

    //
    // Wait for interrupt to occur
    //
    while(!g_bIntFlag)
    {
    }

    //
    // Display a message indicating that the one shot interrupt was received.
    //
    UARTprintf("\n\nOne shot timer interrupt received.");

    //
    // Loop forever.
    //
    while(1)
    {
    }
}
Example #2
0
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;
    }
  }

}
Example #3
0
int main(void)
{
	/* FIFO Buffer */
	unsigned long temp[1];

	/*Set the clocking to directly run from the crystal at 8MHz*/
	SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

	/*Enable ADC Peripheral*/
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

	//Enable Timers.
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

	/* Set the clock for the GPIO Port B */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	/* Set the type of the GPIO Pin */
	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_5);

	/* UART configuration */
	InitConsole();

	//Setting the timer for PWM
	TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM);
	TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);
	TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);

	/*Configure ADC Peripheral*/
	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

	/*Configure ADC Sequence*/
	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END);

	/*Enable ADC sequence*/
	ADCSequenceEnable(ADC0_BASE, 3);

	/*Clear ADC Interrupt*/
	ADCIntClear(ADC0_BASE, 3);

	IntMasterEnable();
    TimerLoadSet(TIMER2_BASE, TIMER_B, 500);
    TimerLoadSet(TIMER1_BASE, TIMER_A, 500);
    TimerLoadSet(TIMER0_BASE, TIMER_A, 500);


unsigned long i,k,counter=0,i1=0;

long num1,y=0,num2,num3,j=0,sum1=0,sum2=0,sum3=0;



 	while(1)
    {

		for(i=0;i<15648;i++)
		  {
             if(i%24 == 0)
             {
            	ADCProcessorTrigger(ADC0_BASE, 3);
				while(!ADCIntStatus(ADC0_BASE, 3, false))
				{
				}
	      ADCIntClear(ADC0_BASE, 3);
	      ADCSequenceDataGet(ADC0_BASE, 3, temp);
          x[i/24]=temp[0];
             }
		   }

		num1=0;
		num2=0;
		num3=0;
		n1=_IQ17(0);
		n2=_IQ17(0);
		n3=_IQ17(0);
		 for(k=0;k<652;k++)
			{
			 l1= _IQ17(b1[k]);
			 l2= _IQ17(b2[k]);
			 l3= _IQ17(b3[k]);
	    	  m= _IQ17(x[651-k]);
			 n1=n1 + _IQ17mpy(l1,m);
			 n2=n2 + _IQ17mpy(l2,m);
			 n3=n3 + _IQ17mpy(l3,m);
	         }
		 num1=_IQ17int(n1);
		 num2=_IQ17int(n2);
		 num3=_IQ17int(n3);
		 sum1+=num1*num1;
		 sum2+=num2*num2;
		 sum3+=num3*num3;
		 j++;

		 if(j==15)
		 {
			 sum1=sum1/500;
			 sum2=sum2/500;
			 sum3=sum3/500;
			 r1=isqrt(sum1);
		     r2=isqrt(sum2);
		     r3=isqrt(sum3);
			 sum1=sum2=0;
			 j=0;
		 }


        r01=r1*r1*r1;
        r02=r2*r2*r2;
        r03=r3*r3*r3;


        if(r01>0)
        	{
        	TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);
        	pwm1(256-r01);
        	}
        else
        	{
        	TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC);
        	}


        if(r02>0)
        	{
        	TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);
        	pwm2(256-r02);
        	}
        else
        	{
        	TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC);
        	}


        if(r03>0)
        	{
        	TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM);
            pwm3(256-r03);
        	}
        else
        	{
        	TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PERIODIC);
        	}

    }
}
Example #4
0
void joystick_init(void) {

    // Register Joystick button isr
    GPIOPinTypeGPIOInput(JOY_PORT, JOY_MASK);
    GPIOPadConfigSet(JOY_PORT, JOY_MASK, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOIntTypeSet(JOY_PORT, JOY_MASK, GPIO_BOTH_EDGES);
    GPIOPortIntRegister(JOY_PORT, button_handler);
    GPIOPinIntEnable(JOY_PORT, JOY_MASK);

    //
    // The ADC0 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

    //
    // Select the analog ADC function for these pins.
    //
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_3);

    // Use sequences 0 and 1 for x and y.
    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);

    // Single ended sample on CH3 (X) and CH4 (Y).
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH4 | ADC_CTL_IE | ADC_CTL_END);

    // Enable the sequences.
    ADCSequenceEnable(ADC0_BASE, 0);
    ADCSequenceEnable(ADC0_BASE, 1);

    // Register ISRs.
    ADCIntRegister(ADC0_BASE, 0, x_handler);
    ADCIntRegister(ADC0_BASE, 1, y_handler);
    ADCIntEnable(ADC0_BASE, 0);
    ADCIntEnable(ADC0_BASE, 1);

    // Trigger the first conversion (auto-center)
    ADCProcessorTrigger(ADC0_BASE, 0);
    ADCProcessorTrigger(ADC0_BASE, 1);

    // Configure timer
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
    TimerConfigure(JOY_TIMER, TIMER_CFG_PERIODIC);


    //Register Jog Z buttons
    GPIOPinTypeGPIOInput(JOG_Z_PORT, JOG_Z_MASK);
    GPIOIntTypeSet(JOG_Z_PORT, JOG_Z_MASK, GPIO_BOTH_EDGES);
    GPIOPortIntRegister(JOG_Z_PORT, jog_z_handler);
    GPIOPinIntEnable(JOG_Z_PORT, JOG_Z_MASK);
    GPIOPadConfigSet(JOG_Z_PORT,JOG_Z_MASK,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPD);

    // Create a 10ms timer callback
    TimerLoadSet64(JOY_TIMER, SysCtlClockGet() / 500);
    TimerIntRegister(JOY_TIMER, TIMER_A, joystick_isr);
    TimerIntEnable(JOY_TIMER, TIMER_TIMA_TIMEOUT);
    IntPrioritySet(INT_TIMER3A, CONFIG_JOY_PRIORITY);
    TimerEnable(JOY_TIMER, TIMER_A);
}