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.

TMS320F280039: How is the macro CPU_RATE calculated in ti source files

Part Number: TMS320F280039

Hi,

I want to understand the calculation of CPU_RATE macro used in <device>_examples.h for example: F2837xD_Examples.h.
// Take into account the input clock frequency and the PLL multiplier
// selected in step 1.
//
// Use one of the values provided, or define your own.
// The trailing L is required tells the compiler to treat
// the number as a 64-bit value.
//
// Only one statement should be uncommented.
//
// Example: 200 MHz devices:
// CLKIN is a 10 MHz crystal or internal 10 MHz oscillator
//
// In step 1 the user specified the PLL multiplier = 40 for a
// 200 MHz CPU clock (SYSCLKOUT = 200 MHz).
//
// In this case, the CPU_RATE will be 5.000L
// Uncomment the line: #define CPU_RATE 5.000L
/

#define DELAY_US(A)  F28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)

  • Does the CPU_RATE remian same for internal and external oscillator?
  • Will it not change if I use external oscillator of a frequency other than 10MHz?
  • How is CPU_RATE dependent on PLL multiplier and crystal clock frequency?

Looking forward to your response.

Thanks,

Mukul

  • Hi Mukul,

    The CPU_RATE MARCO is the equivalent SYSCLK period based on the frequency of operation.

    Does the CPU_RATE remian same for internal and external oscillator

    The CPU_RATE macro is decided based on the CPU clock speed output(SYSCLKOUT).

    Eg : if the CPU Clock out for a device = 200MHz, we would be choosing a CPU_RATE = 5.0

    Will it not change if I use external oscillator of a frequency other than 10MHz?

    It will be based on the SYSCLKOUT frequency.

    The launchpad demo example uses these delays "DELAY_US(50000);" in the code which is calculated using this CPU_RATE macro.

     

    Thanks

    Aswin

  • Hi,

     I would request you to give some more clarification regarding the calculation of CPU_RATE and its dependency on Crstal clock frequency.

    I understand that the value is an equivalent number for the SYSCLOCKOUT frequency.

    For example,

    Crystal Clock Frequency Desired CPU Clock Frequency PLL Multiplier CPU_RATE
    10MHz 200MHz 40 5
    20MHz 200MHz 40 ?

    1) Basically, if the crystal clock frequency changes, how the CPU_RATE will change?

    2) In the below formula, what is the significance of subtracting 9 and dividing by 5?

    #define DELAY_US(A)  F28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)

    Thanks,

    Mukul


  • Hi Mukul,

    1) Basically, if the crystal clock frequency changes, how the CPU_RATE will change?

    The CPU_RATE macro is dependent on the CPU Clock frequency. I could see the final CPU clock frequency for both (10MHz/20MHz) crystal to be 200MHz. 

    It does not have dependency on the crystal clock frequency. The CPU_RATE for 200MHz CPU Clock, 20 MHz crystal clock frequency will have a CPU_RATE of 5

    Crystal Clock Frequency Desired CPU Clock Frequency PLL Multiplier CPU_RATE
    10MHz 200MHz 40 5
    20MHz 200MHz 40 5
    In the below formula, what is the significance of subtracting 9 and dividing by 5?

    The context of this math translation is -

    There is a 9/10 cycle overhead and each loop takes five cycles. The LoopCount is given by the following formula:
     DELAY_CPU_CYCLES = 9 + 5*LoopCount
     LoopCount = (DELAY_CPU_CYCLES - 9) / 5
    The macro DELAY_US(A) performs this calculation for you

    Thanks

    Aswin