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

CCS/MSP432P401R: PWM on two pin

$
0
0

Part Number:MSP432P401R

Tool/software: Code Composer Studio

I want to create a program that would give me on the pin 5.6 and 2.4 the PWM signal, I tried to implement this but with not succes because my code is not working properly.
Can someone help me with an example of a program to provide P.W.M. while the pins 2.4 and 5.6?

My code is:

/* DriverLib Includes */
#include "driverlib.h"

/* Standard Includes */
#include <stdint.h>

#include <stdbool.h>

/* Timer_A PWM Configuration Parameter */
Timer_A_PWMConfig pwmConfig =
{
		//uint_fast16_t clockSource;
        TIMER_A_CLOCKSOURCE_SMCLK,
		//uint_fast16_t clockSourceDivider;
        TIMER_A_CLOCKSOURCE_DIVIDER_1,
		//uint_fast16_t timerPeriod;
		1300,
    	//uint_fast16_t compareRegister;
        TIMER_A_CAPTURECOMPARE_REGISTER_1,
		//uint_fast16_t compareOutputMode;
        TIMER_A_OUTPUTMODE_RESET_SET,
        //uint_fast16_t dutyCycle;
        10
};

/* Timer_A PWM Configuration Parameter */
Timer_A_PWMConfig pwmConfig2 =
{
		//uint_fast16_t clockSource;
        TIMER_A_CLOCKSOURCE_SMCLK,
		//uint_fast16_t clockSourceDivider;
        TIMER_A_CLOCKSOURCE_DIVIDER_1,
		//uint_fast16_t timerPeriod;
		1300,
    	//uint_fast16_t compareRegister;
        TIMER_A_CAPTURECOMPARE_REGISTER_1,
		//uint_fast16_t compareOutputMode;
        TIMER_A_OUTPUTMODE_RESET_SET,
        //uint_fast16_t dutyCycle;
        10
};

int main(void)
{
    /* Halting the watchdog */
    MAP_WDT_A_holdTimer();

    int a,b,c,directie,dir;

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

    // PWM - PIN - 5.6 - TIMER_A2_BASE
    // PWM - PIN - 2.4 - TIMER_A0_BASE
    // Configuring GPIO2.4 as peripheral output for PWM
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P5, GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION);
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION);

    // Configuring Timer_A to have a period of approximately 20ms
    MAP_Timer_A_generatePWM(TIMER_A2_BASE, &pwmConfig);
    MAP_Timer_A_generatePWM(TIMER_A2_BASE, &pwmConfig2);

    b = 40;
    c = 30;
	directie = 0;
	dir = 0;

    while (1)
    {
    	MAP_Timer_A_generatePWM(TIMER_A2_BASE, &pwmConfig);
    	MAP_Timer_A_generatePWM(TIMER_A2_BASE, &pwmConfig2);

    	// -----------------------------------------
    	if (dir == 2)
    	{
    		c = c - 10;
    		pwmConfig2.dutyCycle = c;
    		if(c == 40) {
    			dir = 0;
    		}

    		for(a=620; a>0; a--);
    	}
    	else
    	{
    		pwmConfig2.dutyCycle = c;
    		c = c + 10;
    		if(c == 100) {
    			dir = 2;
    		}

    		for(a=620; a>0; a--);
    	}
    	// -----------------------------------------
    	if (directie == 1)
    	{
    		b = b - 10;
    		pwmConfig.dutyCycle = b;
    		if(b == 40) {
    			directie = 0;
    		}

    		for(a=620; a>0; a--);
    	}
    	else
    	{
    		pwmConfig.dutyCycle = b;
    		b = b + 10;
    		if(b == 170) {		
    			directie = 1;
    		}

    		for(a=620; a>0; a--);
    	}
    	// -----------------------------------------
    }
}


Viewing all articles
Browse latest Browse all 262198

Trending Articles



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