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.

TMS320F28054M: Issues with external clk in setup

Part Number: TMS320F28054M
Other Parts Discussed in Thread: MOTORWARE, CONTROLSUITE

Hi TI,

  I am setting up external clk to replace my system clk. So I made the following changes from hal.c: (using proj_lab1 from motorware)

void HAL_setupClks(HAL_Handle handle)
{
  HAL_Obj *obj = (HAL_Obj *)handle;


  // disable internal oscillator 1
  CLK_disableOsc1(obj->clkHandle);

  // set the oscillator source
  //CLK_setOscSrc(obj->clkHandle,CLK_OscSrc_Internal);

  // Enable the external clock in
  CLK_enableClkIn(obj->clkHandle);

  // Set the external clock in
  CLK_setXClkInSrc(obj->clkHandle, CLK_XClkInSrc_Gpio19);

  // disable the external clock in
 // CLK_disableClkIn(obj->clkHandle);

  // disable the crystal oscillator
  CLK_disableCrystalOsc(obj->clkHandle);

  // disable oscillator 2
  CLK_disableOsc2(obj->clkHandle);

  // set the low speed clock prescaler
  CLK_setLowSpdPreScaler(obj->clkHandle,CLK_LowSpdPreScaler_SysClkOut_by_1);

  // set the clock out prescaler
  CLK_setClkOutPreScaler(obj->clkHandle,CLK_ClkOutPreScaler_SysClkOut_by_1);

  return;
} // end of HAL_setupClks() function

Is there anything else I need to setup when using external clock in?

Cuz, after I made above changes, It created Load program error, can't load my proj_lab01.out: Load Failed.

  • Hi Qiang,

    Take a look at your hal.c file and the F2805x_SysCtrl.c file within controlSUITE at the below directory.
    \controlSUITE\device_support\f2805x\v104\F2805x_common\source\

    You'll notice that an unedited version of HAL_setupClks(...) and IntOsc1Sel() essentially do the same thing.  The HAL function does two extra things at the end to set prescalars.

    If you look at the ExtOscSel() function within the SysCtrl file, this should give you an idea about the order that the commands need to be in for things to work when wanting to use an external clock source to drive the F2805x MCU.  You'd then just need to utilize motorWARE driver calls instead of the register bit field writes.

    Hopefully this helps!


    Thank you,
    Brett

  • Great, thank you Brett, here are my modified code:

    void HAL_setupClks(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;
    
      // Set the external clock in
      CLK_setXClkInSrc(obj->clkHandle, CLK_XClkInSrc_Gpio19);
    
       // disable the crystal oscillator
      CLK_disableCrystalOsc(obj->clkHandle);
    
       // Enable the external clock in
       CLK_enableClkIn(obj->clkHandle);
    
       // Switch to external clock
       CLK_setOsc2Src(obj->clkHandle,CLK_Osc2Src_External);
    
       // Switch from INTOSC1 to ext clk
       CLK_setOscSrc(obj->clkHandle,CLK_OscSrc_External);
    
        // Clock Watchdog off of INTOSC1
       CLK_setWatchDogSrc(obj->clkHandle,CLK_WdClkSrc_ExtOscOrIntOsc2);
    
        // Turn off INTOSC2
       CLK_disableOsc2(obj->clkHandle);
    
        // Leave INTOSC1 on
       CLK_enableOsc1(obj->clkHandle);
    
      // set the low speed clock prescaler
      CLK_setLowSpdPreScaler(obj->clkHandle,CLK_LowSpdPreScaler_SysClkOut_by_1);
    
      // set the clock out prescaler
      CLK_setClkOutPreScaler(obj->clkHandle,CLK_ClkOutPreScaler_SysClkOut_by_1);
    
      return;
    } // end of HAL_setupClks() function

    But my system doesn't seems to be running when i get into debugged mode, and when I pause it:

    the program is stuck at here:

      // wait until locked
      while(PLL_getLockStatus(obj->pllHandle) != PLL_LockStatus_Done) {}

    Do I also need to set up anything for PLL CLK?

  • Hi Qiang,

    What is the frequency of your external clock source? 

    Keep in mind that the code as developed expects to utilize the internal 10MHz oscillator.  In order to get different frequency clock sources to work, you'll need to edit the PLL multiplier along with the divider so that the end result is that the device is clocked at 60MHz.

    Hopefully this helps!


    Thank you,
    Brett

  • My external clock frequency is 15MHz, where can I changed the PLL multiplier and divider values to make my device clocked at 15MHz?

    How many values are playing roles in sci communication?

    External Input System clock: 15MHz,  (But I want to make my system runs at 60MHz, how can I do so?)

    BaudRate: SCI_BaudRate_9_6_kBaud

    PLL_setDivideSelect: PLL_DivideSelect_ClkIn_by_4

    HAL_setupPll(handle,PLL_ClkFreq_60_MHz);

    I am a bit confused how they are related each other.

    Thank you for your help!

  • Hi Qiang,

    If external system clock is 15MHz, then I'd suggest using:  15MHz * 8 / 2 = 60MHz.

    Use 8 to go into the PLLCR register (via HAL_setupPll).  The definition of PLL_ClkFreq_60_MHz is 12 and is based on an assumption of using the internal 10MHz oscillator.

    Near the end of HAL_setupPll(...) is a HAL_setDivideSelect to divide-by-2. 

    If you can get the main clock in the device (sysclk) set to 60MHz, then the SCI clock/dividers/baudrate settings will not need to be changed.


    Thank you,
    Brett

  • It works, thank you so much Brett!