SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By SSK
#59118
Dear forum members,

I am using MSP430F1611 in my project. I am trying to generate a PWM using TimerB7 on Port pin P4.5/TB5. My code is as follows:

void ConfigTimerBCompare (void)
{
P4SEL |= 0x20; // P4.5 - Select as TB5 functionality
P4DIR |= 0x20; // P4.5 - Select compare as output

TBCTL = MC_0 | TBCLR; // Stop Timer
TBCCTL5 = 0x00; // CAP = 0 - Compare mode
TBCCR0 = (1024 - 1); // PWM Period/2
TBCCTL5 = OUTMOD_7; // CCR5 Set/Reset
TBCCR5 = 0x00; // CCR5 PWM duty cycle
TBCTL = CNTL_0; // 16 bit format
TBCCR5 = 38; //Initial duty cycle
TBCCTL5 = CCIE; // CCR5 interrupt enabled
TBCTL = TBSSEL_1 | ID_2 | MC_3; // Clock source=ACLK, Divide by 4, Start timer in up-down mode
}

The ISR for TimerB is as:

void ISR_TimerB (void) INTERRUPT[TIMERB1_VECTOR]
{
P1OUT ^= BIT0; // Toggle P1.0 using XOR for testing
TBCCR5 = g_DACCount; //main loop updates the DAC count
TBCCTL5 = CCIE; // CCR5 interrupt enabled
}

The ISR works fine as I have added a port pin toggle code for testing but no output is seen on P4.5/TB5. Please clarify the problem in code.

Thanks in advance.
By OldCow
#59145
When you say: TBCCTL5=CCIE; only the CCIE bit is set to 1 all other bits in TBCCTL5 are cleared to 0. Thus OUTMODx becomes 0 (not 7 as you intended).
By SSK
#59199
Hello OldCow,

Thanks for your reply.

I changed the code to following:

TBCCTL5 = OUTMOD_7 | CCIE; // CCR5 interrupt enabled

both in ISR and Configuration. This is working fine.

Do I need to do this setting for OUTMODx everytime I set CCIE?

Thanks in advance.[/b]
By OldCow
#59224
TBCCTL5 |= CCIE; //same as TBCCTL5 = TBCCTL5 | CCIE;

sets CCIE bit and preserves whatever other bits TBCCTL5 already has.
You were using this kind of operation on P4DIR and P4SEL
By SSK
#59298
Thank you OldCow for clearing this point.
By SSK
#59299
Hello All,

I have used the timer interrupt for updating PWM duty (TBCCR5 = 0xxxxx). Is it good to use interrupt for this task? Will this post any extra overhead on controller for switching context when serving ISR? Whether this will affect the PWM accuracy?

Thanks in advance.