Ejemplo n.º 1
0
static void prvSetupHardware( void )
{
extern void FPU_enableModule( void );
	
	/* The clocks are not configured here, but inside main_full() and
	main_blinky() as the full demo uses a fast clock and the blinky demo uses
	a slow clock. */

	/* Stop the watchdog timer. */
	MAP_WDT_A_holdTimer();
	
	/* Ensure the FPU is enabled. */
	FPU_enableModule();

	/* Selecting P1.2 and P1.3 in UART mode and P1.0 as output (LED) */
	MAP_GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION );
	MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 );
	MAP_GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 );

	/* Enable S2 and LED2 */
	MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN0 );
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0);
	MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN1 );
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1);
	MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN2 );
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2);

	MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN4);
	MAP_GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN4, GPIO_HIGH_TO_LOW_TRANSITION);
	MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN4);
	MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN4);
	MAP_Interrupt_enableInterrupt(INT_PORT1);

}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
int InitFunction(void)
{
	int err = NONE;

	MAP_WDT_A_holdTimer();

	/* Configuring P6.7 as an input. P1.0 as output and enabling interrupts */
//	MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
	//Setting RGB LED as output
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);

	//Set P6.1 to be the pin interupt
	MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P6, GPIO_PIN1);
	MAP_GPIO_clearInterruptFlag(GPIO_PORT_P6, GPIO_PIN1);
	MAP_GPIO_enableInterrupt(GPIO_PORT_P6, GPIO_PIN1);
	MAP_Interrupt_enableInterrupt(INT_PORT6);

	MAP_Interrupt_enableMaster();

	return err;
}
Ejemplo n.º 3
0
int main(void) 
{
    WDT_A_holdTimer();

    //Configure Timer
    unsigned int dcoFrequency = 3E+6;
    MAP_CS_setDCOFrequency(dcoFrequency);
    MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // ( 1Mhz / 64 ) / (Period = 15625) = 1 second

	////////////////////////////////////////////////////////////////////////////////////////////////////
	//            Buttons init
	////////////////////////////////////////////////////////////////////////////////////////////////////
    // Set switch 1 (S1) as input button (connected to P1.1)
    MAP_GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P1, GPIO_PIN1 );

    // Set switch 2 (S2) as input button (connected to P1.4)
    MAP_GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P1, GPIO_PIN4 );

	////////////////////////////////////////////////////////////////////////////////////////////////////
	//            Timer A 0 and PWM on 2.4
	////////////////////////////////////////////////////////////////////////////////////////////////////

    GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION); //writes 0's in PXSEL registers for pins 1.2 and 1.3
    // Set Timer A period (PWM signal period)
    TA0CCR0 = 10000 ; // i think i wrote this wring, his example he showed in class is is 10000
    // Set Duty cycle
    TA0CCR1 = 0 ; //inital DutyCycle of 0% (we don't want the motor to move unless we push button
    // Set output mode to Reset/Set
    TA0CCTL1 = OUTMOD_7 ;    // Macro which is equal to 0x00e0, defined in msp432p401r.h
        // Initialize Timer A
    TA0CTL = TASSEL__SMCLK | MC__UP | TACLR ;  // this bitwise or’s multiple settings at the same time (this just sets different bits in the register to set these functionalities/settings)

	//Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_UP_MODE);

	////////////////////////////////////////////////////////////////////////////////////////////////////
	//            Timer A 2 and PWM on P5.6
	////////////////////////////////////////////////////////////////////////////////////////////////////

    GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P5, GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION); //writes 0's in PXSEL registers for pins 1.2 and 1.3

    // Set Timer A period (PWM signal period)
    TA2CCR0 = 10000 ; // i think i wrote this wring, his example he showed in class is is 10000
    // Set Duty cycle
    TA2CCR1 = 0 ; //inital DutyCycle of 0% (we don't want the motor to move unless we push button
    // Set output mode to Reset/Set
    TA2CCTL1 = OUTMOD_7 ;    // Macro which is equal to 0x00e0, defined in msp432p401r.h
        // Initialize Timer A
    TA2CTL = TASSEL__SMCLK | MC__UP | TACLR ;  // this bitwise or’s multiple settings at the same time (this just sets different bits in the register to set these functionalities/settings)
    											//Does this start the timer?? (is next line necessary?)

	//Timer_A_startCounter(TIMER_A1_MODULE, TIMER_A_UP_MODE);
	/////////////////////////////////////////////////////////////////////////////////////////////////////
    //Set LED's as outputs and turn off
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0);
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P2,GPIO_PIN0);
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0);
	int countedges1 = 1;
	int countedges2 = 1;



    while(1){
    	//infinite loop

    	////////////////////////////////////////////////////////////////////////////////////////////////////
    	//           Turn one direction
    	////////////////////////////////////////////////////////////////////////////////////////////////////
    	if(GPIO_INPUT_PIN_LOW == MAP_GPIO_getInputPinValue ( GPIO_PORT_P1, GPIO_PIN1 )){

    		//stop timer 2
    		Timer_A_stopTimer(TIMER_A2_MODULE);
    		MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN6);
    		//start timer 1
    		Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_UP_MODE);

    		TA0CCR1 = 1000 * countedges1; //increse Duty Cycle by 10% (period is 10000)

    		if (TA0CCR1 > TA0CCR0){ //if Dutcy Cycle = 100%, go back to 0%
    			TA0CCR1 = 0;
    		}//end nested if
    		if (countedges1>11){
    			countedges1 = 0;
    		}
    			countedges1++;


    		while(GPIO_INPUT_PIN_LOW == MAP_GPIO_getInputPinValue ( GPIO_PORT_P1, GPIO_PIN1 )){
        		MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
        		MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0);

    		}//end nested while
    		MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
    		MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0);
    	}//end switch 1 if
    	else{ //the button is not being pushed so do not spin motor (DutyCycle = 0);
    		TA0CCR1 = 0;
    	}

    	////////////////////////////////////////////////////////////////////////////////////////////////////
    	//           Turn other direction
    	////////////////////////////////////////////////////////////////////////////////////////////////////
    	if(GPIO_INPUT_PIN_LOW == MAP_GPIO_getInputPinValue ( GPIO_PORT_P1, GPIO_PIN4 )){

    		//stop timer 1
    		Timer_A_stopTimer(TIMER_A0_MODULE);
    		MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN4);
    		//start timer 2
    		Timer_A_startCounter(TIMER_A2_MODULE, TIMER_A_UP_MODE);

    		TA2CCR1 = countedges2 * 1000; //increse Duty Cycle by 10% (period is 10000)

    		if (TA2CCR1 > TA2CCR0){ //if Dutcy Cycle = 100%, go back to 0%
    			TA2CCR1 = 0;
    		}//end nested if
    		if (countedges2>11){
    			countedges2 = 0;
    		}
    			countedges2++;

    		while(GPIO_INPUT_PIN_LOW == MAP_GPIO_getInputPinValue ( GPIO_PORT_P1, GPIO_PIN4 )){
        		MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
        		MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0);

    		}//end nested while
    		MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
    		MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0);
    	}//end switch 2 if
    	else{ //the button is not being pushed so do not spin motor (DutyCycle = 0)
    		TA2CCR1 = 0;
    	}

    }//end while
}//end main