I am trying to use PWMs to generate a sine wave on two output pins. Here is the code I have so far: #include "msp.h" #include "timer_a.h" #include "driverlib.h" #include "pwmArray.h" int index = 1; Timer_A_PWMConfig pwm1Config = { TIMER_A_CLOCKSOURCE_SMCLK, TIMER_A_CLOCKSOURCE_DIVIDER_1, 2000, TIMER_A_CAPTURECOMPARE_REGISTER_1, TIMER_A_OUTPUTMODE_RESET_SET, 12 }; Timer_A_PWMConfig pwm2Config = { TIMER_A_CLOCKSOURCE_SMCLK, TIMER_A_CLOCKSOURCE_DIVIDER_1, 2000, TIMER_A_CAPTURECOMPARE_REGISTER_2, TIMER_A_OUTPUTMODE_RESET_SET, 0 }; void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer /* Setting MCLK to DCO at 48MHz for HF mode * Setting SMCLK to 48MHz */ MAP_CS_setDCOFrequency(48000000); //Sets Digitally Controlled Oscillator to 48MHz MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); //Initialize Sub Main Clock MAP_PCM_setPowerState(PCM_AM_LDO_VCORE0); /* Configuring GPIO2.4 as peripheral output for PWM */ MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4 | GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION); MAP_Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1); MAP_Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2); MAP_Timer_A_enableInterrupt(TIMER_A0_BASE); /* Generate PWM */ MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwm1Config); MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwm2Config); /* Enabling interrupts and starting the watchdog timer */ MAP_Interrupt_enableInterrupt(INT_TA0_0); MAP_Interrupt_enableSleepOnIsrExit(); MAP_Interrupt_enableMaster(); // Enter LPM0 while(1) { MAP_PCM_gotoLPM0(); } } void interruptTimerA0(void) { uint16_t currentCount = MAP_Timer_A_getCounterValue(TIMER_A0_BASE); if (currentCount == 0) { pwm1Config.dutyCycle = pwm_sine_wave[index%400]; pwm2Config.dutyCycle = pwm_sine_wave[(index+200)%400]; index++; MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwm1Config); MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwm2Config); } } My problem is that it is not outputting anything meaningful on the oscilloscope. Is there someone that can help me with PWM and TimerA0 programming for outputting a sine wave.
↧