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.

Multiple Timing outputs with one Timer

Other Parts Discussed in Thread: MSP430G2452, MSP430G2553

Hi,


We need some advise for our customer's project using G series(MSP430G2452).
This project needs PWM output(100Khz) and a general purpose timer to
produce timely intervals(1ms to 10ms) & to measure the time of PWM output.
(Even the WDT is used for other purpose)

But unfortunately, MSP430G2452 has only one timer(TA3),
we wonder if we could use TA3's three channels to produce 100Khz PWM
as well use it as a general purpose timer.
I have seen some posts & application report about making multiple PWM's out
of one Timer but not with the above scenario.


Please let us know if there is any suggestions to
implement this without going for another device with 2 Timers.

Regards.
Paddu

  • For 100kHz PWM, you'll need to set up the timer to run in up mode from 0 to CCR0 and set up the DC with either CCR1 or CCR2.
    For 1% DC regulation, the timer needs to be clocked with 10MHz.
    However, the longest delay you can produce for your software is 10µs then (= 100 MCLK cycles).
    You can use this to trigger an interrupt, increment a counter and trigger an action after 100 interrupts. However, the CPU would be busy serving teh interrupt msot of the time.
    You can use a trick to reduce this load: you can program the USI in SPI mode to use CCR0 signal as clock signal, program a divider (d) and set up the USI for a 8..16 bit transfer (n). So after starting the transfer, the USI will trigger the next interrupt after CCR0*n*d timer ticks. However, the interrupt latency will cause a 'clock' skew, asteh 'time' stops when the transfer is done and requires to be kicked on again by the USI ISR. It requires some cycle counting to compensate.

  • Hi Jens,

    Thank you.

    According to your suggestion I tried to write the
    code below for PWM of 100Khz(for time being I am using 4Mhz) and a
    1ms timing interval .
    I wonder if it is possible to use TACCR2 also to create one
    more different timing interval.

    #include <msp430g2452.h>

    //PWM Frequency 100Khz


    #define PWM_PERIOD 40

    volatile int PWMCycles;

    void main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    //4Mhz Clock settings
    BCSCTL1 = CALBC1_8MHZ; // Set range
    DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation*/
    BCSCTL2 |= DIVM_1 + DIVS_1; // MCLK=SMCLK=4MHz

    P1DIR |= 0x0C; // P1.2 and P1.3 output
    P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
    P1DIR |= 0x01; // Set P1.0 to output direction

    //Configure timer A
    TACCTL0 = CCIE; // TACCR0 interrupt enabled
    TACCTL1 = OUTMOD_7; // TACCR1 Reset/Set
    TACCR0 = PWM_PERIOD; // Set PWM for 100Khz(10us) operation
    TACCR1 = PWM_PERIOD >> 1; // Start with 50% duty cycle
    TACTL = TASSEL_2 + MC_1 + TACLR; // SMCLK (1MHz), Clear TAR, Up mode

    _BIS_SR(LPM0_bits+ GIE); // Enter LPM0

    }

    // Timer A0 interrupt service routine
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer_A (void)
    {
    PWMCycles++; //Increment PWM cycle count
    if(PWMCycles ==100)
    {
    PWMCycles = 0; //Reset 1ms
    P1OUT ^= 0x01; // Toggle P1.0 every 1ms
    }

    }

    Regards.
    Paddu

  • Hi Paddu,

    If you want to implement three different timer periods on a single timer A3, you will probably need to do something like in this app note: www.ti.com/lit/pdf/slaa513 Basically, you put the timer in continuous mode and then use each CCRx register to set a period. For the PWM, you have to take the additional step to decide what part of the cycle you are in - high or low output - and load in the corresponding # of counts for that part of the duty cycle. The app note explains all of this in more detail though and has diagrams that should help.

    There are also code examples associated with the app note that demonstrate this method: www.ti.com/lit/zip/slaa513

    Alternately, if the third period you want to have is also longer than your PWM period, you could just add another software counter like Jens-Michael taught you how to do in your previous post.

    Regards,

    Katie

  • Katie Enderle said:
    For the PWM, you have to take the additional step to decide what part of the cycle you are in - high or low output - and load in the corresponding # of counts for that part of the duty cycle

    Good idea for a low-frequency PWM, but for 100kHz PWM frequency, this would almost completely eat up all the CPU power (if it is enough at all). And would also be quite unprecise and contain the risk of latch-up (what if the delay for the next part of the PWM cycle is shorter than the ISR execution time?) This is why I was going for the hardware PWM solution. Which in turn requires up mode.

  • But unfortunately, MSP430G2452 has only one timer(TA3)

    One can easily replace the MSP430G2452 by MSP430G2553 which has two Timers.


  • Thank you all for the replies...

**Attention** This is a public forum