Ejemplo n.º 1
0
bool PCM_gotoLPM4(void)
{
    /* Disabling RTC_C and WDT_A */
    WDT_A_holdTimer();
    RTC_C_holdClock();

    /* LPM4 is just LPM3 with WDT_A/RTC_C disabled... */
    return PCM_gotoLPM3();
}
int main(void)
{
    /* Halting WDT */
    WDT_A_holdTimer();
    Interrupt_enableSleepOnIsrExit();
    
    /* Initializing ADC (MCLK/1/1) */
    ADC14_enableModule();
    ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,
            0);

    /* Configuring ADC Memory (ADC_MEM0 A0/A1 Differential) in repeat mode
     * with use of external references */
    ADC14_configureSingleSampleMode(ADC_MEM0, true);
    ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_EXTPOS_VREFNEG_EXTNEG,
            ADC_INPUT_A0, true);

    /* Setting up GPIO pins as analog inputs (and references) */
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,
            GPIO_PIN6 | GPIO_PIN5 | GPIO_PIN4, GPIO_TERTIARY_MODULE_FUNCTION);

    /* Enabling sample timer in auto iteration mode and interrupts*/
    ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION);
    ADC14_enableInterrupt(ADC_INT0);

    /* Enabling Interrupts */
    Interrupt_enableInterrupt(INT_ADC14);
    Interrupt_enableMaster();

    /* Triggering the start of the sample */
    ADC14_enableConversion();
    ADC14_toggleConversionTrigger();

    /* Going to sleep */
    while (1)
    {
        PCM_gotoLPM0();
    }
}
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
int main(void) 
{
    WDT_A_holdTimer();

    while(1);
}
Ejemplo n.º 5
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); // ( 3Mhz / 64 ) / (Period = 46875) = 1 second

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


	////////////////////////////////////////////////////////////////////////////////////////////////////
    //			ADC INITILIZATION P5.5
	////////////////////////////////////////////////////////////////////////////////////////////////////

    /* Initializing ADC */
    MAP_ADC14_enableModule();

    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION); //writes 0's in PXSEL registers for pins 1.2 and 1.3
    MAP_ADC14_setResolution(ADC_10BIT); // initialize to use a 10 Bit ADC
    MAP_ADC14_initModule(ADC_CLOCKSOURCE_SMCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,0);

    /* Configuring ADC Memory */
    MAP_ADC14_configureSingleSampleMode(ADC_MEM0, false); //put results in this 16 bit register location to hold results, false means we are manually triggering
    MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false); //pin 5.5 is tied to channel 0 (A0)
    /* Configuring Sample Timer */
    MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION);

    //Timer A setup
    MAP_Timer_A_configureUpMode(TIMER_A0_MODULE, &upConfig0);
    Interrupt_enableInterrupt(INT_TA0_0);
	Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_UP_MODE);


    /* Enabling/Toggling Conversion */
    MAP_ADC14_enableConversion();
    MAP_ADC14_toggleConversionTrigger();

	////////////////////////////////////////////////////////////////////////////////////////////////////
    //			END ADC
	////////////////////////////////////////////////////////////////////////////////////////////////////



	////////////////////////////////////////////////////////////////////////////////////////////////////
	//            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 = DUTY_CYCLE * 10000; //inital DutyCycle of 0%.. Duty_Cycle is macro
    // 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_A2_MODULE, TIMER_A_UP_MODE);
	////////////////////////////////////////////////////////////////////////////////////////////////////
	//          END Timer A 2 and PWM on 5.6
	////////////////////////////////////////////////////////////////////////////////////////////////////


    Interrupt_enableMaster() ;


    while(1){

    	while(MAP_ADC14_isBusy()==0){ // poll the busy flag. we have a conversion going bc we already triggerted it above, so we are waiting for the conversion to be done, when it is, we are going to call the get result function. this just returns the 16 bit value rsults
    		ADC_result = (uint16_t)MAP_ADC14_getResult(ADC_MEM0); //just goes to memory location takes results and returns the 16 bit value... this just continues to get repopulted.
    		MAP_ADC14_toggleConversionTrigger(); ////once we got the result we start a new conversion and we go back to top and begin wiaitng until its dones again
    	}//end nested while
    }//end inf while
}//end main