Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 62309

Forum Post: RE: MSP 432 SERVO 0 ~ 180 degrees problem

$
0
0
I was helped to solve the problem with the loop and implementation is described below: /******************************************************************************* * * MSP432P401R * MSP432P401R * ---------------------- * /|\| | * | | | * --|RST P2.4/P5.6 |--> Output PWM * | | * | | * | | * | | * | | * ******************************************************************************/ /* DriverLib Includes */ #include "driverlib.h" /* Standard Includes */ #include #include /* 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 }; // PWM - PIN - 5.6 - TIMER_A2_BASE // PWM - PIN - 2.4 - TIMER_A0_BASE int main(void) { /* Halting the watchdog */ MAP_WDT_A_holdTimer(); int a,b; /* 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_P5, GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION); // Configuring Timer_A to have a period of approximately 20ms MAP_Timer_A_generatePWM(TIMER_A2_BASE, &pwmConfig); b = 40; while (1) { pwmConfig.dutyCycle = b; b = b + 10; if(b == 170) b = 40; for(a=3000; a>0; a--); // change delay MAP_Timer_A_generatePWM(TIMER_A2_BASE, &pwmConfig); } } My question is now why the above code works and this code doesn't work? int main(void) { int a,b; b = 0; while (1) { while(b != 170) { b = b + 10; pwmConfig.dutyCycle = b; for(a=1000; a>0; a--){} } while(b > 0) { b = b - 10; pwmConfig.dutyCycle = b; for(a=1000; a>0; a--); } } }

Viewing all articles
Browse latest Browse all 62309

Trending Articles



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