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.

Using SysCtlClockGet() to generate different clock; error

Genius 3300 points

Other Parts Discussed in Thread: TM4C123GH6PM

1. I am using tm4c123gh6pm & want to generate different freq.

2. Case 1: Internal 16Mhz crystal as system clock. What value should I write here, value I had put is wrong

SysCtlClockSet(SYSCTL_OSC_INT );
 freq = SysCtlClockGet();                /* freq returns: 66666666 */


3. Case 2: 80Mhz using internal 16Mhz

  SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_INT);

   freq = SysCtlClockGet();                /* freq returns: 66666666 */


4. case 3: External 16Mhz clock as system clock

SysCtlClockSet(SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ );
freq = SysCtlClockGet(); /* freq returns: 66666666 */

5. case 4: 80Mhz using external 16Mhz oscillator

  SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ );
  freq = SysCtlClockGet();                /* freq returns: 66666666 */

6. basically whatever setting I am doing, the  SysCtlClockGet() always return 66.67Mhz.

However if I call this function before configuring the clock it retusn correct value ie 16Mhz

  • Hi,

       See, reply by TI Amit regarding SysCtlClockGet() at the post below.

       set Tiva C series 80MHZ

    - kel

  • I wonder if it will take TI a whole year to release a fix. I know a patch lies hidden in some message in the forum, but that won't reach any newcomers. The TivaWare release itself is already 13 months+ old, not sure when the SysCtlClockGet but was first reported...
  • Can anyone confirm that below settings are OK.

    1. Case1 : Internal 16Mhz crystal as system clock
    SysCtlClockSet(SYSCTL_OSC_INT );


    2. Case2 : 80Mhz as system clock using Internal 16Mhz crystal
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_INT);


    3. Case3 : External 16Mhz crystal as system clock
    SysCtlClockSet(SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ );


    4. Case4 : 80Mhz as system clock using External 16Mhz crystal
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ );
  • Hello Vindhyachal,

    As long as the device sees the correct fields it should be fine. To ensure that mention the entire set of API's parameters.

    Case:1
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_OSC | SYSCTL_OSC_INT| SYSCTL_XTAL_16MHZ );

    Regards
    Amit
  • Hi Amit,

    Ok , does not mean even if those parameters are not used for particular setting but we should mention them. right?

    1. Case1 : Internal 16Mhz crystal as system clock
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_OSC | SYSCTL_OSC_INT| SYSCTL_XTAL_16MHZ );


    2. Case2 : 80Mhz as system clock using Internal 16Mhz crystal
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_INT| SYSCTL_XTAL_16MHZ);


    3. Case3 : External 16Mhz crystal as system clock
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 |SYSCTL_USE_OSC |SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ );


    4. Case4 : 80Mhz as system clock using External 16Mhz crystal
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ );

  • Hello Vindhyachal,

    Perfect. Yes, they should be placed with the correct values. This allows any software change to be backward compatible.

    Regards
    Amit
  • Hi Amit,

    I think I have done it wrong.

    Today i have configured the systick timer & inverted a pin to measure the exact clock freq.

    I think to correctly configure the clock to make it 16Mhz external crystal the correct setting would be:

    SysCtlClockSet(SYSCTL_SYSDIV_1 |SYSCTL_USE_OSC |SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ );

    1. If I had used SYSCTL_SYSDIV_1  , the on/off time of pin is 1ms, which is correct. because I had write 16000 in systick load register. 

    But if I use SYSCTL_SYSDIV_2_5 , the on/off time comes out to be 3ms which is wrong.

    Below is the code which I have used.

    void SysTick_Handler(void)
    {
        GPIOF_AHB->DATA ^= REG32_BIT_2;         /* invert the bit */
    }
    
    
    void func(void)
    {
    /* set clock */
    	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_INT  | SYSCTL_XTAL_16MHZ );   /* 16Mhz internal */
    	//SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_OSC | SYSCTL_OSC_INT  | SYSCTL_XTAL_16MHZ );   /* wrong */
    	
    /* PF2 as output low */    
        SYSCTL->RCGCGPIO |= REG32_BIT_5;                /* enable PORTF clock */
        while(! (SYSCTL->PRGPIO & REG32_BIT_5));        /* while periph ready */
        SYSCTL->GPIOHBCTL |= REG32_BIT_5;               /* enable access to AHB bus  */
    
        GPIOF_AHB->DATA     &= (u32_t)(~REG32_BIT_2);  /* pin low on output */  
        GPIOF_AHB->DIR      |= REG32_BIT_2;            /* make as output */
        GPIOF_AHB->AFSEL    &= (u32_t)(~REG32_BIT_2);  /* used as GPIO */
        GPIOF_AHB->PUR      &= (u32_t)(~REG32_BIT_2);  /* pull up disabled */
        GPIOF_AHB->PDR      &= (u32_t)(~REG32_BIT_2);  /* pull down disabled */
        GPIOF_AHB->ODR      &= (u32_t)(~REG32_BIT_2);  /* not open drain */
        GPIOF_AHB->AMSEL    &= (u32_t)(~REG32_BIT_2);  /* analog function disabled */  
        GPIOF_AHB->DR2R     |= REG32_BIT_2;            /* 2mA drive enable */
        GPIOF_AHB->SLR      &= (u32_t)(~REG32_BIT_2);  /* slew disabled */
        GPIOF_AHB->DEN      |= REG32_BIT_2;            /* digital function enabled */
    	
    	
    /* systick regsiter */
        SysTick->CTRL &= ((uint32_t)~REG32_BIT_1);   /* disable systick */
        SysTick->CTRL |= REG32_BIT_2;                /* sysytem clock as clock source */
        SysTick->CTRL |= REG32_BIT_1;                /* enable systick interrupt */
        SysTick->VAL = 0U;                           /* clesr counter */
        SysTick->LOAD = 15999U;                      /* (15999 + 1) / 16  = 1000us */
        SysTick->CTRL |= REG32_BIT_0;                /* start the counter */
    
        while(1)
        {
        }    	
    
    }

  • Hello Vindhyachal

    Oversight on my side and yes you are correct. The DIV_2_5 does not need to be there for 16MHz PIOSC clock as the system clock source.

    Regards
    Amit
  • hello Amit,
    i have tried all these 4 lines to configure my clock to 80Mhz but no one of them work(it works for the pin but not for printing some value using putty),however it works for the last one,could you explain me please what is the wrong here
    //SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ );
    //SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_INT| SYSCTL_XTAL_16MHZ);
    //SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    //SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_OSC | SYSCTL_OSC_INT | SYSCTL_XTAL_16MHZ );


    SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320,80000000);
  • Hello Tarik,

    SysCtlClockFreqSet is for TM4C129x devices and SysCtlClockSet/SysCtlClockGet is for TM4C123x devices

    Regards
    Amit