int main(void)
{	
	//Setting the clock frequency
	
	SysCtlClockSet(SYSCTL_SYSDIV_3 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);  // Refer to tm4c123gh6pm data sheet page 223
																																													 // and TivaWare™ Peripheral Driver Library refrence page: 489 for more options
																																													 // In this case the clock freq is 66.67 MHz
	
	
	//Get the clock
	Clock = SysCtlClockGet();           //In case you want to confirm the clock frequency
	
	
	//Setup peripherals
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);																							// enable timer0
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);																							// enable PORTF
	
	//set outputs
  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_3)); 			// set pins of portf as output
	
	//Enable global interrupt
	IntMasterEnable();
	
	//Timer0 configuration
	Timer0Conf();
	
	while(1){
		SysCtlSleep(); 				
	}
	
	
}
Пример #2
0
//*****************************************************************************
//
//! The application main entry point.
//!
//! This is where the program starts running.  It initializes the system
//! clock.  Then it calls the User Interface module initialization function,
//! UIInit().  This will cause all the other modules to be initialized.
//! Finally, it enters an infinite loop, sleeping while waiting for an
//! interrupt to occur.
//!
//! \return None.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set cpu clock for 50 MHz
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_6MHZ);

    //
    // Enable peripherals to operate when CPU is in sleep
    //
    SysCtlPeripheralClockGating(true);

    //
    // Initialize the user interface,
    // on-board and off-board
    //
    UIInit();

    //
    // Loop forever.  All the real work is done in interrupt handlers.
    //
    while(1)
    {
        //
        // Put the processor to sleep when it is waiting for an
        // interrupt to occur.
        //
        SysCtlSleep();
    }
}
Пример #3
0
// With this setup it would seem like main() must be the first function in this file, otherwise
// the wrong function gets called on reset.
int main(void) {
    unsigned long ulLoop;
    char buffer[32];

    SecondsCount = 0;
    minutesCount = 0;

    initHW();

    // Start the OLED display and write a message on it

    RIT128x96x4Init(ulSSI_FREQUENCY);
    RIT128x96x4StringDraw("Hi :)", 0, 0, mainFULL_SCALE);
    RIT128x96x4StringDraw("Running Timers...", 0, 10, mainFULL_SCALE);

    //
    // Loop forever.
    //
    while (1) {

        //
        // Turn on the LED.
        //
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0);
        // GPIO_PORTF_DATA_R |= 0x01;

        RIT128x96x4StringDraw("               ", 50, 50, mainFULL_SCALE);
        itoa(SecondsCount, buffer, 10);
        RIT128x96x4StringDraw(buffer, 50, 50, mainFULL_SCALE);

        RIT128x96x4StringDraw("               ", 50, 60, mainFULL_SCALE);
        itoa(minutesCount, buffer, 10);
        RIT128x96x4StringDraw(buffer, 50, 60, mainFULL_SCALE);

        SysCtlSleep();

        //
        // Turn off the LED.
        //
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);

        //
        // Delay for a bit.
        //
        for (ulLoop = 0; ulLoop < 200000; ulLoop++) {
        }
    }

    return 0;
}
Пример #4
0
//*****************************************************************************
//
//! \brief  Wdt api wdt wakeup test.
//!
//! \return None.
//
//*****************************************************************************
static void wdt_WakeUp_test(void)
{
    unsigned long ulTemp;
    
    //
    // Set WatchDog Timer(WDT)'s Timer Interval.
    //  
    WDTimerInit(WDT_INTERVAL_2_14T);
    
    //
    // Enter WDT function of wake up
    //    
    WDTimerFunctionEnable(WDT_WAKEUP_FUNCTION | WDT_INT_FUNCTION);
    
    xIntEnable(INT_WDT);
    
    //
    // Install WDT callback function
    //
    WDTimerIntCallbackInit(WDTCallbackSW);

    //
    // Start the WDT
    //
    WDTimerEnable();
    ulTemp = xHWREG(WDT_WTCR);
    
    //
    // Enter power down mode
    //
    SysCtlSleep();
    SysCtlDelay(200);
    
    ulTemp = xHWREG(WDT_WTCR);
    TestAssert(WDT_WTCR_WTWKF == (ulTemp & WDT_WTCR_WTWKF), "WDT API error!");
}
Пример #5
0
// ============================== POWER MANAGEMENT ==========================
static void enterSleepMode( void ){
	SysCtlSleep();
}
Пример #6
0
//*****************************************************************************
//
// This example demonstrates how to use the uDMA controller to transfer data
// between memory buffers and to and from a peripheral, in this case a UART.
// The uDMA controller is configured to repeatedly transfer a block of data
// from one memory buffer to another.  It is also set up to repeatedly copy a
// block of data from a buffer to the UART output.  The UART data is looped
// back so the same data is received, and the uDMA controlled is configured to
// continuously receive the UART data using ping-pong buffers.
//
// The processor is put to sleep when it is not doing anything, and this allows
// collection of CPU usage data to see how much CPU is being used while the
// data transfers are ongoing.
//
//*****************************************************************************
int
main(void)
{
    static unsigned long ulPrevSeconds;
    static unsigned long ulPrevXferCount;
    static unsigned long ulPrevUARTCount = 0;
    static char cStrBuf[40];
    tRectangle sRect;
    unsigned long ulCenterX;
    unsigned long ulXfersCompleted;
    unsigned long ulBytesTransferred;

    //
    // Set the clocking to run from the PLL at 50 MHz.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Set the device pinout appropriately for this board.
    //
    PinoutSet();

    //
    // Enable peripherals to operate when CPU is in sleep.
    //
    ROM_SysCtlPeripheralClockGating(true);

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the graphics context and find the middle X coordinate.
    //
    GrContextInit(&g_sContext, &g_sKitronix320x240x16_SSD2119);

    //
    // Get the center X coordinate of the screen, since it is used a lot.
    //
    ulCenterX = GrContextDpyWidthGet(&g_sContext) / 2;

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = 23;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_pFontCm20);
    GrStringDrawCentered(&g_sContext, "udma-demo", -1, ulCenterX, 11, 0);

    //
    // Show the clock frequency on the display.
    //
    GrContextFontSet(&g_sContext, g_pFontCmss18b);
    usnprintf(cStrBuf, sizeof(cStrBuf), "Stellaris @ %u MHz",
              SysCtlClockGet() / 1000000);
    GrStringDrawCentered(&g_sContext, cStrBuf, -1, ulCenterX, 40, 0);

    //
    // Show static text and field labels on the display.
    //
    GrStringDrawCentered(&g_sContext, "uDMA Mem Transfers", -1,
                         ulCenterX, 62, 0);
    GrStringDrawCentered(&g_sContext, "uDMA UART Transfers", -1,
                         ulCenterX, 84, 0);

    //
    // Configure SysTick to occur 100 times per second, to use as a time
    // reference.  Enable SysTick to generate interrupts.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // Initialize the CPU usage measurement routine.
    //
    CPUUsageInit(SysCtlClockGet(), SYSTICKS_PER_SECOND, 2);

    //
    // Enable the uDMA controller at the system level.  Enable it to continue
    // to run while the processor is in sleep.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA);

    //
    // Enable the uDMA controller error interrupt.  This interrupt will occur
    // if there is a bus error during a transfer.
    //
    ROM_IntEnable(INT_UDMAERR);

    //
    // Enable the uDMA controller.
    //
    ROM_uDMAEnable();

    //
    // Point at the control table to use for channel control structures.
    //
    ROM_uDMAControlBaseSet(ucControlTable);

    //
    // Initialize the uDMA memory to memory transfers.
    //
    InitSWTransfer();

    //
    // Initialize the uDMA UART transfers.
    //
    InitUART0Transfer();

    //
    // Remember the current SysTick seconds count.
    //
    ulPrevSeconds = g_ulSeconds;

    //
    // Remember the current count of memory buffer transfers.
    //
    ulPrevXferCount = g_ulMemXferCount;

    //
    // Loop until the button is pressed.  The processor is put to sleep
    // in this loop so that CPU utilization can be measured.
    //
    while(1)
    {
        //
        // Check to see if one second has elapsed.  If so, the make some
        // updates.
        //
        if(g_ulSeconds != ulPrevSeconds)
        {
            //
            // Print a message to the display showing the CPU usage percent.
            // The fractional part of the percent value is ignored.
            //
            usnprintf(cStrBuf, sizeof(cStrBuf), "CPU utilization %2u%%",
                      g_ulCPUUsage >> 16);
            GrStringDrawCentered(&g_sContext, cStrBuf, -1, ulCenterX, 160, 1);

            //
            // Tell the user how many seconds we have to go before ending.
            //
            usnprintf(cStrBuf, sizeof(cStrBuf), " Test ends in %d seconds ",
                      10 - g_ulSeconds);
            GrStringDrawCentered(&g_sContext, cStrBuf, -1, ulCenterX, 120, 1);

            //
            // Remember the new seconds count.
            //
            ulPrevSeconds = g_ulSeconds;

            //
            // Calculate how many memory transfers have occurred since the last
            // second.
            //
            ulXfersCompleted = g_ulMemXferCount - ulPrevXferCount;

            //
            // Remember the new transfer count.
            //
            ulPrevXferCount = g_ulMemXferCount;

            //
            // Compute how many bytes were transferred in the memory transfer
            // since the last second.
            //
            ulBytesTransferred = ulXfersCompleted * MEM_BUFFER_SIZE * 4;

            //
            // Print a message to the display showing the memory transfer rate.
            //
            usnprintf(cStrBuf, sizeof(cStrBuf), " %8u Bytes/Sec ",
                      ulBytesTransferred);
            GrStringDrawCentered(&g_sContext, cStrBuf, -1, ulCenterX, 182, 1);

            //
            // Calculate how many UART transfers have occurred since the last
            // second.
            //
            ulXfersCompleted = (g_ulRxBufACount + g_ulRxBufBCount -
                                ulPrevUARTCount);

            //
            // Remember the new UART transfer count.
            //
            ulPrevUARTCount = g_ulRxBufACount + g_ulRxBufBCount;

            //
            // Compute how many bytes were transferred by the UART.  The number
            // of bytes received is multiplied by 2 so that the TX bytes
            // transferred are also accounted for.
            //
            ulBytesTransferred = ulXfersCompleted * UART_RXBUF_SIZE * 2;

            //
            // Print a message to the display showing the UART transfer rate.
            //
            usnprintf(cStrBuf, sizeof(cStrBuf), " %8u Bytes/Sec ",
                      ulBytesTransferred);
            GrStringDrawCentered(&g_sContext, cStrBuf, -1, ulCenterX, 204, 1);
        }

        //
        // Put the processor to sleep if there is nothing to do.  This allows
        // the CPU usage routine to measure the number of free CPU cycles.
        // If the processor is sleeping a lot, it can be hard to connect to
        // the target with the debugger.
        //
        SysCtlSleep();

        //
        // See if we have run long enough and exit the loop if so.
        //
        if(g_ulSeconds >= 10)
        {
            break;
        }
    }
Пример #7
0
//*****************************************************************************
//
// Main application entry point.
//
//*****************************************************************************
int
main(void)
{
	int_fast32_t i32IPart[16], i32FPart[16];
	uint_fast32_t ui32Idx, ui32CompDCMStarted;
	float pfData[16];
	float *pfAccel, *pfGyro, *pfMag, *pfEulers, *pfQuaternion;

	//
	// Initialize convenience pointers that clean up and clarify the code
	// meaning. We want all the data in a single contiguous array so that
	// we can make our pretty printing easier later.
	//
	pfAccel = pfData;
	pfGyro = pfData + 3;
	pfMag = pfData + 6;
	pfEulers = pfData + 9;
	pfQuaternion = pfData + 12;

	//
	// Setup the system clock to run at 40 Mhz from PLL with crystal reference
	//
	SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
			SYSCTL_OSC_MAIN);

	//
	// Enable port B used for motion interrupt.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

	//
	// Initialize the UART.
	//
	ConfigureUART();

	//
	// Print the welcome message to the terminal.
	//
	UARTprintf("\033[2JMPU9150 Raw Example\n");

	//
	// Set the color to a purple approximation.
	//
	g_pui32Colors[RED] = 0x8000;
	g_pui32Colors[BLUE] = 0x8000;
	g_pui32Colors[GREEN] = 0x0000;

	//
	// Initialize RGB driver.
	//
	RGBInit(0);
	RGBColorSet(g_pui32Colors);
	RGBIntensitySet(0.5f);
	RGBEnable();

	//
	// The I2C3 peripheral must be enabled before use.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

	//
	// Configure the pin muxing for I2C3 functions on port D0 and D1.
	//
	GPIOPinConfigure(GPIO_PD0_I2C3SCL);
	GPIOPinConfigure(GPIO_PD1_I2C3SDA);

	//
	// Select the I2C function for these pins.  This function will also
	// configure the GPIO pins pins for I2C operation, setting them to
	// open-drain operation with weak pull-ups.  Consult the data sheet
	// to see which functions are allocated per pin.
	//
	GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
	GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

	//
	// Configure and Enable the GPIO interrupt. Used for INT signal from the
	// MPU9150
	//
	GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
	GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2);
	GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE);
	IntEnable(INT_GPIOB);

	//
	// Keep only some parts of the systems running while in sleep mode.
	// GPIOB is for the MPU9150 interrupt pin.
	// UART0 is the virtual serial port
	// TIMER0, TIMER1 and WTIMER5 are used by the RGB driver
	// I2C3 is the I2C interface to the ISL29023
	//
	SysCtlPeripheralClockGating(true);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER1);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C3);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER5);

	//
	// Enable interrupts to the processor.
	//
	IntMasterEnable();

	//
	// Initialize I2C3 peripheral.
	//
	I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
			SysCtlClockGet());

	//
	// Initialize the MPU9150 Driver.
	//
	MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS,
			MPU9150AppCallback, &g_sMPU9150Inst);

	//
	// Wait for transaction to complete
	//
	MPU9150AppI2CWait(__FILE__, __LINE__);

	//
	// Write application specifice sensor configuration such as filter settings
	// and sensor range settings.
	//
	g_sMPU9150Inst.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98;
	g_sMPU9150Inst.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250;
	g_sMPU9150Inst.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ |
			MPU9150_ACCEL_CONFIG_AFS_SEL_2G);
	MPU9150Write(&g_sMPU9150Inst, MPU9150_O_CONFIG, g_sMPU9150Inst.pui8Data, 3,
			MPU9150AppCallback, &g_sMPU9150Inst);

	//
	// Wait for transaction to complete
	//
	MPU9150AppI2CWait(__FILE__, __LINE__);

	//
	// Configure the data ready interrupt pin output of the MPU9150.
	//
	g_sMPU9150Inst.pui8Data[0] = MPU9150_INT_PIN_CFG_INT_LEVEL |
			MPU9150_INT_PIN_CFG_INT_RD_CLEAR |
			MPU9150_INT_PIN_CFG_LATCH_INT_EN;
	g_sMPU9150Inst.pui8Data[1] = MPU9150_INT_ENABLE_DATA_RDY_EN;
	MPU9150Write(&g_sMPU9150Inst, MPU9150_O_INT_PIN_CFG,
			g_sMPU9150Inst.pui8Data, 2, MPU9150AppCallback,
			&g_sMPU9150Inst);

	//
	// Wait for transaction to complete
	//
	MPU9150AppI2CWait(__FILE__, __LINE__);

	//
	// Initialize the DCM system. 50 hz sample rate.
	// accel weight = .2, gyro weight = .8, mag weight = .2
	//
	CompDCMInit(&g_sCompDCMInst, 1.0f / 50.0f, 0.2f, 0.6f, 0.2f);

	UARTprintf("\033[2J\033[H");
	UARTprintf("MPU9150 9-Axis Simple Data Application Example\n\n");
	UARTprintf("\033[20GX\033[31G|\033[43GY\033[54G|\033[66GZ\n\n");
	UARTprintf("Accel\033[8G|\033[31G|\033[54G|\n\n");
	UARTprintf("Gyro\033[8G|\033[31G|\033[54G|\n\n");
	UARTprintf("Mag\033[8G|\033[31G|\033[54G|\n\n");
	UARTprintf("\n\033[20GRoll\033[31G|\033[43GPitch\033[54G|\033[66GYaw\n\n");
	UARTprintf("Eulers\033[8G|\033[31G|\033[54G|\n\n");

	UARTprintf("\n\033[17GQ1\033[26G|\033[35GQ2\033[44G|\033[53GQ3\033[62G|"
			"\033[71GQ4\n\n");
	UARTprintf("Q\033[8G|\033[26G|\033[44G|\033[62G|\n\n");

	//
	// Enable blinking indicates config finished successfully
	//
	RGBBlinkRateSet(1.0f);

	ui32CompDCMStarted = 0;

	while(1)
	{
		//
		// Go to sleep mode while waiting for data ready.
		//
		while(!g_vui8I2CDoneFlag)
		{
			SysCtlSleep();
		}

		//
		// Clear the flag
		//
		g_vui8I2CDoneFlag = 0;

		//
		// Get floating point version of the Accel Data in m/s^2.
		//
		MPU9150DataAccelGetFloat(&g_sMPU9150Inst, pfAccel, pfAccel + 1,
				pfAccel + 2);

		//
		// Get floating point version of angular velocities in rad/sec
		//
		MPU9150DataGyroGetFloat(&g_sMPU9150Inst, pfGyro, pfGyro + 1,
				pfGyro + 2);

		//
		// Get floating point version of magnetic fields strength in tesla
		//
		MPU9150DataMagnetoGetFloat(&g_sMPU9150Inst, pfMag, pfMag + 1,
				pfMag + 2);

		//
		// Check if this is our first data ever.
		//
		if(ui32CompDCMStarted == 0)
		{
			//
			// Set flag indicating that DCM is started.
			// Perform the seeding of the DCM with the first data set.
			//
			ui32CompDCMStarted = 1;
			CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1],
					pfMag[2]);
			CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1],
					pfAccel[2]);
			CompDCMGyroUpdate(&g_sCompDCMInst, pfGyro[0], pfGyro[1],
					pfGyro[2]);
			CompDCMStart(&g_sCompDCMInst);
		}
		else
		{
			//
			// DCM Is already started.  Perform the incremental update.
			//
			CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1],
					pfMag[2]);
			CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1],
					pfAccel[2]);
			CompDCMGyroUpdate(&g_sCompDCMInst, -pfGyro[0], -pfGyro[1],
					-pfGyro[2]);
			CompDCMUpdate(&g_sCompDCMInst);
		}

		//
		// Increment the skip counter.  Skip counter is used so we do not
		// overflow the UART with data.
		//
		g_ui32PrintSkipCounter++;
		if(g_ui32PrintSkipCounter >= PRINT_SKIP_COUNT)
		{
			//
			// Reset skip counter.
			//
			g_ui32PrintSkipCounter = 0;

			//
			// Get Euler data. (Roll Pitch Yaw)
			//
			CompDCMComputeEulers(&g_sCompDCMInst, pfEulers, pfEulers + 1,
					pfEulers + 2);

			//
			// Get Quaternions.
			//
			CompDCMComputeQuaternion(&g_sCompDCMInst, pfQuaternion);

			//
			// convert mag data to micro-tesla for better human interpretation.
			//
			pfMag[0] *= 1e6;
			pfMag[1] *= 1e6;
			pfMag[2] *= 1e6;

			//
			// Convert Eulers to degrees. 180/PI = 57.29...
			// Convert Yaw to 0 to 360 to approximate compass headings.
			//
			pfEulers[0] *= 57.295779513082320876798154814105f;
			pfEulers[1] *= 57.295779513082320876798154814105f;
			pfEulers[2] *= 57.295779513082320876798154814105f;
			if(pfEulers[2] < 0)
			{
				pfEulers[2] += 360.0f;
			}

			//
			// Now drop back to using the data as a single array for the
			// purpose of decomposing the float into a integer part and a
			// fraction (decimal) part.
			//
			for(ui32Idx = 0; ui32Idx < 16; ui32Idx++)
			{
				//
				// Conver float value to a integer truncating the decimal part.
				//
				i32IPart[ui32Idx] = (int32_t) pfData[ui32Idx];

				//
				// Multiply by 1000 to preserve first three decimal values.
				// Truncates at the 3rd decimal place.
				//
				i32FPart[ui32Idx] = (int32_t) (pfData[ui32Idx] * 1000.0f);

				//
				// Subtract off the integer part from this newly formed decimal
				// part.
				//
				i32FPart[ui32Idx] = i32FPart[ui32Idx] -
						(i32IPart[ui32Idx] * 1000);

				//
				// make the decimal part a positive number for display.
				//
				if(i32FPart[ui32Idx] < 0)
				{
					i32FPart[ui32Idx] *= -1;
				}
			}

			//
			// Print the acceleration numbers in the table.
			//
			UARTprintf("\033[5;17H%3d.%03d", i32IPart[0], i32FPart[0]);
			UARTprintf("\033[5;40H%3d.%03d", i32IPart[1], i32FPart[1]);
			UARTprintf("\033[5;63H%3d.%03d", i32IPart[2], i32FPart[2]);

			//
			// Print the angular velocities in the table.
			//
			UARTprintf("\033[7;17H%3d.%03d", i32IPart[3], i32FPart[3]);
			UARTprintf("\033[7;40H%3d.%03d", i32IPart[4], i32FPart[4]);
			UARTprintf("\033[7;63H%3d.%03d", i32IPart[5], i32FPart[5]);

			//
			// Print the magnetic data in the table.
			//
			UARTprintf("\033[9;17H%3d.%03d", i32IPart[6], i32FPart[6]);
			UARTprintf("\033[9;40H%3d.%03d", i32IPart[7], i32FPart[7]);
			UARTprintf("\033[9;63H%3d.%03d", i32IPart[8], i32FPart[8]);

			//
			// Print the Eulers in a table.
			//
			UARTprintf("\033[14;17H%3d.%03d", i32IPart[9], i32FPart[9]);
			UARTprintf("\033[14;40H%3d.%03d", i32IPart[10], i32FPart[10]);
			UARTprintf("\033[14;63H%3d.%03d", i32IPart[11], i32FPart[11]);

			//
			// Print the quaternions in a table format.
			//
			UARTprintf("\033[19;14H%3d.%03d", i32IPart[12], i32FPart[12]);
			UARTprintf("\033[19;32H%3d.%03d", i32IPart[13], i32FPart[13]);
			UARTprintf("\033[19;50H%3d.%03d", i32IPart[14], i32FPart[14]);
			UARTprintf("\033[19;68H%3d.%03d", i32IPart[15], i32FPart[15]);

		}
	}
}
Пример #8
0
int main(void)
{
	//========= Peripheral Enable and Setup ===========//
	setup_LCD(); //LCD Screen setup
	setup_tmp36(); //TMP36 ADC thermometer setup


	setup_GPS(); //GPS Pin Setup
	setup_microSD(); //MicroSD Pin Setup
	setupTMP102();  
	setup_PID(&pid);
	setupBMS();
	setup_pwm();

	//Setup the buttons
	
	setup_buttonInterrupts();
	sleepEnablePeripherals();
	setup_timerInterrupt();

	
	//========= Peripheral enable and run ============//
	enable_LCD(); //Start LCD Commmunication
	enable_GPS(); //Start GPS Communication
	clearDisplay(); //Refresh Display



	while(1)
	{	
		//Listen for the GPS Data
		listen_GPS();
		//Open the datalog file for writing
		open_datalog();

		//Obtain vehicle speed
		char *velocity;
		char velocityArray[] = "000";
		
		//velocity = velocityArray;
		velocity = getVelocity();
		//Convert string to int
		int speedInteger = atoi(velocity);
		//Convert knots to mph

		
		speedInteger = 1.15 * speedInteger;
		//Return to string
		sprintf(velocity, "%i", speedInteger);
		// velocity = "50";
		selectLineOne();
		//Show velocity
		putPhrase("V:");
		putPhrase(velocity);

		//Analog Temperature Sensor
		int anag_tempValue = get_analog_temp();
		sprintf(anag_temp, "%i", anag_tempValue);

		//Digital Temperature Sensor
		int digi_tempValue = getTemperature();
		sprintf(digi_temp, "%i", digi_tempValue);

		//Get BMS Level
		char load[] = "89";
		char *load_value;
		load_value = load;
		//-------BMS Communication------
		sendStartSequence();
		getDataString();
		load_value = getLoad();
		//------------------------------

		

			
		//If Cruise Control is on
		if(enableSys)
		{	
			//If initialized
			if(obtain_speed)
			{	//Debouncing
				//SysCtlDelay(533333);
				obtain_speed = 0;
				clearDisplay();

				//Get set velocity
				set_velocity = 10;
			}

			//If driver increases set speed
			if(incr_speed)
			{	
				//SysCtlDelay(533333);

				incr_speed = 0;
				set_velocity += 1;
			}

			//if driver decresaes set speed
			else if(decr_speed)
			{	
				//SysCtlDelay(533333);
				decr_speed = 0;
				set_velocity -= 1;
			}

			//==============PID Portion of the Main Loop ==============//
			float process_value = atof(velocity); //Convert String to Int
			float error = set_velocity - process_value; //Calculate error
			float u_t = UpdatePID(&pid, error, 1.0); //Feed error to the PID
			
			uint32_t duty_cycle = u_t*scaleFactor;
			if(duty_cycle < 950){
				duty_cycle = 50;
			}
			else if(duty_cycle > 0){
				duty_cycle = 950;
			}
			pwm_out(1000, duty_cycle); //Scale and output the PID output

			//====================================================//

			//Show other essentials to the LCD
			putPhrase("mph/"); 

			char set_point[5];
			sprintf(set_point, "%imph", (int) set_velocity);
			putPhrase(set_point);
			putPhrase(" ON"); //Cruise control on

		}

		else
		{
			//Spacer
			putPhrase("mph ");
			putPhrase("Standby  ");

		}

		//Select bottom line
		selectLineTwo();

		//Display analog and digital temperatures
		putPhrase("T:");
		putPhrase(anag_temp);
		putPhrase("/");
		putPhrase(digi_temp);
		putPhrase("C  ");


		//Show Load level
		putPhrase("B:");
		putPhrase(load_value);
		putPhrase("%");

		
		write_datalog(velocity, "ddmm.mmmmmmX", "ddmm.mmmmmX", getTime(), anag_temp, digi_temp, load_value);
		close();

		//Put system in low power mode
		SysCtlSleep();	


}
}
Пример #9
0
//*****************************************************************************
//
// Main loop
//
//*****************************************************************************
int main(void) {

	// Initialize relevant GPIO pins and periodic timer
	InitClocksGPIOAndTimer();

	// Initialize the UART.
	ConfigureUART();

	UARTprintf("Started!\n");


	// Init to shorter period
	ulPeriod = (SysCtlClockGet() * LIGHTS_ON_PERIOD_SEC);
#ifdef RUN_AS_MASTER
	uint32_t ulIdleMinutesLimit = SHORT_IDLE_TIME_MINS;
	int lightSwitchState = 0;
#else
	bool ambienceOn = false;
	bool lightSwitchOn = false;
#endif

	// Set the blue led on at startup. Will shut down in first periodic timer trig.
	setStatusLedState(false);

	while (1) {
#ifdef RUN_AS_MASTER
		if (lightSwitchTrigged) {
			int i, realHit = 1;

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

				SysCtlDelay(SysCtlClockGet() / 1000);

				if (lightSwitchGPIOActive() == 0) {
					realHit = 0;
					break;
				}
			}
			if (realHit) {
				UARTprintf("Light switch hit\n");
				if (lightSwitchState == OFF) {
					lightSwitchState = ON;
					UARTprintf("Switching ON\n");
					SendIRCode(SWITCH_ON);
					rampBottomPWM(PWM_RAMP_UP);

					// Use longer idle period
					ulIdleMinutesLimit = LONG_IDLE_TIME_MINS;
					startIdleDetectionTimer(ulPeriod, true);
				} else {
					lightSwitchState = OFF;
					UARTprintf("Switching OFF\n");
					SendIRCode(SWITCH_OFF);
					rampBottomPWM(PWM_RAMP_DOWN);

					// Use shorter idle period
					ulIdleMinutesLimit = SHORT_IDLE_TIME_MINS;
					startIdleDetectionTimer(ulPeriod, true);
				}
			} else {
				UARTprintf("False hit\n");
			}
			lightSwitchTrigged = 0;

		}

		if (idleTimerTrigged) {
			// idle (no movement detected) timer trigged
			idleTimerTrigged = 0;
			ulIdleMinutes ++;
			if (ulIdleMinutes < ulIdleMinutesLimit)
			{
				startIdleDetectionTimer(ulPeriod, false);
				blink_n(1);
			}
			else
			{
				UARTprintf("Idle timer trigged, turning leds off\n");

				if (motionDetectorGPIOActive()) {
					// Level is still high - let's restart the timer.

					UARTprintf("Level still high, restarting timer\n");
					startIdleDetectionTimer(ulPeriod, true);
				} else {
					setStatusLedState(false);

					// Turn the PMW output off
					SendIRCode(AMBIENCE_OFF);
					rampTopPWM(PWM_RAMP_DOWN);
					if (lightSwitchState == ON)
					{
						SendIRCode(SWITCH_OFF);
						rampBottomPWM(PWM_RAMP_DOWN);
					}
				}
			}
		}

		if (motionDetectorTrigged) {
			// Movement detected

			motionDetectorTrigged = 0;
			UARTprintf("motionDetectorTrigged\n");

			// Send this in any case. Rx shall maintain its own state
			SendIRCode(AMBIENCE_ON);
			if (!idleTimerRunning()) {
				setStatusLedState(true);

				// Turn the PMW output on
				rampTopPWM(PWM_RAMP_UP);
				if (lightSwitchState == ON)
				{
					SendIRCode(SWITCH_ON);
					rampBottomPWM(PWM_RAMP_UP);
				}

				UARTprintf("Starting timer\n");
			} else {
				// Leds are on at this point - no need to set those on again
				UARTprintf("RE-Starting timer\n");
			}

			startIdleDetectionTimer(ulPeriod, true);
		}
		//if (timerTrigged)

		{
			// signal the state using on-board led and UART printouts

			bool gpioActive = motionDetectorGPIOActive();
			if (gpioActive) {
				UARTprintf("Input active (motion detected)\n");
			}
			if (!idleTimerRunning()) {
				UARTprintf("Timer not running\n");
			} else {
				UARTprintf("Timer running for %d\n",
						idleTimerRemainingSecondsGet());
				if (gpioActive) {
					setStatusLedState(true);
				} else {
					setStatusLedState(false);
				}
			}
		}
#else
		UARTprintf("SLAVE LOOP: %d\n", ir_pulse_count);
		if (receivedIRCode != 0) {
			uint32_t _code = receivedIRCode;
			receivedIRCode = 0;
			switch (_code) {
			case AMBIENCE_ON:
				if (!ambienceOn)
				{
					rampTopPWM(PWM_RAMP_UP);
					ambienceOn = true;
				}
				break;

			case AMBIENCE_OFF:
				if (ambienceOn)
				{
					rampTopPWM(PWM_RAMP_DOWN);
					ambienceOn = false;
				}
				break;

			case SWITCH_ON:
				if (!lightSwitchOn)
				{
					rampBottomPWM(PWM_RAMP_UP);
					lightSwitchOn = true;
				}
				break;

			case SWITCH_OFF:
				if (lightSwitchOn)
				{
					rampBottomPWM(PWM_RAMP_DOWN);
					lightSwitchOn = false;
				}
				break;

			default:
				break;
			}

			// Blink out the code
			if (_code < 10)
			{
				// blink_n(_code);
			}
		}
#endif
		//
		// Sleep until next interrupt
		//
		SysCtlSleep();
	}
}
Пример #10
0
int main(void)
{
    long dir;
    unsigned long vel, pos;



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



    //
    // Set up low level I/O for printf()
    //
    llio_init(115200);


    //
    // Set up GPIO for LED
    //
    LED_INIT();



    //
    // Set up QEI peripheral
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

    GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_6);
    QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET |
                QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 0xffffffff);
    QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, SysCtlClockGet() / 10);

    QEIEnable(QEI0_BASE);
    QEIVelocityEnable(QEI0_BASE);



    //
    // Set up GPIO for encoder push switch
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_5);
    GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOIntTypeSet(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_FALLING_EDGE);
    GPIOPortIntRegister(GPIO_PORTC_BASE, SW_IntHandler);
    GPIOPinIntEnable(GPIO_PORTC_BASE, GPIO_PIN_5);




    //
    // Set up the period for the SysTick timer.
    //
    SysTickPeriodSet(SysCtlClockGet() / 10);   // 10Hz SysTick timer


    //
    // Enable the SysTick Interrupt.
    //
    SysTickIntEnable();
    SysTickIntRegister(SysTickIntHandler);

    //
    // Enable SysTick.
    //
    SysTickEnable();

    printf("\r\nEncoder example\r\n");


    //
    // Loop forever.
    //
    while(1)
    {
        SysCtlSleep();              // sleep here till interrupt

        LED_TOGGLE();

        dir = QEIDirectionGet(QEI0_BASE);
        vel = QEIVelocityGet(QEI0_BASE);
        pos = QEIPositionGet(QEI0_BASE);
        printf("%d,%d,%d\r\n", dir, vel, pos);
    }
}
Пример #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();
    }
}
Пример #12
0
// With this setup it would seem like main() must be the first function in this file, otherwise
// the wrong function gets called on reset.
int
main(void)
{
  volatile unsigned long ulLoop;
  volatile int event;

  initHW();

  // Start the OLED display and write a message on it

  RIT128x96x4Init(ulSSI_FREQUENCY);
  RIT128x96x4StringDraw("Hi :)", 0, 0, mainFULL_SCALE);
  RIT128x96x4StringDraw("enter the code ...", 0, 5, mainFULL_SCALE);

  // Wait for the select key to be pressed
  while (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1))
    ;
  // Wait for the select key to be pressed
  while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0))
    ; // Wait for the select key to be pressed
  while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1))
    ; // Wait for the select key to be pressed
  while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2))
    ;
  // Wait for the select key to be pressed
  while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3))
    ;

  //
  // Loop forever.
  //
  while (1)
    {

      // This is where a statemachine could be added
      event = GetKeyEvents(  ReadKeys() );
      if (event == KEY_ENTER)
        RIT128x96x4StringDraw("Enter Pressed", 0, 0, mainFULL_SCALE);
      if (event == KEY_UP)
        RIT128x96x4StringDraw("up Pressed", 0, 0, mainFULL_SCALE);
      if (event == KEY_DOWN)
        RIT128x96x4StringDraw("down Pressed", 0, 0, mainFULL_SCALE);
      if (event == KEY_CANCEL)
        RIT128x96x4StringDraw("cancel Pressed", 0, 0, mainFULL_SCALE);




      //
      // Turn on the LED.
      //
      GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0);
      // GPIO_PORTF_DATA_R |= 0x01;

      //
      // Delay for a bit.
      // This is BAD STYLE (tm) any embedded system should be either free-running or timer based
      for (ulLoop = 0; ulLoop < 200000; ulLoop++)
        {
        }

      //
      // Turn off the LED.
      //
      GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);

      //
      // Delay for a bit.
      //
//      for (ulLoop = 0; ulLoop < 200000; ulLoop++)
//        {
//        }
      SysCtlSleep();
    }

  return 0;
}
Пример #13
0
//Esto se ejecuta cada vez que entra a funcionar la tarea Idle
void vApplicationIdleHook (void)
{
	SysCtlSleep();
}