0
\$\begingroup\$

I try to use UpMode timerA configuration on MSP to get PWM with arranged Duty Cyle. So here is my code below:

#include "msp432.h"
#include "driverlib.h"

void SetConfiguation(void);

int main(void) 
{
    WDT_A_holdTimer();
    SetConfiguation();
    while(1);
}

void SetConfiguation(void)
{

    Interrupt_disableMaster();

    CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_24);
    CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_128);

    /* TimerA UpMode Configuration Parameter */
    Timer_A_UpModeConfig upConfig =
    {
            TIMER_A_CLOCKSOURCE_SMCLK,              // SMCLK Clock SOurce
            TIMER_A_CLOCKSOURCE_DIVIDER_64,          // SCLK/64 = 24MHz/128/64 = 2929 Hz
            24,                           // 50000 tick period
            TIMER_A_TAIE_INTERRUPT_ENABLE,         // Enable Timer interrupt
            TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE ,    // Enable CCR0 interrupt
            //TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE,     // Disable CCR0 interrupt
            TIMER_A_DO_CLEAR                      // Clear value
    };

    P1DIR |= BIT0;
    P1OUT &= ~BIT0;

    Timer_A_configureUpMode(TIMER_A0_MODULE, &upConfig);

    Timer_A_CompareModeConfig compConfig =
    {
        //uint_fast16_t compareRegister;
        TIMER_A_CAPTURECOMPARE_REGISTER_1,
        //uint_fast16_t compareInterruptEnable;
        TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE,
        //uint_fast16_t compareOutputMode;
        //TIMER_A_OUTPUTMODE_SET_RESET,
        TIMER_A_OUTPUTMODE_TOGGLE_RESET,
        //uint_fast16_t compareValue;
        6
    };

    Timer_A_initCompare(TIMER_A0_MODULE, &compConfig);

    //Timer_A_enableCaptureCompareInterrupt(TIMER_A0_MODULE, TIMER_A_CAPTURECOMPARE_REGISTER_0);
    Timer_A_enableCaptureCompareInterrupt(TIMER_A0_MODULE, TIMER_A_CAPTURECOMPARE_REGISTER_1);

    Interrupt_enableInterrupt(INT_TA0_0);

    PCM_setCoreVoltageLevel(PCM_VCORE0);
    PCM_setPowerState(PCM_AM_LDO_VCORE0);

    Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_UP_MODE);
    Interrupt_enableMaster();
}


void Port1IsrHandler(void)
{

}

void Timer_AIsrHandler(void)
{
    Timer_A_clearCaptureCompareInterrupt(TIMER_A0_MODULE, TIMER_A_CAPTURECOMPARE_REGISTER_0);
    Timer_A_clearCaptureCompareInterrupt(TIMER_A0_MODULE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
    Timer_A_clearInterruptFlag(TIMER_A0_MODULE);
    P1OUT ^= 1;

}

In the Code, upMode works fine, interrupts work fine so I get 60 Hz what I want. But, to get PWM with arranged duty cycle, I need to use compare mode So I structed compConfig as seen on the code. However, it seems like there is no interrupt created for compare Mode. I use compare_register1 to catch interrupt but whether I put the compare interrupt enable or not result is same. It has no effect on the output. So, where am I doing wrong here? What is the correct way to achieve adjustable PWM.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Problem solved. I forgot to enable INT_TA0_N interrupt which includes CCR1 to CCR7 vector. In this case CCR1 determines the duty Cycle so I just added one more Interrupt to NVIC and enabled the interrupt. New code is like this:

#include "msp432.h"
#include "driverlib.h"

void SetConfiguation(void);

int main(void) 
{
    WDT_A_holdTimer();
    SetConfiguation();
    while(1);
}

void SetConfiguation(void)
{

    Interrupt_disableMaster();

    CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_24);
    CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_128);

    /*
    Timer_A_UpModeConfig upConfig =
    {
            TIMER_A_CLOCKSOURCE_SMCLK,              // SMCLK Clock SOurce
            TIMER_A_CLOCKSOURCE_DIVIDER_64,          // SCLK/64 = 24MHz/128/64 = 2929 Hz
            24,                           // 50000 tick period
            TIMER_A_TAIE_INTERRUPT_ENABLE,         // Enable Timer interrupt
            TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE ,    // Enable CCR0 interrupt
            //TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE,     // Disable CCR0 interrupt
            TIMER_A_DO_CLEAR                      // Clear value
    };
    */
    Timer_A_PWMConfig pwmConf =
    {
        //uint_fast16_t clockSource;
        TIMER_A_CLOCKSOURCE_SMCLK,
        //uint_fast16_t clockSourceDivider;
        TIMER_A_CLOCKSOURCE_DIVIDER_64,
        //uint_fast16_t timerPeriod;
        1600,
        //uint_fast16_t compareRegister;
        TIMER_A_CAPTURECOMPARE_REGISTER_1,
        //uint_fast16_t compareOutputMode;
        TIMER_A_OUTPUTMODE_SET_RESET,
        //uint_fast16_t dutyCycle;
        200
    };

    Timer_A_generatePWM(TIMER_A0_MODULE, &pwmConf);

    P1DIR |= BIT0;
    P1OUT &= ~BIT0;

    //Timer_A_configureUpMode(TIMER_A0_MODULE, &upConfig);
    /*
    Timer_A_CompareModeConfig compConfig =
    {
        //uint_fast16_t compareRegister;
        TIMER_A_CAPTURECOMPARE_REGISTER_1,
        //uint_fast16_t compareInterruptEnable;
        TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE,
        //uint_fast16_t compareOutputMode;
        TIMER_A_OUTPUTMODE_SET_RESET,
        //TIMER_A_OUTPUTMODE_TOGGLE_RESET,
        //uint_fast16_t compareValue;
        6
    };
    */
    //Timer_A_initCompare(TIMER_A0_MODULE, &compConfig);

    Timer_A_enableCaptureCompareInterrupt(TIMER_A0_MODULE, TIMER_A_CAPTURECOMPARE_REGISTER_0);
    Timer_A_enableCaptureCompareInterrupt(TIMER_A0_MODULE, TIMER_A_CAPTURECOMPARE_REGISTER_1);

    Interrupt_enableInterrupt(INT_TA0_0);
    Interrupt_enableInterrupt(INT_TA0_N);

    PCM_setCoreVoltageLevel(PCM_VCORE0);
    PCM_setPowerState(PCM_AM_LDO_VCORE0);

    //Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_UP_MODE);
    Interrupt_enableMaster();
}


void Port1IsrHandler(void)
{

}

void Timer_AIsrHandler(void)
{
    Timer_A_clearCaptureCompareInterrupt(TIMER_A0_MODULE, TIMER_A_CAPTURECOMPARE_REGISTER_0);
    //Timer_A_clearCaptureCompareInterrupt(TIMER_A0_MODULE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
    //Timer_A_clearInterruptFlag(TIMER_A0_MODULE);
    P1OUT ^= 1;

}

void Timer_A_N_IsrHandler(void)
{
    Timer_A_clearCaptureCompareInterrupt(TIMER_A0_MODULE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
    P1OUT ^= 1;
}
\$\endgroup\$
3
  • \$\begingroup\$ You could just omit the interrupt handlers, and use set/reset output mode to automatically toggle the output pin connected to the timer. \$\endgroup\$
    – CL.
    Commented Dec 16, 2015 at 13:51
  • \$\begingroup\$ what do you meanby "output pin connected to the timer" is there such thing? How do I assign a pinout to the timer? \$\endgroup\$
    – Alper91
    Commented Dec 16, 2015 at 18:19
  • \$\begingroup\$ Pins labelled TAx.y can be configured to output the timer's output. \$\endgroup\$
    – CL.
    Commented Dec 16, 2015 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.