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.

Timer Frequency Calculation?

Other Parts Discussed in Thread: MSP430F5529

I'm currently using a timer (up/down) to generate a frequency from 10Hz to 2Khz, I want the user to be able to control what freq they want the pins to output. I have the code all working all except for figuring out how to determine the calculation value to put into TA0CCR0 register. Is there a simple calculation to determine this?

  • Hi tang87699, 

    How is your timer configured?

    1) Output mode (ex = set/reset, toggle, etc)

    2) Source clock of your timer (ex = ACLK, SMCLK, etc) 

    3) CCRx registers being used (ex = TA0CCR0 and TACCR1)

    In general terms, the value of your timer counter (TAR) increments by 1 for every clock cycle of the source clock. You need two CCRx registers to generate a square wave on the output. One to give you the frequency (this is always TA0CCR0) and a second one for the duty cycle (ON/OFF timer of your square wave). Depending on the output mode that you have, the calculation of the frequency is a bit different. For instance, assume your mode is Reset/Set then you output is reset when the timer counts to TA0CCRx and sets when the timer counts to TA0CCR0. Let's also assume your TA0CCR1 value is 0 and your TA0CCR0 is a value less than 0xFFFF. Then then output looks as in the attachment. 

    Please provide the additional information and I will help you figure out the equation for the frequency of your specific configuration. 

    Thanks, 

    Damian 

  • Hi Damian,

    1.) Toggle Mode

    2.) Source is SMLK @ 20Mhz / 8

    3.) TA0CCR0

     

  •  tang87699, 

    In Toggle mode, up/down:

    Your output frequency is: 

    f (out) = Input clock / (TA0CCR0 * 2) -- Multiply by 2 since timer counts to TA0CCR0, then down to 0 and up to TA0CCR0 again for one period. In your case: 

    f (out) = 20/8 * 1/(TA0CCR0 *2) MHz

    Hope this helps, 

    Damian 

  • Thanks, but that didn't work.

    I plotted 6 values by entering a set increment value and measure the output. I then performed a linear regression model using the power formula. The resulting equation I got was y=624127x^-1.Where Y = Frequency and X is the Timer Count Value.

    I then solved for x (Timer Count) and got X = 624127 / y. The result was exact on the mark as I did a set of range test.

    Thanks anyways.

  • co tang87699, 

    Are you sure your input clock is running at 20Mhz /8 and not 1MHz /8? 


    Damian 

  • please help calculate small (5oms ) dealy using msp430f5529

  • sunil shetty said:
    please help calculate small (5oms ) dealy using msp430f5529

    Without providing information about clock frequency, there is an unlimited number of possibilities. If the clock frequency of th timér is known, then there is only one solution and the calculation is math for beginners.

    However, you might need to read the users guide, clock system and timer chapters, to get an idea how a delay can be implemented when base clock speed and delay time are known.

    Hint: if you have a clock frequency of 1 million/s, counting 50.000 clock pulses takes 50ms

**Attention** This is a public forum