Ejemplo n.º 1
0
int main(void)
{

    SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_5);
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);

    ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH8);
    ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH11 | ADC_CTL_IE | ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 2);
    ADCIntClear(ADC0_BASE, 2);

    while(1)
    {
        ADCProcessorTrigger(ADC0_BASE, 2);
        while(!ADCIntStatus(ADC0_BASE, 2, false));
        ADCIntClear(ADC0_BASE, 2);
        ADCSequenceDataGet(ADC0_BASE, 2, adcValue);
        SysCtlDelay(SysCtlClockGet() / 12);
    }
}
Ejemplo n.º 2
0
void adc_init(void)
{
    unsigned long ulDummy = 0;

    // Enable the ADC hardware
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

    

    // Configure the pin as analog input
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1); // PIN D3/2/1 as ADC.
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5); // PIN E5 as ADC.
    //GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_5 | GPIO_PIN_4);                           // U_AN{0..1}



    

    // for 6 ADCs
    // use Sample Sequencer 0 since it is the only one able to handle more than four ADCs
    ADCSequenceDisable(ADC0_BASE, 0);
    // configure Sequencer to trigger from processor with priority 0
    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    // do NOT use TRIGGER_TIMER because of malfunction in the touch screen handler
    //ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);

    // configure the steps of the Sequencer
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH4);   //CH4 = PD3  
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH5);   //CH5 = PD2    
    ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH6);   //CH6 = PD1    
    ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);//CH8 = PE5
    //ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH11);                    // U_AN1
    //ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH4);                     // U_AN2
    //ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH5);                     // U_AN3
    //ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH6);                     // U_AN4
    //ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH7 | ADC_CTL_IE | ADC_CTL_END);       // U_AN5
    ADCSequenceEnable(ADC0_BASE, 0);

    // flush the ADC
    ADCSequenceDataGet(ADC0_BASE, 0, &ulDummy);

    // Enable Interrupt for ADC0 Sequencer 0
    ADCIntEnable(ADC0_BASE, 0);
    IntEnable(INT_ADC0);

    /*
   	for (int i=0; i < 4; i++) {
        for (int j=0; j < ADC_BUFF_SIZE; j++) {
            adcBuff[i][j] = 50; //give the buffers a half decent starting value.
        }
    }

    adcBuffCnt = 0;
    */

}
Ejemplo n.º 3
0
//---------------------------------------------------------------------------
// 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_GPIOB);
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

		//Removing Locks From Switch
					LOCK_F=0x4C4F434B;
					CR_F=GPIO_PIN_0|GPIO_PIN_4;

	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);

	GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
		GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_6);
		GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_3);
		GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5);
		GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
		//GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);

		GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,0x10);

}
Ejemplo n.º 4
0
void SensorInit(void){

	uint32_t sensorSetFlag;

	SENSOR_VERSION.word = 0x14081000LU;
	SubsystemInit(SENSOR, MESSAGE, "SENSOR", SENSOR_VERSION);

	//Enable register access to ADC0
	SysCtlPeripheralEnable( SYSCTL_PERIPH_ADC0 );

	//Enable register access to GPIO Port B
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

	// Set the sensor outputs as outputs
	GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5 | GPIO_PIN_7);

	// Select the analog ADC function for these pins.
	GPIOPinTypeADC( GPIO_PORTB_BASE, GPIO_PIN_4);	//Sensor 1 In
	GPIOPinTypeADC( GPIO_PORTB_BASE, GPIO_PIN_6);	//Sensor 2 In

	//Set up the ADC sequencer
	ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_ALWAYS, 3);
	ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH10|ADC_CTL_CMP0);
	ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH10|ADC_CTL_END);
	ADCSequenceEnable(ADC0_BASE, 0);

	// Read from EEPROM to see if this is the first time this is being setup
	EEPROMRead(&sensorSetFlag, EE_ADDR_SENSOR_SETUP, sizeof(sensorSetFlag));
	if(sensorSetFlag == EE_SENSOR_SET){
		EEPROMRead(&sensorTimeout, EE_ADDR_SENSOR_TIMEOUT, sizeof(sensorTimeout));
		EEPROMRead(&sensorThreshold, EE_ADDR_SENSOR_THRESHOLD, sizeof(sensorThreshold));
		LogMsg(SENSOR, MESSAGE, "Sensor Timeout Restored : %k seconds", sensorTimeout/1000);
		LogMsg(SENSOR, MESSAGE, "Sensor Threshold Restored To : %k", sensorThreshold);
	} else {
		sensorSetFlag = EE_SENSOR_SET;
		EEPROMProgram(&sensorTimeout, EE_ADDR_SENSOR_TIMEOUT, sizeof(sensorTimeout));
		EEPROMProgram(&sensorThreshold, EE_ADDR_SENSOR_THRESHOLD, sizeof(sensorThreshold));
		EEPROMProgram(&sensorSetFlag, EE_ADDR_SENSOR_SETUP, sizeof(sensorSetFlag));
		LogMsg(SENSOR, MESSAGE, "No sensor values saved, default values used. Threshold: %k, Timeout: %k", sensorThreshold, sensorTimeout);
	}

	//Set up the comparator
	ADCComparatorConfigure(ADC0_BASE, 0, ADC_COMP_TRIG_NONE|ADC_COMP_INT_LOW_HONCE );
	ADCComparatorRegionSet(ADC0_BASE, 0, sensorThreshold - SENSOR_HYST_WINDOW, sensorThreshold + SENSOR_HYST_WINDOW);
	ADCComparatorReset(ADC0_BASE, 0, true, true);
	ADCComparatorIntEnable(ADC0_BASE, 0);

	ADCIntRegister(ADC0_BASE, 0, Sensor1ISR);
	ADCIntEnable(ADC0_BASE, 0);

}
Ejemplo n.º 5
0
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();

}
Ejemplo n.º 6
0
void SampleLightCO(void){
	
	unsigned long ulADC0_Value[1];
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
	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);
	ADCIntClear(ADC0_BASE, 3);

	while(1){
		ADCProcessorTrigger(ADC0_BASE, 3);
		while(!ADCIntStatus(ADC0_BASE, 3, false)){
		}
		ADCIntClear(ADC0_BASE, 3);
		ADCSequenceDataGet(ADC0_BASE, 3, ulADC0_Value);
		
		Log("Breath Level = ");
		LogD(ulADC0_Value[0]);
		Log("\r");

		SysCtlDelay(SysCtlClockGet() / 12);
	}
}
Ejemplo n.º 7
0
/*******************************************************************************
*函数名:
  ()
*功能:
*输入:
*输出:
*说明:
*******************************************************************************/
void adcInit ( void )
{
    /*
    GPIOPinTypeADC ( GPIO_PORTE_BASE ,
                     GPIO_PIN_7 | GPIO_PIN_6 | GPIO_PIN_5 | GPIO_PIN_4 );
    */
    GPIOPinTypeADC ( GPIO_PORTE_BASE ,
                     GPIO_PIN_7 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_4 );
    SysCtlPeripheralEnable ( SYSCTL_PERIPH_ADC0 );
    //ADCSequenceConfigure ( ADC0_BASE, CMM_ADC_SEQU ,  ADC_TRIGGER_PROCESSOR, 0 );

    HWREG ( ADC0_BASE + ADC_O_ACTSS ) = 0x00; /*disable*/

    HWREG ( ADC0_BASE + ADC_O_IM ) = 0x00;           /*disable int*/
    HWREG ( ADC0_BASE + ADC_O_EMUX ) = 0x00;     /* soft control*/

    HWREG ( ADC0_BASE + ADC_O_SAC ) = 0x03;   /*8次采样平均*/

    HWREG ( ADC0_BASE + ADC_O_SSMUX0 ) =
        ( 0 << 0 ) | ( 1 << 4 ) | ( 2 << 8 ) | ( 3 << 12 )  ;


    HWREG ( ADC0_BASE + ADC_O_SSCTL0 ) = ( 1 << 13 ) |   /*第4个采样序列结束*/
                                         ( 1 << 14 )     /*并置ADCRIS 对应位为1*/
                                         ;//| ( ( uint ) 1 << 31 )   ;  /*第8个读取温度传感器*/

    HWREG ( ADC0_BASE + ADC_O_ACTSS ) = 0x01;   /*enable*/

}
Ejemplo n.º 8
0
/*
 * 初始化ADC引脚和配置
 * 其中ADC0的输入引脚配置为CH1,ADC1的输入引脚配置为CH2
 */
void Init_ADC()
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);

	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 3);
    ADCIntClear(ADC0_BASE, 3);

	ADCSequenceConfigure(ADC1_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC1_BASE, 3, 0, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END);
    ADCSequenceEnable(ADC1_BASE, 3);
    ADCIntClear(ADC1_BASE, 3);
}
Ejemplo n.º 9
0
// *******************************************************
// Initializes the ADC pins and their ISRs.
void heightInit(void)
{
	// using code from WEEK-2_ADC, my_adc.c written by Dr. Steve Weddell



	//SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
	//                 SYSCTL_XTAL_8MHZ);

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

	//
	// For this example ADC0 is used with AIN0 on port B1. This
	// was given by the LM3S1968 data sheet.
	// Therefore, GPIO port B needs to be enabled
	// so these pins can be used.
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

	// Select the analog ADC function for these pins.
	// The LM3S1968 data sheet was consulted to see which functions are
	// allocated per pin.
	GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_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.  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);

	initCircBuf (&g_heightBuf, CIRCBUF_SIZE);

}
Ejemplo n.º 10
0
//*****************************************************************************
//
// Initializes the ADC.
//
//*****************************************************************************
void
ADCInit(void)
{
    //
    // Set the ADC speed to 1 Msps.
    //
    ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS);

    //
    // Configure the GPIOs used with the analog inputs.
    //
    GPIOPinTypeADC(ADC_POSITION_PORT, ADC_POSITION_PIN);
    GPIOPinTypeADC(ADC_CURRENT_PORT, ADC_CURRENT_PIN);
    GPIOPinTypeADC(ADC_VBUS_PORT, ADC_VBUS_PIN);
    GPIOPinTypeADC(ADC_VBOOTA_PORT, ADC_VBOOTA_PIN);
    GPIOPinTypeADC(ADC_VBOOTB_PORT, ADC_VBOOTB_PIN);

    //
    // Configure the ADC sample sequence that is triggered by PWM
    // generator 2
    //
    ROM_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PWM0, 0);
    ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CURRENT_CH);
    ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_VBUS_CH);
    ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_POSITION_CH);
    ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 3,
                                 (ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END));
    ROM_ADCSequenceEnable(ADC0_BASE, 0);

    //
    // Enable interrupts
    //
    ROM_ADCIntEnable(ADC0_BASE, 0);
    ROM_IntEnable(INT_ADC0SS0);

    //
    // Set the zero current to indicate that the initial sampling has just
    // begun.
    //
    g_usCurrentZero = 0xffff;
}
Ejemplo n.º 11
0
//---------------------------------------------------------------------------
// 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);

}
Ejemplo n.º 12
0
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);
}
Ejemplo n.º 13
0
void adc_init(void){
	//GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0);
	GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	//  enable the ADC0 peripheral
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	//configure ADC sequencer - use ADC 0, sample sequencer 1, want the processor to trigger sequence, use highest priority
	ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
	//Configure ADC Sequencer Steps 0 - 2 on sequencer 1 to sample the temperature sensor
	ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH7 );
	ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH7 );
	ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH6 );
	//final sequencer step: need to sample temp sensor(ADC_CTL_TS), configure interrupt flag(ADC_CTL_IE) to be set when sample is done
	//tell ADC logic that this is the last conversion on sequencer (ADC_CTL_END)
	ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH6 |ADC_CTL_IE|ADC_CTL_END);
	ADCSequenceEnable(ADC0_BASE, 1);
}
Ejemplo n.º 14
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] ;

	}
}
Ejemplo n.º 15
0
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);
}
Ejemplo n.º 16
0
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;
}
Ejemplo n.º 17
0
//*****************************************************************************
//
// 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);
    }
}
Ejemplo n.º 18
0
void hardware_init(void)
{
	//Set PWM clock at the same frequency as system clock
	SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

	/*
	 * Inverter system setup
	 * period : Switching Frequency : 20Khz
	 * cycle : Duty Cycle SPWM
	 * deadband : Deadband
	 */
	inv.period = SysCtlClockGet()/20000;
	inv.deadband = 25*inv.period/100;
	inv.cycle = inv.period*500/1000;

	/*
	 * Boost converter system setup
	 * period: Switching frequency: 20kHz
	 * cycle: Duty cycle
	 * deadband: Deadband
	 */
	conv.period = inv.period;
	conv.deadband = inv.deadband;
	conv.cycle = conv.period*500/1000;

	/*
	 * Setup SPWM on PWM0 GEN0 and GEN1
	 * PB6 : PWM0 GEN0
	 * PB7: PWM0 GEN1
	 */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

	SysCtlPeripheralReset(SYSCTL_PERIPH_PWM0);
	SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOB);

	GPIOPinConfigure(GPIO_PB6_M0PWM0);
	GPIOPinConfigure(GPIO_PB7_M0PWM1);

	GPIOPinTypePWM(GPIO_PORTB_BASE, (GPIO_PIN_6 | GPIO_PIN_7));

	PWMGenConfigure(PWM0_BASE, PWM_GEN_0, (PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_GEN_SYNC_LOCAL | PWM_GEN_MODE_FAULT_UNLATCHED | PWM_GEN_MODE_DB_NO_SYNC));
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, inv.period-1);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, inv.cycle);
	PWMDeadBandEnable(PWM0_BASE, PWM_GEN_0, 13, 0);
	PWMGenEnable(PWM0_BASE, PWM_GEN_0);
	PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT|PWM_OUT_1_BIT, true);

	PWMSyncUpdate(PWM0_BASE, PWM_OUT_0_BIT|PWM_OUT_1_BIT);

	/*
	 * Setup boost converter pwm on PWM1
	 * PA6: PWM1 GEN1
	 */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	SysCtlPeripheralReset(SYSCTL_PERIPH_PWM1);
	SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOA);

	GPIOPinConfigure(GPIO_PA6_M1PWM2);	//Map PWM1, P1 OP2 to PA6
	GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6);	//Configure PA6 as PWM

	PWMGenConfigure(PWM1_BASE, PWM_GEN_1, (PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_GEN_NO_SYNC| PWM_GEN_MODE_DB_NO_SYNC));	//Configure PWM1, G1 as Down counter with no sync of updates
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, conv.period-1);	//Set Period of PWM1, G1
	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, conv.cycle);	//Set phase shift

	PWMIntEnable(PWM1_BASE, PWM_INT_GEN_1);
	PWMGenIntTrigEnable(PWM1_BASE, PWM_GEN_1, PWM_TR_CNT_LOAD|PWM_INT_CNT_LOAD);
	IntPrioritySet(INT_PWM1_1, 0x02);
	PWMOutputState(PWM1_BASE, PWM_OUT_2_BIT, true);

	PWMGenEnable(PWM1_BASE, PWM_GEN_1);

	/*
	 * Setup ISR for updating SPWM duty cycle
	 */
	uint32_t ui32TimIntSine = SysCtlClockGet()/200000;

	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);

	SysCtlPeripheralReset(SYSCTL_PERIPH_TIMER2);

	TimerConfigure(TIMER2_BASE, TIMER_CFG_A_PERIODIC);
	TimerLoadSet(TIMER2_BASE, TIMER_A, ui32TimIntSine-1);

	TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT);
	IntPrioritySet(INT_TIMER2A, 0x03);
	TimerEnable(TIMER2_BASE, TIMER_A);

	uint32_t ui32TimIntIcontrol = SysCtlClockGet()/40000;

	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
	SysCtlPeripheralReset(SYSCTL_PERIPH_TIMER1);

	TimerConfigure(TIMER1_BASE, TIMER_CFG_A_PERIODIC);
	TimerLoadSet(TIMER1_BASE, TIMER_A, ui32TimIntIcontrol-1);

	TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
	IntPrioritySet(INT_TIMER1A, 0x01);
	TimerEnable(TIMER1_BASE, TIMER_A);

	/*
	 * Setup PF1 as debug pin
	 */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

//	SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOF);

	HWREG(0x40005520) = 0x4C4F434B;
	HWREG(0x40005524) |= 0x01;
	HWREG(0x40005520) = 0x00;

	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);

	GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);

	GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE);

	IntPrioritySet(INT_GPIOF,0x00);
	GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_4);

	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);

	/*
	 * Setup ADC
	 * Configuration currently in discussion
	 * Interrupt at end might not be necessary
	 */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

	SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOE);

	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

	SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);

	ADCHardwareOversampleConfigure(ADC0_BASE, 2);
	ADCSequenceDisable(ADC0_BASE, 2);

	ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PWM1, 0x00);
	HWREG(0x4003801C) |= 0x1000;	//Sec 13.4.2 Pt 3

	ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH1);

	ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH2);

	ADCSequenceStepConfigure(ADC0_BASE, 2, 2, ADC_CTL_CH3|ADC_CTL_IE|ADC_CTL_END);

	ADCSequenceEnable(ADC0_BASE, 2);
}
Ejemplo n.º 19
0
//*****************************************************************************
// 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);

    }
}
Ejemplo n.º 20
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);
}
Ejemplo n.º 21
0
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;

}
Ejemplo n.º 22
0
void RMBD01Init(void)
{


  //
  // Configure the ADC for Pitch and Roll
  // sequence 3 means a single sample
  // sequence 1, 2 means up to 4 samples
  // sequence 0 means up to 8 samples
  // we use sequence 1
  //
  if (SysCtlPeripheralPresent(SYSCTL_PERIPH_ADC0))
  {

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);	
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);


    //
    // Configure the pins to be used as analog inputs.
    //
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    //
    // Select the external reference for greatest accuracy.
    //
    //ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);

    //
    // Only for LM4F232 Apply workaround for erratum 6.1, in order to use the
    // external reference.
    //
    //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    //HWREG(GPIO_PORTB_BASE + GPIO_O_AMSEL) |= GPIO_PIN_6;
	
    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); // 1 captures up to 4 samples
    //ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); // 1 captures up to 4 samples


    //ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ENCODER_CHANNEL_PITCH);     // sample pitch
    //ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ENCODER_CHANNEL_ROLL | ADC_CTL_IE | ADC_CTL_END);     // sample roll

    ADCHardwareOversampleConfigure(ADC0_BASE, 64);
    //ADCSoftwareOversampleConfigure(ADC0_BASE, 0, 8);	

	//ADCSoftwareOversampleStepConfigure(ADC0_BASE, 0, 0, (ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END));
	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0);


	//ADCSoftwareOversampleStepConfigure(ADC0_BASE, 0, 0, (ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END));
    //ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);     // sample roll
    //ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);     // sample roll
	    
    //ADCIntRegister(ADC0_BASE,0,ADCIntHandler);

	//
	// Enable the sequencer and interrupt
	//
	ADCSequenceEnable(ADC0_BASE, 3);
	ADCIntEnable(ADC0_BASE, 3);
	IntEnable(INT_ADC3);
	//
	// Zero the oversample counter and the sum
	//
	g_ucOversampleCnt = 0;
	g_ulSum = 0;
	
    //ADCSequenceEnable(ADC0_BASE, 2);
    //ADCIntEnable(ADC0_BASE, 2);

	#if 0
    //
    // Enable the ADC sequencers
    //
    ADCSequenceEnable(ADC0_BASE, 0);

    //
    // Flush the ADC sequencers to be sure there is no lingering data.
    //
    ADCSequenceDataGet(ADC0_BASE, 0, PitchRollAmp);

    //
    // Enable ADC interrupts
    //
    ADCIntClear(ADC0_BASE, 0);
    ADCIntEnable(ADC0_BASE, 0);
    IntEnable(INT_ADC0SS0);

	#else
    //
    // Setup timer for ADC_TRIGGER_TIMER
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
	
    //
    // Configure the second timer to generate triggers to the ADC 
    //
    TimerConfigure(TIMER1_BASE, TIMER_CFG_32_BIT_PER);
    TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() / 20000); // 50 us == 20K
    ulTimeSysClock = ROM_SysCtlClockGet()/20000;

  
    TimerControlStall(TIMER1_BASE, TIMER_A, true);
    TimerControlTrigger(TIMER1_BASE, TIMER_A, true);

    //
    // Enable the timers.
    //	
    TimerEnable(TIMER1_BASE, TIMER_A);
	#endif
	
    new_adc = false;
    //
  }
  //
  // Clear outstanding ADC interrupt and enable
  //
  //ADCIntClear(ADC0_BASE, 2);
  //ADCIntEnable(ADC0_BASE, 2);  
  //IntEnable(INT_ADC2);

  //
  // Set the zero current to indicate that the initial sampling has just
  // begun.
  //
  g_usCurrentZero = 0xffff;
} // InitADC
Ejemplo n.º 23
0
void Startup(void) {
  
  //STEP 1: OLED and PWM setup
  unsigned long ulPeriod;
  //SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
  SysCtlPWMClockSet(SYSCTL_PWMDIV_1); 
  SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
  GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);
  ulPeriod = SysCtlClockGet() / 400;
  PWMGenConfigure(PWM0_BASE, PWM_GEN_0,PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
  PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);
  PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, ulPeriod / 16);
  PWMGenEnable(PWM0_BASE, PWM_GEN_0); 
  
  
  //STEP 2: Timer setup
  //SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
  /*TimerState = 0;
  TimerIntUnregister(TIMER1_BASE, TIMER_A);
  TimerIntRegister(TIMER1_BASE, TIMER_A, IntTimer0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
  TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
  TimerLoadSet(TIMER1_BASE, TIMER_A, SysCtlClockGet());    
  IntEnable(INT_TIMER1A);
  TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
  TimerEnable(TIMER1_BASE, TIMER_A);*/
  
  // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
  
  //STEP 3: Button pad setup 
  TrainState = 0;
  GPIOPortIntUnregister(GPIO_PORTE_BASE);
  GPIOPortIntRegister(GPIO_PORTE_BASE,IntGPIOe);
  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);
  GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 , GPIO_FALLING_EDGE);
  GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 );
  IntEnable(INT_GPIOE);
  
  IntPrioritySet( INT_GPIOE, configKERNEL_INTERRUPT_PRIORITY);
  
  //STEP 4: Frequency count setup
  tempCount = 0;
  frequencyCount = 0;
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);       
  GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_3);
  GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
  GPIOPortIntUnregister(GPIO_PORTF_BASE);
  GPIOPortIntRegister(GPIO_PORTF_BASE,IntGPIOf);
  GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_RISING_EDGE);
  GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_3);
  IntEnable(INT_GPIOF);
  
  //STEP 5: UART setup  
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                      (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                       UART_CONFIG_PAR_NONE));
  IntEnable(INT_UART0); 
  UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
  
  IntPrioritySet( INT_UART0, configKERNEL_INTERRUPT_PRIORITY);
  
  //STEP 6: pin setup  
  /*SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, PORT_DATA);*/
  
  //STEP 7: ADC SETUP
  SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
  
  ADCSequenceDisable(ADC0_BASE,0);
  ADCSequenceDisable(ADC0_BASE,1);
  ADCSequenceDisable(ADC0_BASE,2);
  ADCSequenceDisable(ADC0_BASE,3);
  
  GPIOPinTypeADC(ADC0_BASE, 0xF); 
  
  ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);   
  ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); 
  ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0); 
  ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
  
  ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  
  ADCSequenceEnable(ADC0_BASE, 0);
  ADCSequenceEnable(ADC0_BASE, 1);
  ADCSequenceEnable(ADC0_BASE, 2);
  ADCSequenceEnable(ADC0_BASE, 3);
  
   ADCIntClear(ADC0_BASE, 0);
   ADCIntClear(ADC0_BASE, 1);
    ADCIntClear(ADC0_BASE, 2);
  ADCIntClear(ADC0_BASE, 3);
  
  ADCIntEnable(ADC0_BASE, 0);
  ADCIntEnable(ADC0_BASE, 1);
  ADCIntEnable(ADC0_BASE, 2);
   ADCIntEnable(ADC0_BASE, 3);
  
 
  //IntEnable(INT_ADC0);
  //IntPrioritySet(INT_ADC, 50);
  
  //IntEnable(INT_ADC0);
  //ADCIntClear(ADC0_BASE, 0);
  
 
  
  return;
}
Ejemplo n.º 24
0
void camera_init()
{
	Serial_puts(UART_DEBUG_MODULE, "inside \"camera_init\"\r\n", 100);
	// Calculate the PWM clock frequency
	camera_PWMClockFreq = SysCtlClockGet() / CAMERA_CLOCK_DIV;

	DEBUG_LINE("camera_init");

	// Enable the PWM peripheral
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

	// Enable the GPIO port
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

	// Configure PD0 as the PWM output for the drive motor
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);
	GPIOPinConfigure(GPIO_PB7_M0PWM1);
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4);
	GPIOPinConfigure(GPIO_PB4_M0PWM2);

	// Set the camera clock pulse period
	PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, CAMERA_SAMPLE_PERIOD - 1);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, (CAMERA_SAMPLE_PERIOD / 2) - 1);

	// Set the camera enable pulse period
	PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, (CAMERA_SAMPLE_PERIOD * CAMERA_SAMPLES) - 1);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, ((CAMERA_SAMPLE_PERIOD / 2) * 2) - 1);

	DEBUG_LINE("camera_init");

	// Enable the PWM output
	PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_2_BIT, true);
	PWMGenEnable(PWM0_BASE, PWM_GEN_0);
	PWMGenEnable(PWM0_BASE, PWM_GEN_1);

	PWMSyncTimeBase(PWM0_BASE, PWM_GEN_0_BIT | PWM_GEN_1_BIT);

	// Enable PWM trigger on zero count on Generator 0
	PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_TR_CNT_ZERO); // PWM_TR_CNT_ZERO/PWM_TR_CNT_LOAD

	// Trigger an interrupt on GEN1 load (to setup the uDMA transfer on a consistent time boundary)
	PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_1, PWM_INT_CNT_LOAD);

	DEBUG_LINE("camera_init");
	
    /********************************************
	 * 			  ADC CONFIGURATION			    *
	 ********************************************
	 */

	// Enable ADC0 module
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

	DEBUG_LINE("camera_init");

	ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_FULL, 1);

	DEBUG_LINE("camera_init");

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    // Camera Far
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
    // Camera Near
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);

	DEBUG_LINE("camera_init");

	// Configure and enable the ADC sequence; single sample
	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PWM0, 0);
	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
	ADCSequenceEnable(ADC0_BASE, 3);

	DEBUG_LINE("camera_init");

	ADCSequenceDMAEnable(ADC0_BASE, 3);

	DEBUG_LINE("camera_init");

	// Start writing into the first buffer
	camera_DBSelected = 0;
    current_Camera = FAR;
	// Expose the other buffer
	camera_buffer = camera_DoubleBuffer[1];

	/********************************************
	 * 			  uDMA CONFIGURATION			*
	 ********************************************
	 */

	// Enable the uDMA for normal and sleep operation
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA);
	uDMAEnable();

	DEBUG_LINE("camera_init");

	// Set the position of the uDMA control table
	uDMAControlBaseSet(uDMAControlTable);

	// Put the uDMA table entry for ADC3 into a known state
	uDMAChannelAttributeDisable(UDMA_CHANNEL_ADC3,
		UDMA_ATTR_USEBURST |
		UDMA_ATTR_ALTSELECT |
		UDMA_ATTR_HIGH_PRIORITY |
		UDMA_ATTR_REQMASK);

	// Configure the primary and alternate uDMA channel structures
	uDMAChannelControlSet(UDMA_CHANNEL_ADC3 | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1);
	uDMAChannelControlSet(UDMA_CHANNEL_ADC3 | UDMA_ALT_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1);

	// Configure the primary and alternate transfers for ping-pong operation
	uDMAChannelTransferSet(UDMA_CHANNEL_ADC3 | UDMA_PRI_SELECT, UDMA_MODE_PINGPONG, (void*) (ADC0_BASE + ADC_O_SSFIFO3), camera_DoubleBuffer[0], CAMERA_SAMPLES);
	uDMAChannelTransferSet(UDMA_CHANNEL_ADC3 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG, (void*) (ADC0_BASE + ADC_O_SSFIFO3), camera_DoubleBuffer[1], CAMERA_SAMPLES);

	DEBUG_LINE("camera_init");

	// Enable the ADC3 uDMA channel
	uDMAChannelEnable(UDMA_CHANNEL_ADC3);

	// Enable interrupts
	// IntEnable(INT_ADC0SS3);
	// ADCIntEnableEx(ADC0_BASE, ADC_INT_DMA_SS3);

	IntEnable(INT_PWM0_1);
	PWMIntEnable(PWM0_BASE, PWM_INT_GEN_1);


	DEBUG_LINE("camera_init");

}
Ejemplo n.º 25
0
/** Initializes Ports/Pins: sets direction, interrupts, pullup/pulldown resistors etc. */
void portInit()
{
    /* Port A
     * PA0      U0Rx (Debug UART)
     * PA1      U0Tx (Debug UART)
     * PA2      Bit-Bang I2C SDA
     * PA3      Bit-Bang I2C SCL
     * PA4      BoosterPack RGB LED - Green
     * PA5      Module SS & MRDY
     * PA6		BoosterPack RGB LED - Red
     * PA7		Module SRDY
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    PERIPHERAL_ENABLE_DELAY();
    /* Configure UART pins */
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    /* Outputs */
    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6);
    GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_6, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); // For LEDs
    /* Inputs */
    GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_7);
    /* Bit-bang I2C */
    //GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_DIR_MODE_OUT);  //SDA & SCL
    //GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_OD);  //SDA & SCL open-drain
    //GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_PIN_2 | GPIO_PIN_3);  //Set SDA & SCL high


    /* Port B
     * PB0
     * PB1
     * PB2		BoosterPack RGB LED - Blue
     * PB3
     * PB4		Module SCLK		SSI2CLK
     * PB5      LED0
     * PB6      Module MISO		SSI2Rx
     * PB7		Module MOSI		SSI2Tx
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);  //FOR STATUS LED
    PERIPHERAL_ENABLE_DELAY();
    /* SSI2 Configuration for Module SPI */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
    PERIPHERAL_ENABLE_DELAY();
    GPIOPinConfigure(GPIO_PB4_SSI2CLK);
    GPIOPinConfigure(GPIO_PB6_SSI2RX);
    GPIOPinConfigure(GPIO_PB7_SSI2TX);
    GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7);
    /* Outputs */
    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_5);
    GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_5, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);

    /* Port C
     * PC0		(JTAG TCK/SWCLK)
     * PC1		(JTAG TMS/SWDIO)
     * PC2		(JTAG TDI)
     * PC3		(JTAG TDIO/SWO)
     * PC4
     * PC5
     * PC6
     * PC7
     */
    // Note: no initialization needed for Port C required; using default configuration

    /* Port D
     * PD0		I2C3SCL
     * PD1		I2C3SDA
     * PD2
     * PD3
     * PD4		(USB D-)
     * PD5      (USB D+)
     * PD6
     * PD7		(USB VBUS)
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);  //FOR STATUS LED
    PERIPHERAL_ENABLE_DELAY();
    /* I2C Configuration */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); //requires 5 clock cycles to initialize
    PERIPHERAL_ENABLE_DELAY();
    GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); //NOTE: Only required for blizzard (LM4F) parts
    GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
    GPIOPinConfigure(GPIO_PD0_I2C3SCL);
    GPIOPinConfigure(GPIO_PD1_I2C3SDA);
#ifdef TIVA
    I2CMasterInitExpClk(I2C3_BASE, SysCtlClockGet(), false); //FALSE = 100kbps
#else
    I2CMasterInitExpClk(I2C3_MASTER_BASE, SysCtlClockGet(), false); //FALSE = 100kbps
#endif

    SysCtlDelay(10000); //otherwise portion of SlaveAddrSet() lost - only for blizzard

    /* Port E - note this port is only 6 pins
     * PE0		Module Reset
     * PE1
     * PE2
     * PE3
     * PE4		Switch S2 on BoosterPack - note has external 47k pullup on BoosterPack
     * PE5      Current Sensor analog input
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    PERIPHERAL_ENABLE_DELAY();
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    PERIPHERAL_ENABLE_DELAY();
    /* Outputs */
    GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0);
    /* Inputs */
    GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_4 , GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
    GPIODirModeSet(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN);
    GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE); // Make button a falling-edge triggered interrupt
#ifdef TIVA
    GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_4);					// Enable the interrupt on this pin
    GPIOIntClear(GPIO_PORTE_BASE, GPIO_PIN_4);					//Clear interrupts
#else
    GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_4);					// Enable the interrupt on this pin
    GPIOPinIntClear(GPIO_PORTE_BASE, GPIO_PIN_4);					//Clear interrupts
#endif
    IntEnable(INT_GPIOE);//enable interrupt 18

    /* ADC Inputs */
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);

    RADIO_OFF();
    SPI_SS_CLEAR();

    /* Port F
     * PF0      Switch SW2 on Stellaris LaunchPad
     * PF1		RGB LED on Stellaris LaunchPad - Red
     * PF2		RGB LED on Stellaris LaunchPad - Green
     * PF3		RGB LED on Stellaris LaunchPad - Blue
     * PF4		Switch SW1 on Stellaris LaunchPad
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    PERIPHERAL_ENABLE_DELAY();
    /* Outputs */
    // Note: PWM Outputs for LEDs are initialized separately if they are being used
    /* Inputs */
    // Unlock PF0 so we can change it to a GPIO input. see ButtonsInit() in buttons.c in example qs-rgb
    // Once we have enabled (unlocked) the commit register then re-lock it
    // to prevent further changes.  PF0 is muxed with NMI thus a special case.
#ifdef TIVA
    HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
#else
    HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD;
#endif
    HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
    HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;
    GPIODirModeSet(GPIO_PORTF_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN);
    GPIOPadConfigSet(GPIO_PORTF_BASE, ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOIntTypeSet(GPIO_PORTF_BASE, ALL_BUTTONS, GPIO_FALLING_EDGE); // Make button a falling-edge triggered interrupt
#ifdef TIVA
    GPIOIntEnable(GPIO_PORTF_BASE, ALL_BUTTONS);                  // Enable the interrupt on this pin
    GPIOIntClear(GPIO_PORTF_BASE, ALL_BUTTONS);                   //Clear interrupts
#else
    GPIOPinIntEnable(GPIO_PORTF_BASE, ALL_BUTTONS);                  // Enable the interrupt on this pin
    GPIOPinIntClear(GPIO_PORTF_BASE, ALL_BUTTONS);                   //Clear interrupts
#endif

    IntEnable(INT_GPIOF);
}
Ejemplo n.º 26
0
int main(void)
{
	unsigned long ulADC0_Value[1];
	bool running;
	int LED=2;
	int i=0;
	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    //
    // Enable GPIO port A which is used for UART0 pins.
    // TODO: change this to whichever GPIO port you are using.
    //
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    //
    // Configure the pin muxing for UART0 functions on port A0 and A1.
    // This step is not necessary if your part does not support pin muxing.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);

    //
    // Select the alternate (UART) function for these pins.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	GPIOPinTypeGPIOOutput(LED_PORT, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|TEST_PIN);
    // Initialize the UART for console I/O.
    //
    UARTStdioInit(0);
    running = false;
    //
    // 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/PE3\n\n");

	// >>>>>>>>>>>>> ADC CONFIGURATION <<<<<<<<<<<<<<<<<

	// Enable the clock to the ADC0 module
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);


	// >>>>>>>>>>>>> GPI CONFIGURATION <<<<<<<<<<<<<<<<<

	// Configure the pin as analog input
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);

	// Configure the ADC to sample at 500KSps
	SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);

	// Disable sample sequences 3
	ADCSequenceDisable(ADC0_BASE, 3);

	// Configure sample sequence 3: timer trigger, priority = 0
	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

	// Configure sample sequence 3 steps 0
	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);

	ADCSequenceEnable(ADC0_BASE, 3);

    ADCIntEnable(ADC0_BASE, 0);

    // 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)
    {
    	i++;
        if (UARTCharsAvail(UART0_BASE)) {
            char temp;

            temp = UARTCharGetNonBlocking(UART0_BASE);

            if (temp == '1') running = true;
            else if (temp == '0') running = false;
        }
        if (running) {
        	if (i==100){
               	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, LED);
        	}
 
        	// 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, ulADC0_Value);

            // Display the AIN0 (PE7) digital value on the console.
            unsigned short val = ulADC0_Value[0];

            UARTCharPut(UART0_BASE,(char)(val&0x00FF));
            UARTCharPut(UART0_BASE,(char)((val>>8)&0x00FF));
            if (i==200){
            	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
            	i=0;
            }
        }
        // This function provides a means of generating a constant length
        // delay.  The function delay (in cycles) = 3 * parameter.  Delay
        // 250ms arbitrarily.
        SysCtlDelay(SysCtlClockGet() / 250);
    }
}