This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TimerA on MSP430x2013 as PWM output on P2.6

Other Parts Discussed in Thread: MSP430F2013

 

Hi all,

I've been stumped on a niggling problem I was hoping somebody could help me out with. I'm using the IAR dev suite that came with the eZ430-2013 SpiBiWire dev kit.

I'm trying to use TimerA to generate a PWM signal on P2.6 of a MSP430x2013. Here is the code snipet I'm using to setup the DCO, timer and port accordingly. However I'm not getting a PWM output on P2.6 ... what's wrong?

..... <snip> ...

// Configure Timer A to be both a PWM output on P2.6, as well as configuring timer interrupts for a system timer.
void TimerPWMConfigure(volatile unsigned int PWMWidth)
{
  // Setup system clock to 12-18.5MHz
  BCSCTL1 |= 0xF0 + 15;       // RSELx = 15
 
  // Setup the TMRA register
  TACTL = ID_0 + TASSEL_2 + MC_3 + TACLR + TAIE;     // 0 divider, SMCLK, up-down mode, TMRA clear, TMRA interrupt enabled

  // Setup the period CC0 register to PWM period 
  CCTL0 = CCIE;          
  CCR0 = PWMPeriod;                      // PWM Period

  // Setup the PWM width CC1 registers
  CCTL1 = OUTMOD_6 + CCIE;             // CCR1 toggle/set, compare mode
  CCR1 = PWMWidth;                         // CCR1 PWM duty cycle 
 
  // Use P2.6 as TA1
  P2SEL |= 0x40;                            // P2.6 as TA1 option
  P2DIR |= 0x40;                            // P2.6 as output 
}
// -------------------------------------------------------------------------

..... <snip> ...

 

As you can see, I have enabled interrupts and I know the timers are going. I can breakpoint in the ISR and check that TAR is counting as it should and that CCR1 is comparing at the correct value set by PWMWidth.

I can even set P2.6 to be a GPIO output and toggle the line in the ISR and I get a PWM, though I'd like it to work free of the CPU. I am able to get P1.1/TA0 and P1.2/TA1 working, just not P2.6 ... so please help if you know what is wrong??

I'm sure its blindingly obvious, but I can't see it ... :)

 

Thanks in advance.

Regards,

Hemon

 

 

  • The reset state of P2SEL.BIT 6 and BIT 7 is logic 1. If the peripheral pin needs to be selected on P2.6, the selection of P2SEL.BIT 7 seems to have an influence. It has to be manually cleared, if you want to use the peripheral pin. Making this change upfront solves the issue. Please let me know if you have any further questions.

  • Thanks for your reply.

    I've changed the code to the following:

      // Use P2.6 as TA1
      P2SEL &= ~0xC0;
      P2SEL |= 0x40;                            // P2.6 as TA1 option
      P2DIR |= 0x40;                            // P2.6 as output

    It now seems to work fine, so thanks for that suggestion. Is this a hardware bug?

     

    Regards,

    Hemon

     

     

     

     

  • This is not a hardware bug.  The logic for configuring Port P2 (P2.6) pin schematics is on page 56 of the MSP430F2013 datasheet.  This figure illustrates the conditions required to ensure P2.6 propagates the TA1 output and configures the pin as an output.

     

     

  • Oh ok, thanks for pointing that out - I think you meant Pg 76 though as this is a 2013 device, but it is identical to the page you referred to.

    The documentation should really say in the logic table:

    Timer_A2.TA1 => P2DIR.6 = 1,   (P2SEL.6 = 1 with P2SEL.7 = 0)

     

    Anyways, thanks again for your help.

     

    Regards,

    Hemon

  • Could you tell me how to set P2.6 and P2.7 as a GPIO? I am looking at the page 56 in TI specific data sheet but it seems complicated. I am using MSP430F2013. Please, help me.

    Regards,

    Piotr N.

  • Actually, I have problem with the program below. My purpose is to set 2.6 and 2.7. I cannot achieve this. P1.5 is '1' and that's ok.

    ---------------------------------------------------

    #include "msp430.h"

    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
      P1DIR = 0x20;
      P2DIR = 0xC0;
      WDTCTL = WDTPW + WDTHOLD;
      BCSCTL1 = CALBC1_16MHZ;
      DCOCTL = CALDCO_16MHZ;
      P1OUT = 0x20;
      P2OUT = 0xC0;
    }

    ---------------------------------------------------

  • Piotr N. said:

    Could you tell me how to set P2.6 and P2.7 as a GPIO? I am looking at the page 56 in TI specific data sheet but it seems complicated. I am using MSP430F2013.

    These pins are crystal pins by default on start-up, so you need to clear the P2SEL bits. PxSEL should be set to zero for the bit corresponding to the port desired in this register.

**Attention** This is a public forum