Example #1
0
static void IR_Timer_Timeout(void)
{
	ir_TimerID = INVALID_TIMER_ID;
	switch (ADC_Step)
	{
		case 0:
		case 1:
			ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH3 | ADC_CTL_IE);
			break;
		case 2:
		case 3:
			ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH2 | ADC_CTL_IE);
			break;
		case 4:
		case 5:
			ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH1 | ADC_CTL_IE);
			break;
		case 6:
		case 7:
			ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH0 | ADC_CTL_IE);
			break;
		default:
			ADC_Step = 0;
			ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH3 | ADC_CTL_IE);
			break;
	}
	ROM_ADCProcessorTrigger(ADC0_BASE, 2);

}
Example #2
0
//*****************************************************************************
//
// 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();
}
Example #3
0
static void IR_Timer_Timeout(void)
{
	switch (ADC_Step)
	{
		case 0:
			ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH3 | ADC_CTL_IE);
			break;
		case 1:
			ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH2 | ADC_CTL_IE);
			break;
		case 2:
			ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH1 | ADC_CTL_IE);
			break;
		case 3:
			ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH0 | ADC_CTL_IE);
			break;
		default:
			ADC_Step = 0;
			ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_END | ADC_CTL_CH3 | ADC_CTL_IE);
			break;
	}
	ROM_ADCProcessorTrigger(ADC0_BASE, 2);
}
Example #4
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);
		}
	}
}
void BattSense_Timer3ISR(void)
{
	ROM_TimerIntClear(TIMER3_BASE, TIMER_TIMA_TIMEOUT);
	ROM_ADCProcessorTrigger(ADC0_BASE, 3);
}
Example #6
0
void BattSenseTimerTimout(void)
{
	ROM_ADCProcessorTrigger(ADC1_BASE, 3);
}
Example #7
0
void StartLightSensor(void) {
	ROM_ADCProcessorTrigger(ADC0_BASE, 3);
}
Example #8
0
void TimerTickBatt(void)
{
	ROM_TimerIntClear(TIMER3_BASE, TIMER_TIMA_TIMEOUT);
	ROM_ADCProcessorTrigger(ADC1_BASE, 3);
}
Example #9
0
int main(void) {
	
	volatile uint32_t valore = 0, i, blink = 0, contatore, lampeggio_led;
	volatile int32_t arrot;
	volatile int16_t val1 = 0, x, y, z;
	distanza DIST;

	//--------------------------//
	///definizione strutture/////
	//-------------------------//

	//volatile double d = 1.9845637456;
	gyro G;
	accelerazione A;
	cinematica CIN;
	/// servono differenti PID, almeno uno per la rotazione ed uno per lo spostamento
	/// per la rotazione sarebbero interessante usarne 2, uno per la ortazione soft ed uno per la rotazione
	/// brusca.
	pid CTRL[3], * pidPtr;
	/// descrittore della sintassi dei comandi
	syn_stat synSTATO;
	/// modulo zigbee per telemetria
	xbee XB;
	/// pwm servi e motori
	pwm PWM, pwmServi;
	/// struttura del sensore di colore
	colore COL;
	/// sensore di temperatura ad infrarossi
	temperatura TEMP;
	TEMPER sensIR;
	/// indormazioni sul sopravvissuto
	survivor SUR;
	//inizializzazione struttura per qei
	qei QEI;
	/// oggetto che riallinea il mezzo
	allineamento AL;

	/// disabilita le interruzioni
	DI();
	pidPtr = CTRL;
	dPtr = &DIST;
	TEMPptr =  &TEMP;
	CIN.Aptr = &A;
	CIN.distPTR = &DIST;
	CIN.vel = 0.0;

	dati DATA;

	//passaggio degli indirizzi delle strutture alla struttura generale
	dati_a_struttura(&G, &DIST, &CIN, &COL, &TEMP, &SUR, &DATA);

	/// commento per provare il merge su server remoto

	/// setup di base
	setupMCU();
	/// imposta i parametri del PID
	setupPID(CTRL);
	/// imposta le UART
	setupUART();
    //inizializzo l'i2c
	InitI2C0();
	/// messaggio d'inizio
	PRINT_WELCOME();
	/// inizializza il giroscopio
	initGyro(&G, Z_AXIS);
	/// inizializza il timer 0 e genera un tick da 10 ms
	initTimer0(10, &G);
	/// inizializza il timer 1
	initTimer1(100);
	/// inizializza il contatore della persistenza del comando
	synSTATO.tick = 0;
	/// inizializza il pwm
	pwmMotInit(&PWM);
	// TODO: //pwmServoInit (&pwmServi);
	/// inizializza l'adc e lo prepara a funzionare ad interruzioni.
	initAdc(&DIST);
	/// reset dell'automa di analisi della sintassi
	resetAutoma(&synSTATO);

	//servo = (pwm *) &pwmServi;

	/// iniziailizzazione del lettore encoder
	qei_init(&QEI);

	/// abilita le interruzioni
	EI();
	/// attende che il sensore vada a regime
	if (G.IsPresent == OK){
		PRINTF("\nAzzeramento assi giroscopio\n");
		while (blink < 70){
			if (procCom == 1){
				procCom = 0;
				blink++;
			}
		}
		blink = 0;
		/// azzeramento degli assi
		azzeraAssi(&G);
	}

	/// test della presenza del modulo zig-bee
	/// il modulo zig-be si attiva con al sequnza '+++' e risponde con 'OK' (maiuscolo)
	if (testXbee() == 0){
		// ok;
		XB.present = 1;
		PRINTF("Modulo xbee presente.\n");
	}
	else{
		XB.present = 0;
		PRINTF("Modulo xbee non presente.\n");
	}

	pwm_power(&PWM);
	contatore = 0;

	//// inizializza l'accelrometro
	//stato =  writeI2CByte(CTRL_REG1_A, ODR1 + ODR0 + ZaxEN + YaxEN + XaxEN);
	// scrivo nel registro 0x20 il valore 0x0F, cioe' banda minima, modulo on e assi on
	/// sintassi: indirizzo slave, num parm, indirizzo reg, valore da scrivere
	//I2CSend(ACCEL_ADDR, 2, CTRL_REG1_A, ODR1 + ODR0 + ZaxEN + YaxEN + XaxEN);
	A.isPresent = testAccel();
	if (A.isPresent)
		impostaAccel(&A);

	/// taratura sul sensore di luminosita'
	whiteBal(&COL);
	/// taratura del sensore di temepratura
	taraturaTemp(&TEMP);

	///
	qei_test(&QEI);
	/// task principale
	while(1){

		/// invia la risposta per i comandi di rotazione, quando sono stati eseguiti
		if(pidPtr->rispondi == TRUE){
			rispostaRotazione(pidPtr, &synSTATO);
			pidPtr->rispondi = FALSE;
		}

		if (procCom == 1 ){
			//UARTCharPutNonBlocking(UART1_BASE, 'c');
			procCom = 0;
			contatore++;
			lampeggio_led++;


			if(lampeggio_led >= 50)
			{
				lampeggio_led = 0;

				 if(DATA.surPtr->isSurvivor == TRUE )
				{
					if(HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + (GREEN_LED << 2))) != GREEN_LED )
						HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + (RED_LED << 2))) = 0;

					HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + (GREEN_LED | RED_LED << 2))) ^=  GREEN_LED | RED_LED;


				}

				HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + (GREEN_LED << 2))) ^=  GREEN_LED;
			}


			/*  LETTURA DEL COMANDO */

			/// restituisce l'indirizzo del PID da utilizzare nel successivo processo di calcolo
			pidPtr =  leggiComando(&synSTATO, CTRL, pidPtr, &DATA);

			/* LETTURA SENSORI  */


			/// effettua i calcoli solo se il giroscopio e' presente
			/// TODO: il PID viene calcolato ongi 10ms oppure ogni 20ms? Come è meglio?


			/* misura gli encoder e calcola spostameti e velocità */
			/* misura i sensori di distanza */
			if (DIST.run == true)
				/// TODO controllare se riesce a funzionare mentre legge le accelerazioni su I2C
				ROM_ADCProcessorTrigger(ADC0_BASE, 0);

			/// misura i dati forniti dall'accelerometro se disponibili
			if(A.isPresent)
				misuraAccelerazioni(&A);
			/// le misure del giroscopio invece sono effettuate solo dall'apposito pid

			/*if(G.IsPresent == OK)
				if( contatore == 1){
					/// ogni 10 ms effettua il calcolo del PID
					contatore = 0;
					HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + (GPIO_PIN_0 << 2))) |=  GPIO_PIN_0;
					PID(&G, pidPtr, &PWM, &CIN);
					setXPWM(&CTRL[1], &PWM);
					procCom = 0;
					HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + (GPIO_PIN_0 << 2))) &=  ~GPIO_PIN_0;
					blink++;
					/// lampeggio del led con periodo di 2 s.
					if (blink >= 100){
						HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + ((GPIO_PIN_2 | GPIO_PIN_1) << 2))) = 0;
						HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + (GPIO_PIN_3 << 2))) ^= GPIO_PIN_3;
						blink = 0;
					}
				///provvede ad integrare la misura della velcita' angolare ogni 10 ms
				//misuraAngoli(&G);
				//PRINTF("asse x: %d\t", G.pitch);
				//PRINTF("\tasse y: %d\t", G.roll);
				//PRINTF("\tasse z: %d\n", G.yaw);
				//PRINTF("uscita PID: %d\n", C.uscita);
			}*/

			/* RISPOSTA AL COMANDO */
			inviaSensore(&synSTATO, &DATA);

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

}