Pumpkin, Inc.

Pumpkin User Forums

PWM with TimerB

For issues specific to TI's MSP430 line of ultra-low-power microcontrollers, including compilers (e.g. Quadravox AQ430), IDEs (e.g. IAR Embedded Workbench) and development tools (e.g. TI MSP-FET430 Flash Emulation Tool).

PWM with TimerB

Postby SSK » Sat Nov 15, 2008 3:04 am

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. This pin is toggling but no output is seen on P4.5/TB5. Please clarify the problem in code.

Thanks in advance.

SSK
 
Posts: 1
Joined: Sat Nov 15, 2008 12:00 am
Location: India

Re: PWM with TimerB

Postby Dave Hohl » Thu Nov 20, 2008 5:13 am

This is not really a Salvo question, so you probably should have posted it on the Yahoo MSP430 group instead.

Nonetheless, I think I see what your problem is. The statement
TBCCTL5 = CCIE;
is undoing the effects of the previous
TBCCTL5 = OUTMOD_7;
statement, so you are disabling the reset/set mode of operation. Note that the ISR also has the offending line of code.

I think you want
TBCCTL5 |= CCIE;

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
}

Dave Hohl
 
Posts: 24
Joined: Wed Apr 02, 2008 11:00 pm
Location: Sunnyvale, CA, USA


Return to TI's MSP430

Who is online

Users browsing this forum: No registered users and 1 guest

cron