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.

TM4C123GH6PM: Clock works 4 times faster

Part Number: TM4C123GH6PM

Hello,

I have a problem controlling the clock speed. The clock works 4 times faster than I want it to work. For example in the code below, I want the LEDs to turn on for 1 second and then turn off for 1 second, but it turns on and off twice in on second. The clock speed is 16 MHz, I have used SYSCTL_SYSDIV_64 so that should bring the clock speed down to 250 kHz; so if I say SysCtlDelay(250000), shouldn't I get 1 second since there are 250000 tics every second? I face the same problem when using PWM and other features. I'd appreciate any help and thanks in advance.

int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_64|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

HWREG ( GPIO_PORTF_BASE + GPIO_O_LOCK ) = GPIO_LOCK_KEY ;
HWREG ( GPIO_PORTF_BASE + GPIO_O_CR ) |= 0x01 ;
HWREG ( GPIO_PORTF_BASE + GPIO_O_LOCK ) = 0;

GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_1);

while(1)
{
// Turn on the LED
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_1, 0xFF);
// Delay for a bit
SysCtlDelay(250000);

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_1, 0x00);
// Delay for a bit
SysCtlDelay(250000);

}

}

  • The clock speed is 16 MHz, I have used SYSCTL_SYSDIV_64 so that should bring the clock speed down to 250 kHz

    The SYSCTL_USE_PLL option means the 16 MHz crystal is used to operate the PLL at 400 MHz, where the output from the PLL is divided down to set the system clock frequency. The PLL output has a fixed divide-by-by-two and then further divided by SYSCTL_SYSDIV_64 resulting in a system clock frequency of 3.125 MHz.

    The SysCtlClockGet() function can be used to obtain the frequency which has been set. The following resulted in clock_freq =  3125000 :

        SysCtlClockSet(SYSCTL_SYSDIV_64|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    
        volatile uint32_t clock_freq = SysCtlClockGet ();
    
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);