コード例 #1
0
ファイル: touch.c プロジェクト: Rommelius/ENB350-Assignment1
//*****************************************************************************
//
//! Initializes the touch screen driver.
//!
//! \param ui32SysClock is the frequency of the system clock.
//!
//! This function initializes the touch screen driver, beginning the process of
//! reading from the touch screen.  This driver uses the following hardware
//! resources:
//!
//! - ADC 0 sample sequence 3
//! - Timer 5 subtimer B
//!
//! \return None.
//
//*****************************************************************************
void
TouchScreenInit(uint32_t ui32SysClock)
{
    //
    // Set the initial state of the touch screen driver's state machine.
    //
    g_ui32TSState = TS_STATE_INIT;

    //
    // There is no touch screen handler initially.
    //
    g_pfnTSHandler = 0;

    //
    // Enable the peripherals used by the touch screen interface.
    //
   SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
   SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5);

    //
    // Configure the ADC sample sequence used to read the touch screen reading.
    //
   ADCHardwareOversampleConfigure(ADC0_BASE, 4);
   ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
   ADCSequenceStepConfigure(ADC0_BASE, 3, 0,
                                 TS_YP_ADC | ADC_CTL_END | ADC_CTL_IE);
   ADCSequenceEnable(ADC0_BASE, 3);

    //
    // Enable the ADC sample sequence interrupt.
    //
   ADCIntEnable(ADC0_BASE, 3);
   IntEnable(INT_ADC0SS3);

    //
    // Configure the timer to trigger the sampling of the touch screen
    // every 2.5 milliseconds.
    //
    if((HWREG(TIMER5_BASE + TIMER_O_CTL) & TIMER_CTL_TAEN) == 0)
    {
       TimerConfigure(TIMER5_BASE, (TIMER_CFG_SPLIT_PAIR |
                                         TIMER_CFG_A_PWM |
                                         TIMER_CFG_B_PERIODIC));
    }
   TimerPrescaleSet(TIMER5_BASE, TIMER_B, 255);
   TimerLoadSet(TIMER5_BASE, TIMER_B, ((ui32SysClock / 256) / 400) - 1);
    TimerControlTrigger(TIMER5_BASE, TIMER_B, true);

    //
    // Enable the timer.  At this point, the touch screen state machine will
    // sample and run every 2.5 ms.
    //
   TimerEnable(TIMER5_BASE, TIMER_B);
}
コード例 #2
0
void CapacitorTask(void* pvParameter)
{
	unsigned long ulValue=0;
	int i=0;

	cqueue = xQueueCreate(100,sizeof(unsigned long));


	//SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_1);
	GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_OD);
	GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x02);//Setting the Pin 0 to "high"

	//Initialize the ADC using functions from the Stellaris API
	//SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	ADCSequenceConfigure(ADC_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_IE|ADC_CTL_END|ADC_CTL_CH1);
	ADCSequenceEnable(ADC0_BASE, 1);
	//ADCIntEnable(ADC0_BASE, 1);
	ADCIntClear(ADC0_BASE, 1);

	//Trigger from the Processor
	while(true)
	{

		if(flagcap==1)
		{
			GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x00);//Setting the Pin 0 to "high"
			vTaskDelay(TICK_R*0.5);
			GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x02);//Setting the Pin 0 to "high"
			i=0;
			flagcap = 0;
			//ADCIntClear(ADC0_BASE, 1);
			while(i<100)
			{
				ADCProcessorTrigger(ADC0_BASE, 1);
				while(!ADCIntStatus(ADC0_BASE, 1, false))
				{
				}
				ADCSequenceDataGet(ADC0_BASE, 1, &ulValue);//Enable ADC sequence 0
				ADCIntClear(ADC0_BASE, 1);
				xQueueSend(cqueue, &ulValue, 0);
				i++;
				vTaskDelay(TICK_R*1.0)
;			}
			flagUART = 1;

		}
		vTaskDelay(TICK_R*10);
	}

}
コード例 #3
0
ファイル: Base.c プロジェクト: ilabmp/micro
void Init_ADC() {

	/**** ADC0 ***/
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);
	SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);
	ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0);
	ADCSequenceEnable(ADC_BASE, 0);
	ADCProcessorTrigger(ADC_BASE, 0);
	//값읽기
	ADCProcessorTrigger(ADC_BASE, 0);
	while (!ADCIntStatus(ADC_BASE, 0, false))
		;
	ADCSequenceDataGet(ADC_BASE, 0, &ADC_resultValue0);


	/**** ADC1 ***/
	ADCSequenceConfigure(ADC_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceStepConfigure(ADC_BASE, 1, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH1);
	ADCSequenceEnable(ADC_BASE, 1);
	ADCProcessorTrigger(ADC_BASE, 1);
	//값 읽기
	ADCProcessorTrigger(ADC_BASE, 1);
	while (!ADCIntStatus(ADC_BASE, 1, false))
		;
	ADCSequenceDataGet(ADC_BASE, 1, &ADC_resultValue1);

	/**** ADC2 ***/
	ADCSequenceConfigure(ADC_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceStepConfigure(ADC_BASE, 2, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH2);
	ADCSequenceEnable(ADC_BASE, 2);
	ADCProcessorTrigger(ADC_BASE, 2);
	//값 읽기
	ADCProcessorTrigger(ADC_BASE, 2);
	while (!ADCIntStatus(ADC_BASE, 2, false))
		;
	ADCSequenceDataGet(ADC_BASE, 2, &ADC_resultValue2);

}
コード例 #4
0
ファイル: turret.c プロジェクト: ARENIBDelta/2013_robot
void adc_init(void) {
	unsigned char i;
	for (i=ROLLING_VALUES_COUNT; i--;) {
		rolling_values[i] = 0;
	}

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_5);
    GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ADCSequenceDisable(ADC0_BASE, 0);

    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH11);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH10 | ADC_CTL_IE | ADC_CTL_END);

    ADCSequenceEnable(ADC0_BASE, 0);
    ADCIntEnable(ADC0_BASE, 0);
    ADCIntClear(ADC0_BASE, 0);
    IntEnable(ADC_INT_SS0);
}
コード例 #5
0
ファイル: main.c プロジェクト: BooRan/Auto_Water_TM4
/*****************************************************
 * 	Function: init_IntTempSensor
 *	Description: Initializes internal temperature
 *			sensor and general timer 1
 *			Uses ADC0 Module and TIMER1
 *	Input: NONE
 *	Output: NONE
 *****************************************************/
void init_IntTempSensor(void)
{
	// Enable clock to ADC0
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

	// Configure hardware over-sampling to take 64 samples per step
	// With 4 steps on 64 samples -> 256 samples
	ADCHardwareOversampleConfigure(ADC0_BASE, 64);

	// Configure sequence to trigger on processor trigger
	ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);

	// Configure steps 0-3 to read internal temperature sensor
	// Configure step 3 to end conversion
	ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);

	// Enable sequence
	ADCSequenceEnable(ADC0_BASE, 0);
}
コード例 #6
0
void init_7017(void) {
    adc_mutex = xSemaphoreCreateMutex();
    if (adc_mutex == NULL) {
        return;
    }        

    SysCtlPeripheralEnable(MODULE_ADC_PERIPH);

    MODULE_CONFIG_GPIO();

    ADCSequenceDisable(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM);
    ADCSequenceConfigure(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM, ADC_TRIGGER_PROCESSOR, 0);

    ADCSequenceStepConfigure(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM, 0, MODULE_ADC_SEQUENCE_1_CONFIG);
    ADCSequenceStepConfigure(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM, 1, MODULE_ADC_SEQUENCE_1_CONFIG);
    ADCIntRegister(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM, ADCIntHandler);
    
    ADCIntEnable(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM);
    ADCSequenceEnable(ADC_BASE, MODULE_ADC_SEQUENCE_NUM);
    ADCIntClear(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM);

    ADCProcessorTrigger(MODULE_ADC_BASE, MODULE_ADC_SEQUENCE_NUM);
}
コード例 #7
0
ファイル: main.c プロジェクト: FTGStudio/Sound-Visualizer
void InitializeADC()
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);	//Enable the clock to the ADC module
	ADCSequenceDisable(ADC0_BASE, 3);			//Disable Sequence 3 in order to safely configure ADC

	//Configure Sequence 3: processor trigger, priority=0
	ADCSequenceConfigure(ADC_BASE, 3, ADC_TRIGGER_TIMER, 0);

	//Configure Sequence 3, step 0, analog input 0 | interrupt | end of sequence
	ADCSequenceStepConfigure(ADC_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);

	ADCSequenceEnable(ADC0_BASE, 3);	//Enable sequence 3 and it's interrupt
	ADCIntEnable(ADC0_BASE, 3);			//Enable interrupt
}
コード例 #8
0
/**
Reads the current sense amplifier output using the Analog to Digital Converter (ADC).
Current sense resistor is 0.2 ohms, amplifier multiplies voltage drop by 50. Therefore, every mA of
current translates into 10mV measured by the microcontroller
@note Current sense input is on PE5 on Stellaris LaunchPad
@pre Current sense shunt is installed on the BoosterPack
@return Current in mA multiplied by 10 (e.g. return value of 713 = 71.3mA)
@see StellarisWare/examples/peripherals/adc/single_ended.c
*/
uint16_t getCurrentSensor()
{
    /* This array is used for storing the data read from the ADC FIFO. It must be as large as the
    FIFO for the sequencer in use.  This example uses sequence 3 which has a FIFO depth of 1. */
	uint32_t ulADC0_Value[1];

    /* Enable sample sequence 3 with a processor signal trigger.  Sequence 3 will do a single sample
    when the processor sends a signal to start the conversion. */
    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

    /* Configure step 0 on sequence 3.  Sample channel 8 (ADC_CTL_CH8) in single-ended mode
     * (default) and configure the interrupt flag (ADC_CTL_IE) to be set when the sample is done.
     * Tell the ADC logic that this is the last conversion on sequence 3 (ADC_CTL_END). */
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);

    // Since sample sequence 3 is now configured, it must be enabled.
    ADCSequenceEnable(ADC0_BASE, 3);

    // Clear the interrupt status flag.  This is done to make sure the
    // interrupt flag is cleared before we sample.
    ADCIntClear(ADC0_BASE, 3);

    //
    // Now the setup is done, let's actually measure something!
    //

    // Trigger the ADC conversion.
    ADCProcessorTrigger(ADC0_BASE, 3);

    // Wait for conversion to be completed.
    while(!ADCIntStatus(ADC0_BASE, 3, false))
    {
    }

    // Clear the ADC interrupt flag.
    ADCIntClear(ADC0_BASE, 3);

    // Read ADC Value into ulADC0_Value
    ADCSequenceDataGet(ADC0_BASE, 3, ulADC0_Value);

    // This part does not have a separate voltage reference
    // Therefore we have to measure with reference to what we think VCC is, 3.30V
#define REFERENCE_VOLTAGE_MV                (3300l)

    uint32_t temp = (ulADC0_Value[0] * REFERENCE_VOLTAGE_MV);

#define NUMBER_OF_STEPS_12_BIT_RESOLUTION   (4096l)

    return ((uint16_t) (temp / NUMBER_OF_STEPS_12_BIT_RESOLUTION));
}
コード例 #9
0
ファイル: adc.c プロジェクト: joshthornton/ENGG4810
void adc_init(void)
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

	TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);

	//Set what the timer runs to
	TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() / FREQ );

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);

	ADCSequenceDisable(ADC0_BASE, 1);
	ADCSequenceConfigure(ADC_BASE, 1, ADC_TRIGGER_TIMER, 0);

	ADCSequenceStepConfigure(ADC_BASE, 1, 0, ADC_CTL_CH0);
	ADCSequenceStepConfigure(ADC_BASE, 1, 1, ADC_CTL_CH1);
	ADCSequenceStepConfigure(ADC_BASE, 1, 2, ADC_CTL_CH2);
	ADCSequenceStepConfigure(ADC_BASE, 1, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

	ADCSequenceEnable(ADC0_BASE, 1);
	ADCIntEnable(ADC0_BASE, 1);

	TimerEnable(TIMER1_BASE, TIMER_A);

	//Set timer 1A to trigger the ADC
	TimerControlTrigger(TIMER1_BASE, TIMER_A, 1);

	//May be useful:
	//SysCtlADCSpeedGet();

	ADCIntClear(ADC0_BASE, 1);
	ADCIntEnable(ADC0_BASE, 1);
	IntEnable(INT_ADC0SS1);
}
コード例 #10
0
ファイル: joy.c プロジェクト: SLongofono/Classwork-Resume
void joyTask(void *pvParameters) {

	//initialize queues for communication and user feedback
	dataBuffer = xQueueCreate(5, sizeof(unsigned long));
	feedBack = xQueueCreate(5, sizeof(unsigned long));

	//Enable ADC peripheral for joystick (left and right only)
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

	//Set ADC to trigger from software, high priority
	ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);

	//configure adc to have an interrupt, to throw it at the end of the step sequence
	ADCSequenceStepConfigure(ADC0_BASE, 0, 0,(ADC_CTL_END|ADC_CTL_CH0|ADC_CTL_IE));

	//Enable the configured sequence
	ADCSequenceEnable(ADC0_BASE, 0);

	//clear the interrupt
	ADCIntClear(ADC0_BASE, 0);


	//temporary variable to catch adc vals, since queue docs are full of lies
	unsigned long temp;

	while(true) {
		// Trigger the sample sequence.
		ADCProcessorTrigger(ADC0_BASE, 0);

		// Block until the sampling completes (fcn returns 0 until interrupt is thrown)
		while(!ADCIntStatus(ADC0_BASE, 0, false)){}

		// Read the value from the ADC into a temporary var
		ADCSequenceDataGet(ADC0_BASE, 0, &temp);

		//clear the interrupt
		ADCIntClear(ADC0_BASE, 0);

		//write temp value to queue
		xQueueSend(dataBuffer, (void*) &temp, 0);

		//send ADC value to the OLDE for display
		xQueueSend(feedBack, (void*) &temp, 0);


		//return control to Task scheduler
        vTaskDelay(100*ONE_MS);
	}
}
コード例 #11
0
ファイル: setADC.c プロジェクト: BetteLars/EAL_Embedded
void initADC()
{

	//
	// Enable the clock to the ADC module
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);

	//
	// Enable the first sample sequencer to capture the value of channel 0 when
	// the processor trigger occurs.
	//
	ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceStepConfigure(ADC0_BASE, 0, 0,ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH1);
	ADCSequenceEnable(ADC0_BASE, 0);
}
コード例 #12
0
ファイル: main.c プロジェクト: glocklueng/proditronicproject
static void prvSetupHardware( void )
{
	/* Setup the PLL. */
	SysCtlClockSet( SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ );
	
	/* Initialise the hardware used to talk to the LCD, LED's and UART. */
	PDCInit();
	vParTestInitialise();
	vSerialInit();

	/* The ADC is used to read the light sensor. */
	SysCtlPeripheralEnable( SYSCTL_PERIPH_ADC );
    ADCSequenceConfigure( ADC_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure( ADC_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_END );
    ADCSequenceEnable( ADC_BASE, 0 );

}
コード例 #13
0
ファイル: ADC.c プロジェクト: tach4455/EE345M
int ADC_Collect(unsigned int channelNum, unsigned int fs, 
  void (*task)(unsigned short)){

  unsigned long config;

  ADCTask = task;

  // Determine input channel
  switch(channelNum){
    case 0: config = ADC_CTL_CH0; break;
	case 1: config = ADC_CTL_CH1; break;
	case 2: config = ADC_CTL_CH2; break;
	case 3: config = ADC_CTL_CH3; break;
  }

  ADCSequenceDisable(ADC0_BASE, 0);

  // Enable the ADC0 for interrupt Sequence 0 with lower priority then single shot
  ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 1);

  // Configuring steps of sequence, last step contains ADC_CTL_END and ADC_CTL_IE config paramter
  config |= ADC_CTL_END | ADC_CTL_IE;
  ADCSequenceStepConfigure(ADC0_BASE, 0, 0, config);

  // Disabling Timer0A for configuration
  TimerDisable(TIMER0_BASE, TIMER_A);

  // Configure as 16 bit timer and trigger ADC conversion
  TimerControlTrigger(TIMER0_BASE, TIMER_A, true);

  TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/ fs);
  TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

  ADCSequenceOverflowClear(ADC0_BASE, 0);
  ADCSequenceUnderflowClear(ADC0_BASE, 0);
  ADCIntClear(ADC0_BASE, 0);
  ADCSequenceEnable(ADC0_BASE, 0);
 
  TimerEnable(TIMER0_BASE, TIMER_A);
  TimerIntEnable(TIMER0_BASE, TIMER_A);
  ADCIntEnable(ADC0_BASE, 0);

  IntEnable(INT_ADC0SS0);
  
  return 1; 
}
コード例 #14
0
ファイル: main.c プロジェクト: dealsndime/CS684--2016
//---------------------------------------------------------------------------
// hardware_init()
//
// inits GPIO pins for toggling the LED
//---------------------------------------------------------------------------
void hardware_init(void)
{

	//Set CPU Clock to 40MHz. 400MHz PLL/2 = 200 DIV 5 = 40MHz
	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

	GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0);            // Configuring PD0 as ADC input (channel 1)     CH7 ADC0
	GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_1);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);

	ADCSequenceConfigure(ADC0_BASE,	1, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceConfigure(ADC1_BASE,	1, ADC_TRIGGER_PROCESSOR, 0);

	ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH7);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH7);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH7);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH7 | ADC_CTL_IE | ADC_CTL_END);

	ADCSequenceStepConfigure(ADC1_BASE, 1, 0, ADC_CTL_CH6);
	ADCSequenceStepConfigure(ADC1_BASE, 1, 1, ADC_CTL_CH6);
	ADCSequenceStepConfigure(ADC1_BASE, 1, 2, ADC_CTL_CH6);
	ADCSequenceStepConfigure(ADC1_BASE, 1, 3, ADC_CTL_CH6 | ADC_CTL_IE | ADC_CTL_END);

	ADCSequenceEnable(ADC0_BASE, 1);
	ADCSequenceEnable(ADC1_BASE, 1);
	ADCIntClear(ADC0_BASE, 1);
	ADCIntClear(ADC1_BASE, 1);

	/* Configure Buzzer pin as output */
	 GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4);
	 GPIODirModeSet(GPIO_PORTC_BASE,GPIO_PIN_4,GPIO_DIR_MODE_OUT);
	/* Send a high output on buzzer to turn it off(inverted logic, refer
	schematic) */
	GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,0x10);

}
コード例 #15
0
ファイル: measure.c プロジェクト: ellingjp/ee472
void initializeMeasureTask() {
#if DEBUG
  RIT128x96x4Init(1000000);
#endif
  // Load data memory
  data.temperatureRaw = &(global.temperatureRaw);
  data.systolicPressRaw = &(global.systolicPressRaw);
  data.diastolicPressRaw = &(global.diastolicPressRaw);
  data.pulseRateRaw = &(global.pulseRateRaw);
  data.measureSelect = &(global.measurementSelection);
  
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS);
	//setup for temperature sensor
        ADCSequenceDisable(ADC0_BASE, 1);
	ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 1);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_TS);
        ADCSequenceEnable(ADC0_BASE, 1);

  /* Interrupt setup
   * Note: using statically registered interrupts, because they're faster
   *       this means we aren't using the dynamic GPIOPortIntRegister() function,
   *       instead, an entry in the interrupt table is populated with the address
   *       of the interrupt handler (under GPIO Port A) and this is enabled with
   *       IntEnable(INT_GPIOA) */

  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

  // Set PA4 as input
  GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_4);
  
  // Enable interrupts on PA4
  GPIOPinIntEnable(GPIO_PORTA_BASE, GPIO_PIN_4);

  // Set interrupt type
  GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_4, GPIO_RISING_EDGE);
 
  // Enable interrupts to the processor.
  IntMasterEnable();

  // Enable the interrupts.
  IntEnable(INT_GPIOA);
}
コード例 #16
0
ファイル: ming.c プロジェクト: ilabmp/micro
int main(void) {

	/*SysCtlClockSet(
	 SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN
	 | SYSCTL_XTAL_8MHZ);*/
	SysCtlClockSet(
			SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN
					| SYSCTL_XTAL_8MHZ); //20MHz
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
//	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
	GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_0);
	Init_Timer_a();
	Init_Timer_b();
	Init_PWM();
	unsigned long ulValue;
	//
	// Enable the first sample sequence to capture the value of channel 0 when
	// the processor trigger occurs.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); //Will use ADC
	ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceStepConfigure(ADC_BASE, 0, 0,
			ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0);
	ADCSequenceEnable(ADC_BASE, 0);
	SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);
	//
	// Trigger the sample sequence.
	//
	ADCProcessorTrigger(ADC_BASE, 0);
	//
	// Wait until the sample sequence has completed.
	//
	while (!ADCIntStatus(ADC_BASE, 0, false)) {
	}
	//
	// Read the value from the ADC.
	//
	ADCSequenceDataGet(ADC_BASE, 0, &ulValue);
	while (1) {
	}

}
コード例 #17
0
ファイル: adc.c プロジェクト: itismattei/controlPid
void initHW_ADC(){

	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
//SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	ADCReferenceSet(ADC0_BASE, ADC_REF_INT); //Set reference to the internal reference ,You can set it to 1V or 3 V
//ADCReferenceSet(ADC1_BASE, ADC_REF_INT);
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); //Ain0
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2); //Ain1
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1); //Ain2
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0); //Ain3
	GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_3); //Ain4
	/// imposta il sequencer 0, che ha 8 letture
	ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);

	//i sensori vengono numerati da quello davanti in senso antiorario

	ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
	/// PE.2
	ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);

	// PE.1
	ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2 );
	//GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0); //Ain3
	// PE.0
	ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3 );
	/// PD.3
	ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH4 );
	/// PD.2
	ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END);
	/// abilita il sequencer 0
	ADCSequenceEnable(ADC0_BASE, 0);

	/// messaggio di benvenuto
	PRINTF("Ciao: stai provando il converntitore AD!\n");

	/// abilta l'interruzione del sequencer 0
	ADCIntClear(ADC0_BASE, 0);
    //
    // Enable the ADC interrupt.
    //
    IntEnable(INT_ADC0SS0);
    ADCIntEnable(ADC0_BASE, 0);
    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

}
コード例 #18
0
void tempSensInit() {
	SysCtlPeripheralEnable(TEMP_SENS_ADC_PERIPH) ;
	SysCtlDelay(3) ;

	ADCSequenceConfigure(
			TEMP_SENS_ADC_BASE,
			TEMP_SENS_SEQ_NUM,
			ADC_TRIGGER_PROCESSOR,	// triggered by mcu
			3 ) ; 					// 3 - The lowest priority

	ADCSequenceStepConfigure(
			TEMP_SENS_ADC_BASE,
			TEMP_SENS_SEQ_NUM,
			TEMP_SENS_STEP_NUM,
			ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END) ;
	// Temperature sensor | interrupt enable | only one step

	ADCSequenceEnable(TEMP_SENS_ADC_BASE, TEMP_SENS_SEQ_NUM) ;
	ADCIntClear(TEMP_SENS_ADC_BASE, TEMP_SENS_SEQ_NUM) ;
}
コード例 #19
0
ファイル: main.c プロジェクト: anshuman94/StarShipXP
int main(void)
{

    SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_5);
    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH11 | ADC_CTL_IE | ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 3);
    ADCIntClear(ADC0_BASE, 3);

    while(1)
    {
        ADCProcessorTrigger(ADC0_BASE, 3);
        while(!ADCIntStatus(ADC0_BASE, 3, false));
        ADCIntClear(ADC0_BASE, 3);
        ADCSequenceDataGet(ADC0_BASE, 3, adcValue);
        SysCtlDelay(SysCtlClockGet() / 12);
    }
}
コード例 #20
0
int main(void)
{
	uint32_t ui32ADC0Value[1];
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceStepConfigure(ADC0_BASE,3,0,ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
	ADCSequenceEnable(ADC0_BASE, 3);
	while(1)
	{
		ADCIntClear(ADC0_BASE, 3);
		ADCProcessorTrigger(ADC0_BASE, 3);
		while(!ADCIntStatus(ADC0_BASE, 3, false))
		{
		}
		ADCSequenceDataGet(ADC0_BASE, 3, ui32ADC0Value);
		Temp = ui32ADC0Value[0] ;

	}
}
コード例 #21
0
ファイル: shockmon.c プロジェクト: ceezeh/RTOS_EX2
/****************************************************************
 * This function should be called first in AcquireRun.
 * It starts the ADC interrupt to detect the beginning of data logging
 * which is when the voltage exceeds a changeable threshold or
 * the accelerometer z-axis changes g by more than 0.5. The trigger
 * to look out for depends on the user's selection. The interrupt is
 * called every 100ms.
 ****************************************************************/
void ADC1AcquireStart() {

	//
	// Enable sample sequence 3 with a timer trigger.  Sequence 3
	// will do a single sample when the processor sends a signal to start the
	// conversion.  Each ADC module has 4 programmable sequences, sequence 0
	// to sequence 3.
	//
	ADCSequenceConfigure(ADC1_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

	//
	// Configure step 0 on sequence 3.  Sample channel 0 (ADC_CTL_CH0) in
	// single-ended mode (default) and configure the interrupt flag
	// (ADC_CTL_IE) to be set when the sample is done.  Tell the ADC logic
	// that this is the last conversion on sequence 3 (ADC_CTL_END).  Sequence
	// 3 has only one programmable step.  Sequence 1 and 2 have 4 steps, and
	// sequence 0 has 8 programmable steps.  Since we are only doing a single
	// conversion using sequence 3 we will only configure step 0.  For more
	// information on the ADC sequences and steps, reference the datasheet.
	//

	ADCSequenceStepConfigure(ADC1_BASE, 3, 0, ADC_CTL_CH21 |ADC_CTL_IE|
			ADC_CTL_END);
	//
	// Since sample sequence 3 is now configured, it must be enabled.
	//
	ADCSequenceEnable(ADC1_BASE, 3);

	//
	// Clear the interrupt status flag.  This is done to make sure the
	// interrupt flag is cleared before we sample.
	//
	ADCIntClear(ADC1_BASE, 3);
	// Enable the interrupt after calibration.
//	ADCIntEnable(ADC1_BASE, 3);
}
コード例 #22
0
ファイル: touch.c プロジェクト: hitubaldaniya/lumweb
//*****************************************************************************
//
//! Initializes the touch screen driver.
//!
//! This function initializes the touch screen driver, beginning the process of
//! reading from the touch screen.  This driver uses the following hardware
//! resources:
//!
//! - ADC sample sequence 3
//! - Timer 1 subtimer A
//!
//! \return None.
//
//*****************************************************************************
void
TouchScreenInit(void)
{
    //
    // Set the initial state of the touch screen driver's state machine.
    //
    g_ulTSState = TS_STATE_INIT;

    //
    // Determine which calibration parameter set we will be using.
    //
    g_plParmSet = g_lTouchParameters[SET_NORMAL];

    //
    // There is no touch screen handler initially.
    //
    g_pfnTSHandler = 0;

    //
    // Enable the peripherals used by the touch screen interface.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlPeripheralEnable(TS_P_PERIPH);
    SysCtlPeripheralEnable(TS_N_PERIPH);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    //
    // Configure the ADC sample sequence used to read the touch screen reading.
    //
    ADCHardwareOversampleConfigure(ADC0_BASE, 4);
    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0,
                             ADC_CTL_CH_YP | ADC_CTL_END | ADC_CTL_IE);
    ADCSequenceEnable(ADC0_BASE, 3);

    //
    // Enable the ADC sample sequence interrupt.
    //
    ADCIntEnable(ADC0_BASE, 3);
    IntEnable(INT_ADC3);

    //
    // Configure the GPIOs used to drive the touch screen layers.
    //
    GPIOPinTypeGPIOOutput(TS_P_BASE, TS_XP_PIN | TS_YP_PIN);

    //
    // If no daughter board is installed, set up GPIOs to drive the XN and YN
    // signals.
    //
    if(g_eDaughterType == DAUGHTER_NONE)
    {
        GPIOPinTypeGPIOOutput(TS_N_BASE, TS_XN_PIN | TS_YN_PIN);
    }

    GPIOPinWrite(TS_P_BASE, TS_XP_PIN | TS_YP_PIN, 0x00);
    if(g_eDaughterType == DAUGHTER_NONE)
    {
        GPIOPinWrite(TS_N_BASE, TS_XN_PIN | TS_YN_PIN, 0x00);
    }

    //
    // See if the ADC trigger timer has been configured, and configure it only
    // if it has not been configured yet.
    //
    if((HWREG(TIMER1_BASE + TIMER_O_CTL) & TIMER_CTL_TAEN) == 0)
    {
        //
        // Configure the timer to trigger the sampling of the touch screen
        // every millisecond.
        //
        TimerConfigure(TIMER1_BASE, (TIMER_CFG_16_BIT_PAIR |
                                     TIMER_CFG_A_PERIODIC |
                                     TIMER_CFG_B_PERIODIC));
        TimerLoadSet(TIMER1_BASE, TIMER_A, (SysCtlClockGet() / 1000) - 1);
        TimerControlTrigger(TIMER1_BASE, TIMER_A, true);

        //
        // Enable the timer.  At this point, the touch screen state machine
        // will sample and run once per millisecond.
        //
        TimerEnable(TIMER1_BASE, TIMER_A);
    }
}
コード例 #23
0
int main(void) {

	char *label = "Temperature: ";
	int i;
	int written = 0;

	uint32_t ui32ADC0Value[4]; 			// ADC FIFO
	volatile uint32_t ui32TempAvg; 		// Store average
	volatile uint32_t ui32TempValueC; 	// Temp in C
	uint32_t ui32TempValueF; 	// Temp in F

	SysCtlClockSet(
			SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN
					| SYSCTL_XTAL_16MHZ);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	// Set up UART
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //enable GPIO port for LED
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); //enable pin for LED PF2

	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
	/*
	 IntMasterEnable(); //enable processor interrupts
	 IntEnable(INT_UART0); //enable the UART interrupt
	 UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); //only enable RX and TX interrupts
	 */
	// Set up ADC module
	SysCtlPeripheralEnable( SYSCTL_PERIPH_ADC0); // enable the ADC0 peripheral
	ADCHardwareOversampleConfigure( ADC0_BASE, 64);	// hardware averaging (64 samples)

	// Configure ADC0 sequencer to use sample sequencer 2, and have the processor trigger the sequence.
	ADCSequenceConfigure( ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
	// Configure each step.
	ADCSequenceStepConfigure( ADC0_BASE, 2, 0, ADC_CTL_TS);
	ADCSequenceStepConfigure( ADC0_BASE, 2, 1, ADC_CTL_TS);
	ADCSequenceStepConfigure( ADC0_BASE, 2, 2, ADC_CTL_TS);
	// Sample temp sensor.
	ADCSequenceStepConfigure( ADC0_BASE, 2, 3,
			ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
	ADCSequenceEnable( ADC0_BASE, 2); // Enable ADC sequencer 2

	UARTCharPut(UART0_BASE, '\n');
	UARTCharPut(UART0_BASE, '\r');
	for (i = 0; label[i] != '\0'; i++) 	// Print prompt at start of program
		UARTCharPut(UART0_BASE, label[i]);
	UARTCharPut(UART0_BASE, ' ');

	while (1) //let interrupt handler do the UART echo function
	{
		ADCProcessorTrigger(ADC0_BASE, 2); 	// Trigger ADC conversion.

		while (!ADCIntStatus(ADC0_BASE, 2, false))
			; 	// wait for conversion to complete.

		ADCSequenceDataGet(ADC0_BASE, 2, ui32ADC0Value); // get converted data.
		// Average read values, and round.
		// Each Value in the array is the result of the mean of 64 samples.
		ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2]
				+ ui32ADC0Value[3] + 2) / 4;
		ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096) / 10; // calc temp in C
		ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;

		UARTdeleteLastEntry(written);
		written = UARTPrint_uint32_t(ui32TempValueF);
		UARTCharPut(UART0_BASE, 'F');
		written++;

		// LED logic
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED
		SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED
		SysCtlDelay(SysCtlClockGet());
	}
}
コード例 #24
0
ファイル: single_ended.c プロジェクト: ilemus/uCOS-II
//*****************************************************************************
//
// Configure ADC0 for a single-ended input and a single sample.  Once the
// sample is ready, an interrupt flag will be set.  Using a polling method,
// the data will be read then displayed on the console via UART0.
//
//*****************************************************************************
int
main(void)
{
    //
    // This array is used for storing the data read from the ADC FIFO. It
    // must be as large as the FIFO for the sequencer in use.  This example
    // uses sequence 3 which has a FIFO depth of 1.  If another sequence
    // was used with a deeper FIFO, then the array size must be changed.
    //
    uint32_t pui32ADC0Value[1];

    //
    // Set the clocking to run at 20 MHz (200 MHz / 10) using the PLL.  When
    // using the ADC, you must either use the PLL or supply a 16 MHz clock
    // source.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);

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

    //
    // Display the setup on the console.
    //
    UARTprintf("ADC ->\n");
    UARTprintf("  Type: Single Ended\n");
    UARTprintf("  Samples: One\n");
    UARTprintf("  Update Rate: 250ms\n");
    UARTprintf("  Input Pin: AIN0/PE7\n\n");

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

    //
    // For this example ADC0 is used with AIN0 on port E7.
    // The actual port and pins used may be different on your part, consult
    // the data sheet for more information.  GPIO port E needs to be enabled
    // so these pins can be used.
    // TODO: change this to whichever GPIO port you are using.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    //
    // Select the analog ADC function for these pins.
    // Consult the data sheet to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_7);

    //
    // Enable sample sequence 3 with a processor signal trigger.  Sequence 3
    // will do a single sample when the processor sends a signal to start the
    // conversion.  Each ADC module has 4 programmable sequences, sequence 0
    // to sequence 3.  This example is arbitrarily using sequence 3.
    //
    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

    //
    // Configure step 0 on sequence 3.  Sample channel 0 (ADC_CTL_CH0) in
    // single-ended mode (default) and configure the interrupt flag
    // (ADC_CTL_IE) to be set when the sample is done.  Tell the ADC logic
    // that this is the last conversion on sequence 3 (ADC_CTL_END).  Sequence
    // 3 has only one programmable step.  Sequence 1 and 2 have 4 steps, and
    // sequence 0 has 8 programmable steps.  Since we are only doing a single
    // conversion using sequence 3 we will only configure step 0.  For more
    // information on the ADC sequences and steps, reference the datasheet.
    //
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
                             ADC_CTL_END);

    //
    // Since sample sequence 3 is now configured, it must be enabled.
    //
    ADCSequenceEnable(ADC0_BASE, 3);

    //
    // Clear the interrupt status flag.  This is done to make sure the
    // interrupt flag is cleared before we sample.
    //
    ADCIntClear(ADC0_BASE, 3);

    //
    // Sample AIN0 forever.  Display the value on the console.
    //
    while(1)
    {
        //
        // Trigger the ADC conversion.
        //
        ADCProcessorTrigger(ADC0_BASE, 3);

        //
        // Wait for conversion to be completed.
        //
        while(!ADCIntStatus(ADC0_BASE, 3, false))
        {
        }

        //
        // Clear the ADC interrupt flag.
        //
        ADCIntClear(ADC0_BASE, 3);

        //
        // Read ADC Value.
        //
        ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);

        //
        // Display the AIN0 (PE7) digital value on the console.
        //
        UARTprintf("AIN0 = %4d\r", pui32ADC0Value[0]);

        //
        // This function provides a means of generating a constant length
        // delay.  The function delay (in cycles) = 3 * parameter.  Delay
        // 250ms arbitrarily.
        //
        SysCtlDelay(SysCtlClockGet() / 12);
    }
}
コード例 #25
0
ファイル: main.c プロジェクト: dibakarbarua/TIADC-2012-13
void alarmState(void)
{
    /* Enter accurate button OFF value here */
	
	
	while(temp[0] > 35)    //Till User Doesn't Press the button 
    {

    	UARTprintf("ALARM TRIGGERED\n");
     	for(i=0; i<=800000;i++)
    	{

     	/*Configure ADC Peripheral for READING THE BUTTON*/
     	
		/*Configure ADC Sequence*/
     	ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
     	/*Enable ADC sequence*/
     	ADCSequenceDisable(ADC0_BASE, 0);
     	SysCtlDelay(SysCtlClockGet()/10);
     	ADCSequenceEnable(ADC0_BASE, 0);


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

  		IntMasterEnable();

   		ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);

   	    ADCProcessorTrigger(ADC0_BASE, 0);
   	    while(!ADCIntStatus(ADC0_BASE, 0, false))
   	    {
        }
   	    ADCIntClear(ADC0_BASE, 0);

   	    ADCSequenceDataGet(ADC0_BASE, 0, temp);

        /*Check if button was pressed*/
		
     	if(temp[0] < 20) 
		{
			/*Debounce the button if it IS READ */
			for(i=0; i<=2000; i++)
			{
			}
            if(temp[0] > 20)		
				{
				break;
				}
		}
		
		/*If button is not pressed the initiate alarm sequence */

        GPIOPinWrite(relaycontrolbase, relaycontrolpin, relaycontrolpin);
    	for(i=0; i<=3; i++)
        {
        	 speakerplay();
        }

    	GPIOPinWrite(relaycontrolbase, relaycontrolpin, 0);

        /* Give a missed call using GPS*/
        
		//ENTER GSM MISSED CALL FUNCTION HERE
        
    	}

        SysCtlDelay(SysCtlClockGet());
        
		/*If the user doesnt PRESS the button */
		
		
        if(i == 800000)
        {

        UARTprintf("NO REACTION\n");
		delay(2000);
		UARTprintf("SYSTEM STALLED\n");
		
        SysCtlDelay(SysCtlClockGet()/5);

        /*Send message using GPS*/
        
		//ENTER FUNCTION FOR GSM MESSAGE HERE


         /*System will stall if driver was unable to push the safe button in stipulated time */
          while(1)
          {

        	  GPIOPinWrite(relaycontrolbase, relaycontrolpin, relaycontrolpin);
        	  for(i=0; i<=100; i++)
              {
      	          	 speakerplay();
  	          }
        	  GPIOPinWrite(relaycontrolbase, relaycontrolpin, 0);
          }

        }

        UARTprintf("ALARM\n");
		delay(2000);
		UARTprintf("ESCAPED\n");
		GPIOPinWrite(relaycontrolbase, relaycontrolpin, 0);
		
        SysCtlDelay(SysCtlClockGet()/2);

    }
}
コード例 #26
0
ファイル: main.c プロジェクト: dibakarbarua/TIADC-2012-13
int main(void)
{

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

    /* Set the clock for the GPIO Ports */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

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

	/* Set the type of the GPIO Pins required */
	GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); //initialiing the on-board LEDs as outputs
	GPIOPinTypeGPIOOutput(digital2base, digital2pin);
	GPIOPinTypeGPIOOutput(digital3base, digital3pin);
	GPIOPinTypeGPIOOutput(digital4base, digital4pin);
	GPIOPinTypeGPIOOutput(digital5base, digital5pin);
	GPIOPinTypeGPIOOutput(digital6base, digital6pin);
	GPIOPinTypeGPIOOutput(digital7base, digital7pin);
	GPIOPinTypeGPIOOutput(digital8base, digital8pin);
	GPIOPinTypeGPIOOutput(digital9base, digital9pin);
	GPIOPinTypeGPIOOutput(digital10base, digital10pin);
	GPIOPinTypeGPIOOutput(digital11base, digital11pin);
	GPIOPinTypeGPIOOutput(digital12base, digital12pin);
	
	/* Set the GPIO Pins for the LCD as output */
	
	GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4| GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7);

	/*Initialize digital control pins*/
	GPIOPinWrite(relaycontrolbase, relaycontrolpin, 0); //relay switch off inside main() function
	GPIOPinWrite(speakerbase, speakerpin, 0); //speaker off inside main() function

	/* UART config */
	InitConsole();
	
	/* Enable is set low */
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, 0);

    /* Set up the period for the SysTick timer.  The SysTick timer period will
    be equal to 1ms.*/
    SysTickPeriodSet(SysCtlClockGet()/1000);

    /* Enable SysTick. */
    SysTickEnable();

    ConfigureLCD();
	
	/*WELCOME SCREEN */

    UARTprintf("WELCOME\n");
    delay(2000);

	/*AUTO CALIBRATION OF ACCELEROMETER TO PRESENT STATE ON RESET */

	/*start of auto calibration */

	/*Configure ADC Peripheral*/
	/*Configure ADC Sequence*/
	ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
	/*Enable ADC sequence*/
	ADCSequenceDisable(ADC0_BASE, 0);
	SysCtlDelay(SysCtlClockGet()/10);
	ADCSequenceEnable(ADC0_BASE, 0);


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

	IntMasterEnable();

	ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH1);
	ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

    ADCProcessorTrigger(ADC0_BASE, 0);
    while(!ADCIntStatus(ADC0_BASE, 0, false))
    {
    }
    ADCIntClear(ADC0_BASE, 0);

    unsigned int i= 0;
    unsigned long sumx = 0;
    unsigned long sumz = 0;
    unsigned int xref = 0;
    unsigned int zref = 0;

    SysCtlDelay(SysCtlClockGet());

    for(i=0; i<= 100; i++)
    {

    SysCtlDelay(SysCtlClockGet()/50);
    ADCSequenceDataGet(ADC0_BASE, 0, temp);
    sumx = sumx + temp[1];
    sumz = sumz + temp[0];
    SysCtlDelay(SysCtlClockGet()/50);

    }

    xref = sumx/101;
    zref = sumz/101;

    UARTprintf("Xref = \n");
	UARTprintf(xref);
	delay(3000);
	
	UARTprintf("Yref = \n");
	UARTprintf(yref);
	delay(3000);
	
   /*end of auto calibration */

	/*Configure ADC Peripheral*/
	
	/*Configure ADC Sequence FOR READING JUST THE IR SENSOR*/
	ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_ALWAYS, 0); // 0 for taking 8 samples as 6 channels of ADC are involved

	/*Enable ADC sequence*/
	ADCSequenceDisable(ADC0_BASE, 0);
	SysCtlDelay(SysCtlClockGet()/10);
	ADCSequenceEnable(ADC0_BASE, 0);

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

	IntMasterEnable();

	/* sensors are monitored on an infinite loop */

	while(1)
	{

		/*Reinitiate blinkcounter*/
		blinkcounter = 0;

		/*Reading just IR sensor values in a loop */

		for(i=0; i<= 5; i++)
	    {

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

	    	/*Enable ADC sequence*/
	    	ADCSequenceDisable(ADC0_BASE, 0);
	   	    ADCSequenceEnable(ADC0_BASE, 0);

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

	        IntMasterEnable();

	        ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH4 | ADC_CTL_IE | ADC_CTL_END);

            ADCProcessorTrigger(ADC0_BASE, 0);

            while(!ADCIntStatus(ADC0_BASE, 0, false))
	  	    {
	   	    }

            ADCIntClear(ADC0_BASE, 0);

            ADCSequenceDataGet(ADC0_BASE, 0, temp);

	   	    if(temp[0] < 1000)
	   	    {
	   	    	 blinkcounter++;
	   	    }
	   	    
	   	    UARTprintf("IR value %04d\n", temp[0]);

	   	    SysCtlDelay(SysCtlClockGet()/5);

	    }

    /*Configure ADC Sample Collection from 4 Channels READ ALL OTHER SENSORS*/

    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0); //button

	ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1); //z axis

	ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH3); // x axis

	ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END); //alcohol

	//  For ADC Processor Triggering
    ADCProcessorTrigger(ADC0_BASE, 0);

    while(!ADCIntStatus(ADC0_BASE, 0, false))
    {
    }
    ADCIntClear(ADC0_BASE, 0);

    /*assign sensor values to sensor variables */
    alcoholsense = temp[3];
    xval = temp[2];
    zval = temp[1];
    butval = temp[0];

    UARTprintf("Xval =  %04d\n",xval);
	SysCtlDelay(SysCtlClockGet()/3);

	UARTprintf("Yval = %04d\n", yval);
	SysCtlDelay(SysCtlClockGet()/3);

	UARTprintf("AlcoholVal = %04d\n",alcoholsense);
	SysCtlDelay(SysCtlClockGet()/3);

	UARTprintf("ButtonVal %04d\n", butval);
	SysCtlDelay(SysCtlClockGet()/3);

    /*calculate instataneous deviaton from reference values for head tilting */
	
	deltax = abs(xref - xval);
    deltaz = abs(zref - zval);

    UARTprintf("Z DELTA = %04d\n", deltaz);
    SysCtlDelay(SysCtlClockGet()/3);
    
	
	UARTprintf("X DELTA = %04d\n", deltax);
    SysCtlDelay(SysCtlClockGet()/3);

//Check first for alcohol detection. Completely shutdown the system. Alarm will constantly ring.

	if(alcoholsense > 1000)
	{
		UARTprintf("Alcohol\n");
	    UARTprintf("Present\n");
		delay(1000);
		UARTprintf("Alarm\n");
	    UARTprintf("Triggered\n");
		SysCtlDelay(SysCtlClockGet()/2);
		alcoholdetected();
	}

//	Check for eyes being closed or blinking at a very fast rate or partially closed for long.

    if(blinkcounter >= 4)
    {

    	UARTprintf("Fatigued State");
		delay(2000);
		UARTprintf("Alarm Triggered");
		delay(1000);
    	SysCtlDelay(SysCtlClockGet()/2);
    	alarmState();

    }

    /*Check for accelerometer alert state*/

    /*Reinitiate accelerometer Counter */
    counter = 0;

    /*If one of the values in head position differs from auto calibrated values, re-sensing is done */

    if((deltax >= 70) || (deltaz >= 70))
    {
       	for(count = 0; count <= 10; count++)
       	{
                /*Configure ADC Sequence just for the accelerometer */ 
         		
		        ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
          	    /*Enable ADC sequence*/
           	    ADCSequenceDisable(ADC0_BASE, 0);
           	    SysCtlDelay(SysCtlClockGet()/10);
           	    ADCSequenceEnable(ADC0_BASE, 0);


           	   /*Clear ADC Interrupt*/
           	   ADCIntClear(ADC0_BASE, 0);
           	   IntMasterEnable();

           	   ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH1);

           	   ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

           	   ADCProcessorTrigger(ADC0_BASE, 0);
           	   while(!ADCIntStatus(ADC0_BASE, 0, false))
           	   {
               }
               ADCIntClear(ADC0_BASE, 0);

               ADCSequenceDataGet(ADC0_BASE, 0, temp);

               deltax = abs(xref - temp[1]);
               deltaz = abs(zref - temp[0]);

               if((deltax >= 70) || (deltaz >= 70))
               {
            	       counter++;
            	       SysCtlDelay(SysCtlClockGet()/5);
           	   }
          	}
    	}

        if (counter >= 7)
        {

            
            UARTprintf("Head Tilted");
			delay(2000);
			UARTprintf("ALARM Triggered");
			SysCtlDelay(SysCtlClockGet()/2);
            alarmState();

        }

        else
        {

        	UARTprintf("NO ALARM DETECTED");
			delay(1000);
            SysCtlDelay(SysCtlClockGet()/5);

        }

    }

    return 0;

}
コード例 #27
0
ファイル: lab4.c プロジェクト: CS308-2016/DrowsinessDetector
int main(void) {

	uint32_t ui32ADC0Value[4];

	ui32TempSet = 25;

	// Set System CLock
	SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	// Enaable UART
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	// Enable GPIO
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	// Enable ADC Peripheral
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

	//Allow the ADC12 to run at its default rate of 1Msps.
	ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);

	//our code will average all four samples of temperature sensor data	ta on sequencer 1 to calculate the temperature, so all four sequencer steps will measure the temperature sensor
	ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);

	//enable ADC sequencer 1.
	ADCSequenceEnable(ADC0_BASE, 1);

	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	IntMasterEnable();
	IntEnable(INT_UART0);
	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_3);

	// Set bit rate fr serial communication
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));



	while (1)
	{
		//indication that the ADC conversion process is complete
		ADCIntClear(ADC0_BASE, 1);
		//trigger the ADC conversion with software
		ADCProcessorTrigger(ADC0_BASE, 1);
		//wait for the conversion to complete
		while(!ADCIntStatus(ADC0_BASE, 1, false))
		{
		}
		//read the ADC value from the ADC Sample Sequencer 1 FIFO
		ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
		ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;


		ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
		ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;

		print_temp(ui32TempValueC);
		SysCtlDelay(SysCtlClockGet() / 3); //delay ~1 sec
		if(ui32TempValueC < ui32TempSet)
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 8);
		else
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2);
	}
}
コード例 #28
0
ファイル: main.c プロジェクト: ResearchDev-BMES/SonifiedMyo
//*****************************************************************************
// This example demonstrates MIDI functionality and control methods
//*****************************************************************************
int main(void){

    // Set the clocking to run directly from the crystal.
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    // Enable the peripherals used by this VS1053.
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);	// VS1053 Serial
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);	// VS1053 Serial
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);	// VS1053 Reset + EMG Input
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);		// EMG Input 1

	// Enable PC Console
	InitSerial();

    // Enable processor interrupts.
    IntMasterEnable();

	// Set GPIO B0 and B1 as UART pins for VS1053 Control
    GPIOPinConfigure(GPIO_PB0_U1RX);
	GPIOPinConfigure(GPIO_PB1_U1TX);
	GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	// Set GPIO E4 as Hardware Reset pin and E5 as ADC Input
	GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4);
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);

    // Configure the UART1 as according to VS1053 Datasheet with baudrate of 31250
	UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 31250, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    // Setup ADC Sampling Sequences 3, configure step 0.
    // Note: Sequence 1 and 2 has 4 step, which would be great for 3-channel sampling
    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 3);
    ADCIntClear(ADC0_BASE, 3);

    // Example Started
	UARTprintf("VS1053 Test\n");

	// Reset the VS1053
	VS1053_Reset();

	// Setup the MIDI Channel 0
	midiSetChannelBank(0, VS1053_BANK_MELODY);
	midiSetInstrument(0, VS1053_GM1_OCARINA);
	midiSetChannelVolume(0, 127);
	midiNoteOn(0, 70, 127);
	Delay(1000);

	// Setup the MIDI Channel 1
	midiSetChannelBank(1, VS1053_BANK_MELODY);
	midiSetInstrument(1, VS1053_GM1_OCARINA);
	midiSetChannelVolume(1, 0);
	midiNoteOn(1, 60, 127);

	// Setup variables for ADC
	uint32_t ADC_Output[1];
	uint8_t volume;

    // Infinite Loop of execution
    while(1)
    {

		// ADC Sampling Procedures
		ADCProcessorTrigger(ADC0_BASE, 3);
		while(!ADCIntStatus(ADC0_BASE, 3, false)) {}
		ADCIntClear(ADC0_BASE, 3);
		ADCSequenceDataGet(ADC0_BASE, 3, ADC_Output);
		UARTprintf("AIN8 = %4d\n", ADC_Output[0]);

		// Play Sound as according to voltage level
		volume = inputMapping(ADC_Output[0], 3000, 4000, 50, 127);
		midiSetChannelVolume(0, volume);
		UARTprintf("Volume Level = %4d\n", volume);

		// Delay
		Delay(100);

    }
}
コード例 #29
0
ファイル: main.c プロジェクト: anshuman94/TIVA-C-123G
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;
}
コード例 #30
0
ファイル: FinalVersion.c プロジェクト: mk3a/Geese-Invaders
void DeviceInit()   
{
  /*
   * First, Set Up the Clock.
   * Main OSC     -> SYSCTL_OSC_MAIN
   * Runs off 16MHz clock -> SYSCTL_XTAL_16MHZ
   * Use PLL      -> SYSCTL_USE_PLL
   * Divide by 4    -> SYSCTL_SYSDIV_4
   */
  SysCtlClockSet(SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ | SYSCTL_USE_PLL | SYSCTL_SYSDIV_4);

  /*
   * Enable and Power On All GPIO Ports
   */
  //SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOA | SYSCTL_PERIPH_GPIOB | SYSCTL_PERIPH_GPIOC |
  //            SYSCTL_PERIPH_GPIOD | SYSCTL_PERIPH_GPIOE | SYSCTL_PERIPH_GPIOF);

  SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOA );
  SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOB );
  SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOC );
  SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOD );
  SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOE );
  SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOF );
  /*
   * Pad Configure.. Setting as per the Button Pullups on
   * the Launch pad (active low).. changing to pulldowns for Orbit
   */
  GPIOPadConfigSet(SWTPort, SWT1 | SWT2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);

  GPIOPadConfigSet(BTN1Port, BTN1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);
  GPIOPadConfigSet(BTN2Port, BTN2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);

  GPIOPadConfigSet(LED1Port, LED1, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD);
  GPIOPadConfigSet(LED2Port, LED2, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD);
  GPIOPadConfigSet(LED3Port, LED3, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD);
  GPIOPadConfigSet(LED4Port, LED4, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD);

  /*
   * Initialize Switches as Input
   */
  GPIOPinTypeGPIOInput(SWTPort, SWT1 | SWT2);

  /*
   * Initialize Buttons as Input
   */
  GPIOPinTypeGPIOInput(BTN1Port, BTN1);
  GPIOPinTypeGPIOInput(BTN2Port, BTN2);

  /*
   * Initialize LEDs as Output
   */
  GPIOPinTypeGPIOOutput(LED1Port, LED1);
  GPIOPinTypeGPIOOutput(LED2Port, LED2);
  GPIOPinTypeGPIOOutput(LED3Port, LED3);
  GPIOPinTypeGPIOOutput(LED4Port, LED4);

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

  GPIOPinTypeADC(AINPort, AIN);

  /*
   * Enable ADC with this Sequence
   * 1. ADCSequenceConfigure()
   * 2. ADCSequenceStepConfigure()
   * 3. ADCSequenceEnable()
   * 4. ADCProcessorTrigger();
   * 5. Wait for sample sequence ADCIntStatus();
   * 6. Read From ADC
   */
  ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
  ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0);
  ADCSequenceEnable(ADC0_BASE, 0);

  /*
   * Initialize the OLED
   */
  OrbitOledInit();

  /*
   * Reset flags
   */
  chSwtCur = 0;
  chSwtPrev = 0;
  fClearOled = true;

}