Skip to main content
Louie88
Senior
March 12, 2022
Solved

Frequency measurement with COMP1 and TIM2 NUCLEO-144 H723ZG board

  • March 12, 2022
  • 14 replies
  • 9242 views

I have NUCLEO-144 H723ZG board. 

I created a frequency meter app for the NUCLEO board, but the quality of the frequency measurement a sinusoidal voltage is very poor. I have a generated 720mV RMS, 126.7Hz signal between 0 and +2.5V (max) biased to +1.25V. On scope, the frequency meter connected to the output of the COMP1 shows 126.700x, the 4th digit is 1 or 0. The NUCLEO board measures almost 1Hz less than the frequency meter on scope (I checked it with a real frequency meter and the scope value is right).

My other problem is that the minimum value of the frequency = 125.451, the maximum value = 125.9264Hz, the average = 125.7246 and the standard deviation = 0.0775Hz. I could not measure the frequency as good as a simple scope.

Setup:

I enabled COM1 comparator. I connected the input sine voltage to the positive input (COMP1_INP) and I connected the negative input (COMP1_INN) to the +1.25V reference voltage to which the input signal is biased. With setting the COMP1 speed to “COMP_POWERMODE_HIGHSPEED�? I got terrible output voltage. Both edges of the output are bounced (200-250 spikes) at least 1-3us. Then I set the COMP1 speed to “COMP_POWERMODE_MEDIUMSPEED�? and I got only a couple of spikes. Then I set the COMP1 speed to “COMP_POWERMODE_ULTRALOWPOWER�? and I got no spikes. The hysteresis was always set to “COMP_HYSTERESIS_HIGH�?. Why? Can somebody explain it?

I connected the comparator output with a wire to the Capture Channel 1 input of the 32-bit TIM2. The timer runs on 275MHz (3.636ns) as a simple up counter, with ARR = 0xFFFFFFFF, Prescaler = 0. It is started with HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);

When rising edge of comparator detected on the Capture CHN1 input of TIM2 then TIM2 captures the value its 32-bit counter and calls the HAL_TIM_IC_CaptureCallback(). I read the capture 1 register and store the value in last period count if this is the first interrupt. It this is not the first interrupt then I subtract the current count from the last count (I also update the last value register to the current one). This is the period time in counts. I set a flag in the callback function to signal that I measured a new period time count. In the main() loop when this is true then I simply divide the 275MHz TIM2 clock with the period count. This is my measured frequency. Because I don’t have LCD and send it via serial port to the terminal APP of my notebook. The application runs continuously.

Even though this is a simple period time measurement I cannot not answer the following two questions.

  1. Why do I have so poor quality of the measurement? (See attached log picture)
  2. Why does the calculated frequency 1Hz less than the input signal frequency? This around 1Hz inaccuracy is constant. I can use any frequency it measures 1 Hz less. XTAL frequency problem? Or this is the side effect 2MHz * 275 with the PLL1?

Can somebody help. (Sample app for NUCLEO-144 H723ZG board is available if needed)

Thanks for any help, any idea.

Louis

This topic has been closed for replies.
Best answer by Peter BENSCH

Oops, sorry, Jan is right.

Yes, with ST-LINK-V3E you can set the MCO output to one of three possibilities:

  • Default (HSI/2) = 8MHz
  • HSE/3 = 25/3 MHz
  • Off

I have already crossed out my statement above.

I apologise for forgetting this for a moment.

Regards

/Peter

14 replies

waclawek.jan
Super User
March 12, 2022

What's the primary clock source?

If it's STLink3's 8MHz output, that is not derived from crystal.

JW

Louie88
Louie88Author
Senior
March 12, 2022

Hi waclawek.jan,

Yes, STLINV3 8MHz is the primary clock. The are no other (real) chances. STM does not assemble the 25MHz crystal (X3) and two caps. Without soldering a 25MHz crystal + 2 caps manually into the board, the STLINV3 8MHz is the only chance for the clock source. By the way, the STLINKV3 works from X1 25MHz crystal. Why do you think the 8MHz is not crystal clock? I guess STLINKV3 has a PLL which generates the 8MHz (DIV=25, MUL=8) but I do not know that chip.

Thanks for the idea!

L

Louie88
Louie88Author
Senior
March 16, 2022

Dear STMicro,

I really need to know whether the 8MHz primary clock of NUCLEO-144 H723ZG board is derived from crystal or RC oscillator? If this clock is an RC oscillator then it explains the frequency error and uncertainty.

Thanks,

Louis

Louie88
Louie88Author
Senior
March 17, 2022

I initialized TIMER 1 to run from 137.5 MHz frequency. I set the prescaler = 0, the period = 100 and set channel 1 to toggle the output. I attached my scope probe to the TIMER 1 channel 1 output pin (PE9, CN10.4) and I measured the frequency . It was anything between 1.371 and 1.373 MHz, instead of 1.375 MHz. It was very unstable.

0693W00000Kd2i8QAB.bmpStill no comment?

March 17, 2022. 18:53:

I modified the prescaler = 5 - 1 and period = 27500. The timer 1 divides with 5 * 27500 = 137500, so I should get 1000Hz. But I get anything between 1006 and 1008 Hz...

0693W00000Kd3pKQAR.bmp???

waclawek.jan
Super User
March 17, 2022

I've told you already that STLink3's 8MHz output is not derived from crystal (which means it's derived from its HSI). And your symptoms confirm it. What's the point of your repeated posts, then?

And no, 'F723 used as STLink3 cannot generate 8MHz from 25MHz.

In CubeProgrammer you probably can switch STLink3's output to a different frequency, derived from the 25MHz crystal. I don't use CubeProgrammer nor STLink3. There are several related threads on this forum, search.

JW

waclawek.jan
Super User
March 17, 2022
Louie88
Louie88Author
Senior
March 17, 2022

Thank you all of your the answers, ideas.

When I opened this an the two weeks ago topic I was sure the the STM32H723 NUCLEO board runs from a crystal or crystal oscillator. (I did not have the schematic). Then waclawe.jan told me the HSE = 8MHz clock is not derived from crystal. (Then derived from what?) Then I begun to test the timers, and I found that - probably - the HSE clock is generated by an RC oscillator. My symptoms confirmed that. So now, after two weeks, I know the right question. All I want to know is:

How can I run the STM32H723 NUCLEO board from a crystal or a crystal oscillator?

I guess, the only way is to buy the not assembled 25 MHz crystal and 2 x 5.1 pF capacitors and somehow solder those into the board and remove the SB34 bridge.

Thanks and sorry for the duplicated topics.

L

Peter BENSCH
ST Technical Moderator
March 18, 2022

Well, as @Community member​ wrote, the clock for the target STM32H723ZGT6 is fed from the MCO of the ST-LINK-V3E. The ST-LINK-V3E itself is driven by a STM32F723IEK6, in whose clock scheme the MCO outputs can only be fed from four sources and a divider 1:1...1:5 before the output: LSE, HSE, HSI and PLLCLK. Unfortunately, the (non-changeable) MCO frequency chosen for the ST-LINK-V3E is not the HSE, but 8MHz, which cannot be derived from the required PLLCLK, but only from the HSI.

So if you need a crystal stabilised clock on the STM32H723ZGT6, you must indeed could:

  • either assemble X3 and the load capacitors or
  • set the ST-LINK-V3E to HSE/3, i.e. 8.333MHz

[edited: pls see the comments below]

Fortunately, the NUCLEO is only an evaluation or development board and is not used for finished products, so hopefully this is acceptable?

We are very sorry for this inconvenience.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Louie88
Louie88Author
Senior
March 18, 2022

Thanks Peter, I ordered the crystal and the caps (6x) from DIGI-KEY: $5 the price, $30 the shipping + $8 VAT. (The whole NUCLEO board was less than $30) We do not want to use NUCLEO board in production, we just use it in a prototype transmitter. We designed a motherboard, with all the extra circuits we need and the NUCLEO board will be plugged into the motherboard. This concept worked many times in the past. If the prototype transmitter will pass all the tests then we will design own custom board. By the way it would nice to know how ST supports designing custom boards...

Regards,

Louis

Peter BENSCH
ST Technical Moderator
March 18, 2022

STMicroelectronics supports the development of custom boards by providing the tools to do so: software like STM32CubeIDE (completely free of charge) and hardware like DISCOVERY, NUCLEO and EVAL boards. This means that you can already start developing your own software without having to wait for the layouter or the board manufacturer.

Does it answer your question?

Otherwise, it would make sense to open a separate thread for this, as it is a new topic.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
waclawek.jan
Super User
March 18, 2022

Hi @Peter BENSCH​ ,

Can't the STLinkV3 switched to output HSE/3=8.33MHz as outlined in https://community.st.com/s/question/0D53W00000j62rkSAA/how-to-change-the-stlinkv3e-mco-hse-frequency ?

I don't have STLinkV3 to try but at least Clive appears to confirm that this is indeed possible.

Can you please try/confirm?

Jan

Peter BENSCH
Peter BENSCHBest answer
ST Technical Moderator
March 18, 2022

Oops, sorry, Jan is right.

Yes, with ST-LINK-V3E you can set the MCO output to one of three possibilities:

  • Default (HSI/2) = 8MHz
  • HSE/3 = 25/3 MHz
  • Off

I have already crossed out my statement above.

I apologise for forgetting this for a moment.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.