Hi, I have this code for my msp 432 and servo-motor sg90, my problem is:
- In the program I use my pin for PWM 2.4 but the when I try to use Another pin for PWM (2.5, 2.6, 2.7, 5.6) THESE pins do not work to PWM implementation on it.
- I can't make loop Between 0 and 180 degrees, I want to have a loop for this position and I try diferent approach but I do not have success, the below code works to make one time movement when I press play and pause button from CCS.
My code:
/******************************************************************************* * * MSP432P401 * MSP432P401 * ---------------------- * /|\| | * | | | * --|RST P2.4 |--> Output PWM * | | * | | * | | * | | * | | * ******************************************************************************/ /* 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; 80 }; int main(void) { /* Halting the watchdog */ MAP_WDT_A_holdTimer(); int a; /* 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 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_A0_BASE, &pwmConfig); /* Sleeping when not in use */ while (1) { // ----------------------------------------- // if(pwmConfig.dutyCycle == 210) // pwmConfig.dutyCycle = 10; // for 0 // else // pwmConfig.dutyCycle = 210; // for 180 // ----------------------------------------- // pwmConfig.dutyCycle = 10; // for 0 // for(a=10000; a>0; a--){ // } // pwmConfig.dutyCycle = 210; // for 180 // ----------------------------------------- MAP_PCM_gotoLPM0(); MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig); } }