Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

MSP432P401R: PWM not updating

$
0
0

Part Number:MSP432P401R

I am trying to build a car with obstruction detection using analog output proximity sensors. The problem is whenever I integrate the PWM module for moving the vehicle and the proximity sensors, the PWM does not update (I measured the with an oscilloscope). The weird thing is that whenever I step into the program line by line, the PWM updates but if irun the program it doesnt update.

Below is the code I currently have.

Timer_A_PWMConfig servoConfig =
{
        TIMER_A_CLOCKSOURCE_SMCLK,
        TIMER_A_CLOCKSOURCE_DIVIDER_1,
        1300,
        TIMER_A_CAPTURECOMPARE_REGISTER_1,
        TIMER_A_OUTPUTMODE_RESET_SET,
        94                    //center
};

/* Timer_A  Servo PWM Configuration Parameter */
Timer_A_PWMConfig motorConfig =
{
        TIMER_A_CLOCKSOURCE_SMCLK,
        TIMER_A_CLOCKSOURCE_DIVIDER_1,
        1300,
        TIMER_A_CAPTURECOMPARE_REGISTER_2,
        TIMER_A_OUTPUTMODE_RESET_SET,
        75
};




int main(void)
{
    /* Halting WDT  */
    MAP_WDT_A_holdTimer();
    MAP_Interrupt_disableSleepOnIsrExit();

    /* Zero-filling buffer */
    memset(resultsBuffer, 0x00, 8);

    /* Setting MCLK to REFO at 128Khz for LF mode
     * Setting SMCLK to 64Khz */
    MAP_CS_setReferenceOscillatorFrequency(CS_REFO_128KHZ);
    //MAP_CS_initClockSignal(CS_MCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
    MAP_CS_initClockSignal(CS_SMCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_2);
    MAP_PCM_setPowerState(PCM_AM_LF_VCORE0);

    /* Configuring GPIO2.4 as peripheral output for PWM  and P1.1 for button
     * interrupt */
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4,GPIO_PRIMARY_MODULE_FUNCTION);
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN5,GPIO_PRIMARY_MODULE_FUNCTION);

    /* Configuring Timer_A to have a period of approximately 500ms and
     * an initial duty cycle of 10% of that (3200 ticks)  */
    MAP_Timer_A_generatePWM(TIMER_A0_BASE, &servoConfig);

    /* Configuring Timer_A to have a period of approximately 500ms and
     * an initial duty cycle of 10% of that (3200 ticks)  */
    MAP_Timer_A_generatePWM(TIMER_A0_BASE, &motorConfig);

    /* Configuring GPIO2.4 as peripheral output for PWM  and P1.1 for button
         * interrupt */
        MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4,GPIO_PRIMARY_MODULE_FUNCTION);
        MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN5,GPIO_PRIMARY_MODULE_FUNCTION);




    /* Initializing ADC (MCLK/64/8) */
    MAP_ADC14_enableModule();
    MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_64, ADC_DIVIDER_8,
            0);

    /* Configuring GPIOs for Analog In */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,
            GPIO_PIN5 | GPIO_PIN4 | GPIO_PIN3 | GPIO_PIN2 | GPIO_PIN1
                    | GPIO_PIN0, GPIO_TERTIARY_MODULE_FUNCTION);
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P4,
            GPIO_PIN7 | GPIO_PIN6, GPIO_TERTIARY_MODULE_FUNCTION);
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1);
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);


    /* Configuring ADC Memory (ADC_MEM0 - ADC_MEM7 (A0 - A2)  with repeat)*/
    MAP_ADC14_configureMultiSequenceMode(ADC_MEM0, ADC_MEM2, true);
    MAP_ADC14_configureConversionMemory(ADC_MEM0,
            ADC_VREFPOS_INTBUF_VREFNEG_VSS,
            ADC_INPUT_A0, false);
    MAP_ADC14_configureConversionMemory(ADC_MEM1,
            ADC_VREFPOS_INTBUF_VREFNEG_VSS,
            ADC_INPUT_A1, false);
    MAP_ADC14_configureConversionMemory(ADC_MEM2,
            ADC_VREFPOS_INTBUF_VREFNEG_VSS,
            ADC_INPUT_A6, false);

    /* Enabling the interrupt when a conversion on channel 7 (end of sequence)
     *  is complete and enabling conversions */
    MAP_ADC14_enableInterrupt(ADC_INT2);

    /* Enabling Interrupts */
    MAP_Interrupt_enableInterrupt(INT_ADC14);
    MAP_Interrupt_enableMaster();

    /* Setting up the sample timer to automatically step through the sequence
     * convert.
     */
    MAP_ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION);

    /* Triggering the start of the sample */
    MAP_ADC14_enableConversion();
    MAP_ADC14_toggleConversionTrigger();


    __delay_cycles(20000);

    MAP_Timer_A_generatePWM(TIMER_A0_BASE, &motorConfig);
    motorConfig.dutyCycle = 90;
    /* Going to sleep */
    while (1)
    {
    	//MAP_Timer_A_generatePWM(TIMER_A0_BASE, &motorConfig);
    	/*
        if(ADC_SampleComplete == 1){
        	if((resultsBuffer[0] > 11000) | (resultsBuffer[1] > 11000) | (resultsBuffer[2] > 11000)){
        		motorConfig.dutyCycle = 70;
        		MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1);
        		//MAP_Timer_A_generatePWM(TIMER_A0_BASE, &motorConfig);
        	}
        	else{
        		MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);
        		motorConfig.dutyCycle = 97;
        		// MAP_Timer_A_generatePWM(TIMER_A0_BASE, &motorConfig);
        	}
        }
        */

       // MAP_PCM_gotoLPM0();
    }
}

/* This interrupt is fired whenever a conversion is completed and placed in
 * ADC_MEM7. This signals the end of conversion and the results array is
 * grabbed and placed in resultsBuffer */
void ADC14_IRQHandler(void)
{
    uint64_t status;

    status = MAP_ADC14_getEnabledInterruptStatus();
    ADC_SampleComplete = 0;
    if(status & ADC_INT2)
    {
        resultsBuffer[0] = MAP_ADC14_getResult(ADC_MEM0);
        resultsBuffer[1] = MAP_ADC14_getResult(ADC_MEM1);
        resultsBuffer[2] = MAP_ADC14_getResult(ADC_MEM2);
        ADC_SampleComplete = 1;

        if((resultsBuffer[0] > 11000) | (resultsBuffer[1] > 11000) | (resultsBuffer[2] > 11000)){
        	motorConfig.dutyCycle = 70;
            MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1);
            MAP_Timer_A_generatePWM(TIMER_A0_BASE, &motorConfig);
        }
        else {
        	MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);
            motorConfig.dutyCycle = 97;
            MAP_Timer_A_generatePWM(TIMER_A0_BASE, &motorConfig);
        }
    }
    MAP_ADC14_clearInterruptFlag(status);
}


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>