Beispiel #1
0
void ADC0SS0Handler(void)
{
    ROM_ADCIntClear(ADC0_BASE,SEQUENCER);
    ROM_ADCSequenceDataGet(ADC0_BASE,SEQUENCER,&g_ulADCData[0]);
    g_ulADCCount++;

}
Beispiel #2
0
//*****************************************************************************
//
// This function is called to start an acquisition running.  It determines
// which channels are to be logged, enables the ADC sequencers, and computes
// the first RTC match value.  This will start the acquisition running.
//
//*****************************************************************************
void AcquireStart()
{
    unsigned long ulIdx;

    ulIdx = ulSelectedMask;
    g_ulNumItems = 0;
    while(ulIdx)
    {
        if(ulIdx & 1)
        {
            g_ulNumItems++;
        }
        ulIdx >>= 1;
    }



    //USBStickOpenLogFile(0);

    ROM_ADCSequenceEnable(ADC0_BASE,SEQUENCER);
    //ROM_ADCSequenceDataGet(ADC0_BASE,SEQUENCER,&g_ulADCData[0]);
    ROM_ADCIntClear(ADC0_BASE,SEQUENCER);

    ROM_ADCIntEnable(ADC0_BASE,SEQUENCER);
    ROM_IntEnable(INT_ADC0SS2);

    ROM_TimerEnable(TIMER0_BASE, TIMER_A);

    //ROM_IntEnable(INT_TIMER1A);
    //ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
    //ROM_TimerEnable(TIMER1_BASE, TIMER_A);
    ROM_IntMasterEnable();
}
Beispiel #3
0
static void IR_Detector_ISR(void)
{
	volatile uint32_t ADCResult;
	ROM_ADCIntClear(ADC0_BASE, 2);
	ROM_ADCSequenceDataGet(ADC0_BASE, 2, (uint32_t *)&ADCResult);

	ADC_Step++;
	ADC_Step %= 8;

	switch (ADC_Step)
	{
		case 0:
			IR_Result[3] = -ADCResult+IR_ResultTmp[3];
			TURN_ON_IRD1();
			break;
		case 1:
			IR_ResultTmp[0] = ADCResult;
			TURN_OFF_IRD1();
			break;
		case 2:
			IR_Result[0] = -ADCResult+IR_ResultTmp[0];
			TURN_ON_IRD2();
			break;
		case 3:
			IR_ResultTmp[1] = ADCResult;
			TURN_OFF_IRD2();
			break;
		case 4:
			IR_Result[1] = -ADCResult+IR_ResultTmp[1];
			TURN_ON_IRD3();
			break;
		case 5:
			IR_ResultTmp[2] = ADCResult;
			TURN_OFF_IRD3();
			break;
		case 6:
			IR_Result[2] = -ADCResult+IR_ResultTmp[2];
			TURN_ON_IRD4();
			break;
		case 7:
			IR_ResultTmp[3] = ADCResult;
			TURN_OFF_IRD4();
			break;


		default:
			//Code should never reach this statement
			ADC_Step = 0;
			TURN_ON_IRD1();

			break;
	}
 	ir_Runtimeout(&IR_Timer_Timeout, 1);
}
Beispiel #4
0
//================ PRIVATE DEFINE ===========================================//
//
//================ PRIVATE MACRO ============================================//
//
//================ SOURCE CODE ==============================================//
void LightSensorIntHandler(void) {
	//
	// Get ADC Data
	//
	ADCSequenceDataGet(ADC0_BASE, 3, &(LigthIntensityValue));

	//
	// Clear the ADC interrupt flag.
	//
	ROM_ADCIntClear(ADC0_BASE, 3);
}
Beispiel #5
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);
}
//*****************************************************************************
//
// The interrupt handler for the second timer interrupt. (temperature)
//
//*****************************************************************************
void
Timer1IntHandler(void)
{


    //
    // Clear the timer interrupt.
    //
    ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

    //
    // Clear ADC interrupt
    //
    ROM_ADCIntClear(ADC0_BASE, 3);

    //Increment Timer A Count
    TimerBCount++;

    /*//
    // Use the flags to Toggle the LED for this timer
    //
    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, g_ui32Flags);*/

    //
    // Toggle the flag for the temperature timer.
    //
    HWREGBITW(&g_ui32InterruptFlags, 0) = 1;

    //
    // Trigger ADC Conversion
    //
    ROM_ADCProcessorTrigger(ADC0_BASE, 3);

    //
    //Wait for ADC conversion to complete
    //
    while(!ROM_ADCIntStatus(ADC0_BASE, 3, false)) { //Wait for ADC to finish sampling
    }
	ROM_ADCSequenceDataGet(ADC0_BASE, 3, adc_value); //Get data from Sequencer 3
    //
    // Update the interrupt status.
    //
    //ROM_IntMasterDisable();
    //UARTprintf("ADC Value = %d\n", adc_value[0]); //Print out the first (and only) value
    //ROM_IntMasterEnable();
}
Beispiel #7
0
void BattSenseISR(void)
{
	uint8_t temp;
	uint32_t BattResult;
	static uint32_t avrBattResult = 2700;
	ROM_ADCIntClear(ADC1_BASE, 3);
	ROM_ADCSequenceDataGet(ADC1_BASE, 3, &BattResult);

	avrBattResult = (4 * avrBattResult + BattResult) / 5;
	if (avrBattResult < 2500)
	{
		ROM_GPIOPinWrite(ENABLE_PORT, ENA_LEFT_PIN | ENA_RIGHT_PIN, 0x00);
		SetPWM(MOTOR_LEFT, DEFAULT, 0);
		SetPWM(MOTOR_RIGHT, DEFAULT, 0);
		BoostDisable();
		IntMasterDisable();
	}
}
void BattSenseISR(void)
{
	uint32_t ADCResult, BatteryVoltage;
	ROM_ADCIntClear(ADC0_BASE, 3);
	ROM_ADCSequenceDataGet(ADC0_BASE, 3, (uint32_t *)&ADCResult);
	BatteryVoltage = ((float)ADCResult) / 4096 * 3.3 * (220 + 680) / 220;
#warning CHECK BATT SENSE
#if 0
	if (BatteryVoltage < (float)11.0)
	{
		HBridgeEnable();
		throttleStop();
		while(1)
		{
			LED3_TOGGLE;
			ROM_SysCtlDelay(ROM_SysCtlClockGet()/3);
		}
	}
#endif
}
Beispiel #9
0
void BattSenseISR(void)
{
	uint32_t ADCResult;
	ROM_ADCIntClear(ADC1_BASE, 3);
	battery_Runtimeout(&BattSenseTimerTimout, 10000);
	ROM_ADCSequenceDataGet(ADC1_BASE, 3, (uint32_t *)&ADCResult);
	BatteryVoltage = ((float)ADCResult) / 4096 * 3.3 * (200 + 470) / 200;

	if (BatteryVoltage < (float)7.0)
	{
		buzzer_low_battery_shutdown();
		//shutdown robot here to protect battery

	}
	else if (BatteryVoltage < (float)7.2)
	{
		//Notify user to shutdown robot
		buzzer_low_batterry_notify();
	}
}
Beispiel #10
0
int main(void)
{
	uint32_t ui32ADC0Value[4];
	volatile uint32_t ui32TempAvg;
	volatile uint32_t ui32TempValueC;
	volatile uint32_t ui32TempValueF;


	ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 64);
	ROM_ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
	ROM_ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
	ROM_ADCSequenceEnable(ADC0_BASE, 1);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 64);

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

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));


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

	while(1)
	{
		if(mode == 0)
		{
			ROM_ADCIntClear(ADC0_BASE, 1);
			ROM_ADCProcessorTrigger(ADC0_BASE, 1);
			while(!ROM_ADCIntStatus(ADC0_BASE, 1, false))
			{
			}
			ROM_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;

			UARTStrPut("Current Temperature ");
			UARTIntPut(ui32TempValueC);
			UARTCharPut(UART0_BASE, 176);

			UARTStrPut("C, Set Temperature ");
			UARTIntPut(setTemp);
			UARTCharPut(UART0_BASE, 176);
			UARTStrPut("C\r\n");

			int temp;
			if (setTemp < ui32TempValueC) temp = 2; // red
			else if (setTemp > ui32TempValueC) temp = 8; // green
			else temp = 4; // blue if equal
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, temp);
			SysCtlDelay(SysCtlClockGet()/3);
		}
	}
}
//*****************************************************************************
//
// This function is called each time the ADC sample sequence completes.
//
//*****************************************************************************
void
ADCIntHandler(void)
{
    unsigned short pusADCData[8];
    unsigned long ulIdx;

    //
    // Clear the ADC interrupt.
    //
    ROM_ADCIntClear(ADC0_BASE, 0);

    //
    // If running on Rev A0 silicon, clear the PWM trigger interrupt sources.
    // This is a workaround to allow them to retrigger the ADC.  Since this
    // workaround is otherwise harmless, it is done unconditionally (to avoid
    // checking the silicon revision within this interrupt handler).
    //
    ROM_PWMGenIntClear(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_BD);

    //
    // Call the H-bridge update function.
    //
    HBridgeTick();

    //
    // Drain the ADC of conversions.
    //
    if(HWREG(ADC0_BASE + ADC_O_SSFSTAT0) & ADC_SSFSTAT0_EMPTY)
    {
        return;
    }
    pusADCData[0] = HWREG(ADC0_BASE + ADC_O_SSFIFO0);
    if(HWREG(ADC0_BASE + ADC_O_SSFSTAT0) & ADC_SSFSTAT0_EMPTY)
    {
        return;
    }
    pusADCData[1] = HWREG(ADC0_BASE + ADC_O_SSFIFO0);
    if(HWREG(ADC0_BASE + ADC_O_SSFSTAT0) & ADC_SSFSTAT0_EMPTY)
    {
        return;
    }
    pusADCData[2] = HWREG(ADC0_BASE + ADC_O_SSFIFO0);
    if(HWREG(ADC0_BASE + ADC_O_SSFSTAT0) & ADC_SSFSTAT0_EMPTY)
    {
        return;
    }
    pusADCData[3] = HWREG(ADC0_BASE + ADC_O_SSFIFO0);
    if(!(HWREG(ADC0_BASE + ADC_O_SSFSTAT0) & ADC_SSFSTAT0_EMPTY))
    {
        while(!(HWREG(ADC0_BASE + ADC_O_SSFSTAT0) & ADC_SSFSTAT0_EMPTY))
        {
            HWREG(ADC0_BASE + ADC_O_SSFIFO0);
        }
        return;
    }
    g_pusADCData[0] = pusADCData[0];
    g_pusADCData[1] = pusADCData[1];
    g_pusADCData[2] = pusADCData[2];
    g_pusADCData[3] = pusADCData[3];

    //
    // Put this winding current reading into the current bucket.
    //
    g_pusBuckets[g_ulBucket >> 16] += g_pusADCData[WINDING_CURRENT];
    g_ulBucket++;

    //
    // See if this bucket is full.
    //
    if((g_ulBucket & 0xffff) == 16)
    {
        //
        // Compute the new averaged winding current reading.
        //
        g_usCurrent = ((g_pusBuckets[0] + g_pusBuckets[1] + g_pusBuckets[2] +
                        g_pusBuckets[3] + g_pusBuckets[4] + g_pusBuckets[5] +
                        g_pusBuckets[6] + g_pusBuckets[7]) / (8 * 16));

        //
        // Advance to the next bucket.
        //
        g_ulBucket = (g_ulBucket + 0x10000) & 0x00070000;
        g_pusBuckets[g_ulBucket >> 16] = 0;
    }
void vTempDriverTask() //Code Credit to Tivaware Example temperature_sensor.c
{
	uint32_t measurement[1];

	uint32_t ui32TempValueC;

	ROM_GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0);
	ROM_GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_1);

	ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); //D0
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH15 | ADC_CTL_IE |
			ADC_CTL_END);
	ROM_ADCSequenceEnable(ADC0_BASE, 3);
	ROM_ADCIntClear(ADC0_BASE, 3);

	for(;;)
	{

		xSemaphoreTake(pollTempSem, portMAX_DELAY);

		ROM_ADCProcessorTrigger(ADC0_BASE, 3);

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

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

		// Read ADC Value.
		ROM_ADCSequenceDataGet(ADC0_BASE, 3, measurement);

		ui32TempValueC = (uint32_t)(log(40960/(29.0*measurement[0]) - 10.0/29) * -1/0.041);

		outputBuffer.tempR = ui32TempValueC;

		//Switch to other Thermistor
		ROM_ADCSequenceDisable(ADC0_BASE, 3);
		ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH14 | ADC_CTL_IE | //D1
				ADC_CTL_END);
		ROM_ADCSequenceEnable(ADC0_BASE, 3);

		//Begin ADC poll
		ROM_ADCProcessorTrigger(ADC0_BASE, 3);

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

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

		// Read ADC Value.
		ROM_ADCSequenceDataGet(ADC0_BASE, 3, measurement);

		ui32TempValueC = (uint32_t)(log(40960/(29.0*measurement[0]) - 10.0/29) * -1/0.041);

		outputBuffer.tempL = ui32TempValueC;

		ROM_ADCSequenceDisable(ADC0_BASE, 3);
		ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH15 | ADC_CTL_IE |
				ADC_CTL_END);
		ROM_ADCSequenceEnable(ADC0_BASE, 3);
	}

}