Esempio n. 1
1
void confADC(){



	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);   // Habilita ADC0
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_ADC0);
	ADCSequenceDisable(ADC0_BASE,0); // Deshabilita el secuenciador 1 del ADC0 para su configuracion


	HWREG(ADC0_BASE + ADC_O_PC) = (ADC_PC_SR_500K);	// usar en lugar de SysCtlADCSpeedSet
	ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);// Disparo de muestreo por instrucciones de Timer
	ADCHardwareOversampleConfigure(ADC0_BASE, 64); //SobreMuestreo de 64 muestras

	// Configuramos los 4 conversores del secuenciador 1 para muestreo del sensor de temperatura
	ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0); //Sequencer Step 0: Samples Channel PE3
	ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1); //Sequencer Step 1: Samples Channel PE2
	ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END); //Sequencer Step 2: Samples Channel PE1

	IntPrioritySet(INT_ADC0SS0,5<<5);
	// Tras configurar el secuenciador, se vuelve a habilitar
	ADCSequenceEnable(ADC0_BASE, 0);
	//Asociamos la funcion a la interrupcion
	ADCIntRegister(ADC0_BASE, 0,ADCIntHandler);

	//Activamos las interrupciones
	ADCIntEnable(ADC0_BASE,0);


}
//******************************************************************************
void initADC (void)
{
  // The ADC0 peripheral must be enabled for configuration and use.
  SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

  // 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 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
  // on the ADC sequences and steps, refer to the LM3S1968 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);

  // Register the interrupt handler
  ADCIntRegister (ADC0_BASE, 3, HeightIntHandler);

  // Enable interrupts for ADC0 sequence 3 (clears any outstanding interrupts)
  ADCIntEnable(ADC0_BASE, 3);
}
Esempio n. 3
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);
    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_TIMER, 0); // 1 captures up to 4 samples

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

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


    //
    // 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, SysCtlClockGet() / 1000); // 2 ms
  
    TimerControlStall(TIMER1_BASE, TIMER_A, true);
    TimerControlTrigger(TIMER1_BASE, TIMER_A, true);

    //
    // Enable the timers.
    //	
    TimerEnable(TIMER1_BASE, TIMER_A);
    new_adc = false;
    //
  }
  //
  // Clear outstanding ADC interrupt and enable
  //
  ADCIntClear(ADC0_BASE, 1);
  IntEnable(INT_ADC0);
} // InitADC
Esempio n. 4
0
int ADC_Collect(unsigned int channelNum, unsigned int fs, 
  unsigned long buffer[], unsigned int numberOfSamples){

  int i;
  unsigned long config;

  // Setting global pointer to point at array passed by funciton
  Buffer = buffer;

  // 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;
  }

  // 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
  for(i = 0; i < (numberOfSamples - 1); i++){
    ADCSequenceStepConfigure(ADC0_BASE, 0, i, config);
  }
  ADCSequenceStepConfigure(ADC0_BASE, 0, numberOfSamples - 1, config | ADC_CTL_END | ADC_CTL_IE);
  ADCIntRegister(ADC0_BASE, 0, ADC0_Handler);
  ADCSequenceEnable(ADC0_BASE, 0);

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

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

  //
  //
  // TODO: configure this to calculate load value based on frequency inputed
  //
  //
  TimerLoadSet(TIMER0_BASE, TIMER_A, 1000);
  TimerEnable(TIMER0_BASE, TIMER_A);

  ADCIntClear(ADC0_BASE, 0);
  TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

  ADCIntEnable(ADC0_BASE, 0);
  TimerIntEnable(TIMER0_BASE, TIMER_A);

  // Claering Status flag
  Status = FALSE;
  
  return 1; 
}
Esempio n. 5
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);

}
Esempio n. 6
0
void BattSense_init(void)
{
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
	ROM_GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4);
	ROM_ADCHardwareOversampleConfigure(ADC1_BASE, 64);

	ROM_ADCSequenceConfigure(ADC1_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
	ROM_ADCSequenceStepConfigure(ADC1_BASE, 3, 0, ADC_CTL_END | ADC_CTL_CH10 | ADC_CTL_IE);
	ROM_ADCSequenceEnable(ADC1_BASE, 3);
 	ADCIntRegister(ADC1_BASE, 3, &BattSenseISR);
 	ROM_ADCIntEnable(ADC1_BASE, 3);

 	battery_Runtimeout(&BattSenseTimerTimout, 10000);
}
Esempio n. 7
0
//============================================================================//
//==                      ADC初始化函数                                     ==//
//============================================================================//
//==说明:     对于测试将方波滤波成为正弦波的测试,需要改变AD的采样频率       ==//
//==          SYSCTL_ADCSPEED_1MSPS   // 采样速率:1M次采样/秒              ==//
//==          SYSCTL_ADCSPEED_500KSPS // 采样速率:500K次采样/秒            ==//
//==          SYSCTL_ADCSPEED_250KSPS // 采样速率:250K次采样/秒            ==//
//==          SYSCTL_ADCSPEED_125KSPS // 采样速率:125K次采样/秒            ==//
//==          频率高的方波AD采样频率应适当增加                              ==//
//==入口参数: 无                                                            ==//
//==出口参数: 无                                                            ==//
//==返回值:   无                                                            ==//
//============================================================================//
void ADCInit(void)
{
  SysCtlPeriEnable(SYSCTL_PERIPH_ADC);                 // 使能ADC模块
  SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);          // 设置ADC采样速率
  ADCSequDisable(ADC_BASE, 0);                         // 配置前先禁止采样序列
// 采样序列配置:ADC基址,采样序列编号,触发事件,采样优先级
  ADCSequConfig(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
// 采样步进设置:ADC基址,采样序列编号,步值,通道设置(ADC0转换完后停止触发中断)
  ADCSequStepConfig(ADC_BASE, 0, 0, ADC_CTL_CH0 |
                                    ADC_CTL_END |
                                    ADC_CTL_IE);
  ADCIntEnable(ADC_BASE, 0);                           // 使能ADC中断
  IntEnable(INT_ADC0);                                 // 使能ADC采样序列中断
  ADCIntRegister(ADC_BASE, 0, ADC_ISR);
  IntMasterEnable( );                                  // 使能处理器中断
  ADCSequEnable(ADC_BASE, 0);                          // 使能采样序列
}
Esempio n. 8
0
void LightSensorInit(void) {
	// Set up pin as ADC
	ROM_GPIOPinTypeADC(LIGHTSENSOR_PORT, LIGHTSENSOR_PIN);

	ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

	ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE
			| ADC_CTL_END);

	ROM_ADCSequenceEnable(ADC0_BASE, 3);

	ROM_ADCIntEnable(ADC0_BASE, 3);

	ROM_ADCIntClear(ADC0_BASE, 3);

	ADCIntRegister(ADC0_BASE, 3, LightSensorIntHandler);
}
Esempio n. 9
0
void IRDetector_init(void)
{
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
	ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0x00);

	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
	ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 32);

	ROM_ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH0 | ADC_CTL_IE);	//PE3, enable interrupt

	ROM_ADCSequenceEnable(ADC0_BASE, 2);
 	ADCIntRegister(ADC0_BASE, 2, &IR_Detector_ISR);
 	ROM_ADCIntEnable(ADC0_BASE, 2);


 	ADC_Step = 0;
 	TURN_ON_IRD1();
 	ir_Runtimeout(&IR_Timer_Timeout, 1);
}
Esempio n. 10
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);
}
Esempio n. 11
0
int main(void)
{
    unsigned long adc_result[16];
    unsigned long cnt;
    float temperature;

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


    //
    // Configure low-level I/O to use printf()
    //
    llio_init(115200);


    //
    // Configure ADC
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);
    SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);

    // ADC sequence #0 - setup with 2 conversions
    ADCSequenceDisable(ADC_BASE, 0);
    ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_TIMER, 0);
    ADCIntRegister(ADC_BASE, 0, ADCIntHandler);
    ADCIntEnable(ADC_BASE, 0);

    // sequence step 0 - channel 0
    ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH0);
    // sequence step 1 - internal temperature sensor. Generate Interrupt & End of Sequence
    ADCSequenceStepConfigure(ADC_BASE, 0, 1, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);

    ADCSequenceEnable(ADC_BASE, 0);

    //
    // Configure Timer to trigger ADC
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    TimerConfigure( TIMER0_BASE, TIMER_CFG_32_BIT_PER );
    TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
    TimerLoadSet( TIMER0_BASE, TIMER_A, SysCtlClockGet() / 2 );     // 2Hz trigger
    TimerEnable( TIMER0_BASE, TIMER_A );


    printf("\r\n\r\nADC 2 Channel Example\r\n");

    //
    // Loop forever.
    //
    while(1)
    {
        cnt = ADCSequenceDataGet(ADC_BASE, 0, adc_result);
        if (cnt == 2)
        {
            // Calculate temperature
            temperature = (2.7 - (float)adc_result[1] * 3.0 / 1024.) * 75. - 55.;

            printf("%d,%d,%.1f\r\n", adc_result[0], adc_result[1], temperature);
        }
        SysCtlSleep();
    }
}
Esempio n. 12
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);
}