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.

Real Check: How to check the user setting clock speed using Oscilloscope?



My question is that when a user wants to know a real clock speed using a oscilloscope, how to check it?

My board is Stellaris Launchpad(EK-LM4F120XL). It uses 16MHz osc.

From the below example,

 SysCtlClockSet  brings me 40MHz by literature.

At that time, I really want to confirm it whether 40MHz is real or not with Oscilloscope.

And ulPeriod resulted from SysCtlClockGet should be checked by Oscilloscope.

Would you let me know how to check it and give me a tip?

I would like to probe 40MHz and ulPeriod.

------------------------------ Example (Lab 4, workshop) ---------------------

int main(void)
{
unsigned long ulPeriod;

SysCtlClockSet(SYSCTL_SYSDIV_4| SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER);

ulPeriod = (SysCtlClockGet() / 10) /2;

TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1);

IntEnable( INT_TIMER0A );
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntMasterEnable();

TimerEnable(TIMER0_BASE, TIMER_A);

~~~~ // ~~~~~

  • Hi,

    In the timer interrupt, toggle one of declared GPIO output pins. The scope then will show the timer activity - and must be close with your timer settings. Take into account that scopes are often within +/-1% calibrated (or at least declared...)

    Petrei

  • Another way to achieve this - eliminates effort/possible error introduction via interrupt addition.  (i.e. no interrupt set-up/overhead required)

    BTW - unlikely that SYSCTL_DIV_4 yields 40 MHz.  (50MHz = 200MHz/4...)

    Here - perhaps a more elegant method to output System Clock at 1/1000th Sys Clock frequency:  (i.e. 50MHz SysClock yields 50KHz)

    void SysClockMeasure()
    {
        // use TIMER2 TIMER_A as a PWM to show clock frequency

        SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);

        SysCtlPeripheralEnable(GPIO_PORTD_BASE)

        GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_5); // Match your chosen Timer to its GPIO Pin

        GPIOPinConfigure(GPIO_PD5_CCP4);   // this function confined to newer Stellaris MCU Class - check!

        TimerDisable(TIMER2_BASE, TIMER_A);

        TimerConfigure (TIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);

        TimerLoadSet (TIMER2_BASE, TIMER_A, 1000); // Fout is 1/1000 of SysClock

        TimerMatchSet (TIMER2_BASE, TIMER_A, 500); // Duty Cycle set to 50%

        TimerEnable (TIMER2_BASE, TIMER_A);  // SysClock/1000 output here - no possibility of disturbing xtal input...

    }

    Note: You must choose Timer Port and Pins suitable for your MCU and board.  GPIOPinConfigure() is restricted to more modern MCUs (yours is ok)

    This use of the PWM Mode w/in the Timer Module is the best (only) means to generate a solid output signal from the Timer resource...