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.

PWM signal frequency calculation

Other Parts Discussed in Thread: MSP430G2231

hi friends,

      i use MSP430G2231 for generating PWM signals with varying duty cycle with the help of interrupt. i know the register TACCR0 determines the period of the PWM signal and the register TACCR1 determines the duty cycle. 

my question is "is there any formula to calculate the frequency or time period of the output PWM signal using this TACCR0 and TACCR1?" or there is any other way?

because in each time i got my desired output by trial and error method. plz help me.......

regards

S.Sivakumar

  • Sivakumar,

    Since TACCR0 is the period register, that decides the frequency of the PWM signal (and of course the resolution of PWM). 

    Frequency of PWM Signal  = Timer Clock Frequency / TACCR0 Value.

    With the other two values known, third can be calculated. (e.g If Timer is supplied with 1MHz of clock , period register value of 1000 sets PWM frequency as 1kHz)

    Is this what you are looking for?

    Regards,

    Jasraj

  • Jasraj is almost right.

    Frequency of PWM Signal  = Timer Clock Frequency / (TACCR0 Value + 1)

    From 0 to 1000 (inclusive) there are 1001 cycles.

  • Jasraj Dalvi said:
    Frequency of PWM Signal  = Timer Clock Frequency / TACCR0 Value

    Don't forget that the duty cycle is:

    • (TACCR1+1) / (TACCR0+1)  when using Reset/Set Output Mode, or
    • 1 - ((TACCR1+1) / (TACCR0+1))  when using Set/Reset Output Mode

    So, for a 1MHz clock, and a TACCR0 = 999 you get a 1KHz PWM rate. Setting TACCR1 (in Reset/Set Mode) to 399 gives you an on time of 40% each 1KHz period.

    In formulas:

    Fpwm = Fclock / (TACCR0 + 1)

    Ton = (TACCR1 + 1) / Fclock

  • Thanks Jasraj Dalvi and Brian Boorman.

    i got a clear idea from ur valuable answer. im using MSP430G2231 microcontroller. u mentioned that "if timer is supplied with 1MHz of clock". what does it mean?

    im using SMCLK signal for the timer A. is there any clock freq range for different clk signals(ACLK. MCLK, SMCLK, BSCLK).

    plz reply

    Regards

    S.Sivakumar

  • Take a look at Section 5 of the User's Guide: http://www.ti.com/lit/ug/slau144i/slau144i.pdf

    Depending on how you program BCSCTL2 register selects your SMCLK source.

    You need to know what your SMCLK source is and dividers selected to know what rate you are clocking the TimerA with and perform the calculations above.

**Attention** This is a public forum