6
\$\begingroup\$

Is there a nice way to be able to observe the clock signal in an oscilloscope to validate my settings for clock speed? After setting it to 168 MHz with PLL for an STM32F407VGT6 MCU let's say.

\$\endgroup\$
2
  • \$\begingroup\$ Most MCUs feature some sort of "clock out" feature for this purpose. Though you could just implement something like a simple periodic timer based on ARM CMSIS "SysTick", then have that one toggle a GPIO periodically, and measure the GPIO with your scope. \$\endgroup\$
    – Lundin
    Jun 2, 2020 at 8:07
  • \$\begingroup\$ @Lundin in such case, I won't divide frequency for timer right? I mean Prescaler will be 0 for example \$\endgroup\$
    – muyustan
    Jun 2, 2020 at 8:18

2 Answers 2

8
\$\begingroup\$

Directly from the reference manual, pay attention to the last line.
enter image description here

Without oscilloscope you can use TIM5 to perform a comparison between two clocks.
Since TIM5 can input capture from LSI or LSE, you can compare the SYSCLK (the one TIM5 is running on) with any of those. TIM11 can do HSE.
Which is described in detail in chapter: 6.2.11 Internal/external clock measurement using TIM5/TIM11

I'd recommend to do this before using a crystal to check whether it is the expected freqeuncy.

\$\endgroup\$
2
  • \$\begingroup\$ Ok, so if I configure my clock speed to 84 MHz by PLL instead of 168 MHz, then I should be able to observe 84 MHz clock signal directly from MCO1 pin, if I configure it to output PLL clock, of course. Right? \$\endgroup\$
    – muyustan
    Jun 2, 2020 at 8:53
  • 5
    \$\begingroup\$ @muyustan each clockout pin has a configurable prescaler. This means you can look at internal clocks up to 500 MHz. \$\endgroup\$
    – Jeroen3
    Jun 2, 2020 at 9:26
6
\$\begingroup\$

Some ideas

  1. Configure SysTick timer to tick after 1680000 clocks (10ms) and toggle a LED/GPIO each 100 interrupts to get 1s update rate (the signal will have frequency of 0.5Hz). The interrupt and SW processing will introduce some jitter to the signal, so it is not good for clock calibration, but it is still good to recognize wrong PLL settings.
  2. Configure one of the timers as PWM output. This will have less jitter, but some timers are not running at AHB speed or even APB1/2 speeds, so it's not very reliable to detect doubled/halved speed etc. However if you're after reading the exact oscillator speed, you may use this with combination with the previous step.
  3. Reading the value with RCC_GetClocksFreq, but it is NOT always reliable, as the library will usually tell you the value you asked for, especially if it thinks your crystal frequency is of a different value than in thinks.
\$\endgroup\$
4
  • \$\begingroup\$ why did you do "frequency of 0.5 Hz" edit? Isn't it 1 Hz ? \$\endgroup\$
    – muyustan
    Jun 2, 2020 at 8:28
  • \$\begingroup\$ If the led toggles each second, the signal will not be really 1Hz but half the speed. In other words, the toggle changes the phase of the signal by 180° so it takes two interrupts to complete the cycle. The scope would show 0.5Hz. I've made this error before, so I think it is good to mention on this topic. I've accidentally overclocked my STM32F103 to 144Mhz :-) \$\endgroup\$
    – akwky
    Jun 2, 2020 at 8:34
  • \$\begingroup\$ ok, so the toggle you are talking about is as follows: LED ON for 1 second and OFF for 1 second and keeps going, right? \$\endgroup\$
    – muyustan
    Jun 2, 2020 at 8:50
  • \$\begingroup\$ Yes, that was what I meant. I've edited the response to be more clear. \$\endgroup\$
    – akwky
    Jun 2, 2020 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.