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.
Best Answer
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: